I need to convert the function "path::combine(path1, path2)". Please help me if you have some idea. Thank you!
How to convert NAnt function "path::combine(path1, path2)" to MSBuild?
It's true that the CombinePath Task is not listed in the summary page but only in the tree navigation under "MSBuild Task reference". –
Stentor
I see where you mean. It looks like MSBuild Team added it recently in the list (the alphabetical order shows that). –
Cornall
I updated my example with a workaround which should return the BasePath if an empty Path is passed to the CombinePath Task. –
Stentor
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>
Thank you! It's so strange because I look for the task in MSBuild Task Reference from msdn.microsoft.com/en-us/library/7z253716(v=VS.90).aspx. Microsoft doesn't list <CombinePath... > there. :( –
Cornall
I've tested I found that: When the second path is empty, CombinePath doesn't return the first path. So, we should note this small difference when compared with NAnt path::combine. –
Cornall
Updating this post for newer MsBuild versions. From MSBuild 4.0 and up, you can use property functions
$([System.IO.Path]::Combine($(Path1),$(Path2)))
© 2022 - 2024 — McMap. All rights reserved.