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

被刻印的时光 ゝ 提交于 2019-12-11 00:00:15

问题


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


回答1:


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>



回答2:


Updating this post for newer MsBuild versions. From MSBuild 4.0 and up, you can use property functions

$([System.IO.Path]::Combine($(Path1),$(Path2)))


来源:https://stackoverflow.com/questions/2507215/how-to-convert-nant-function-pathcombinepath1-path2-to-msbuild

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!