Search code examples
msbuildnant

How to convert NAnt function "path::combine(path1, path2)" to MSBuild?


I need to convert the function "path::combine(path1, path2)". Please help me if you have some idea. Thank you!


Solution

  • Use the CombinePath Task:

    <Project DefaultTargets="DefaultTarget" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <PropertyGroup>
            <MyBasePath>.\a\b</MyBasePath>
            <MySecondPath>c\d</MySecondPath>
        </PropertyGroup>
    
        <Target Name="Combine">
            <PropertyGroup>
                <MySecondPath Condition="$(MySecondPath)==''">.\</MySecondPath>
            </PropertyGroup>
            <CombinePath BasePath="$(MyBasePath)" Paths="$(MySecondPath)">
                <Output TaskParameter="CombinedPaths" PropertyName="CombineOutput" />
            </CombinePath>
        </Target>
    
        <Target Name="DefaultTarget" DependsOnTargets="Combine">
            <Message Text="Result from Combine is $(CombineOutput)" />
        </Target>
    
    </Project>