2010-03-24 20 views
2

我需要轉換函數「path :: combine(path1,path2)」。如果你有一些想法,請幫助我。謝謝!如何將NAnt函數「path :: combine(path1,path2)」轉換爲MSBuild?

+0

這是真的,該CombinePath任務不是在摘要頁面,但只有在在「MSBuild任務引用」樹導航上市。 – Filburt 2010-03-25 12:21:52

+0

我明白你的意思了。看起來MSBuild Team最近在列表中添加了它(按字母順序顯示)。 – 2010-03-26 16:14:55

+0

我更新了我的示例,如果將空路徑傳遞給CombinePath任務,應該返回BasePath。 – Filburt 2010-03-29 11:06:00

回答

2

使用CombinePath任務:

<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> 
+0

謝謝!這很奇怪,因爲我在http://msdn.microsoft.com/en-us/library/7z253716(v=VS.90).aspx查找MSBuild任務參考中的任務。微軟沒有列出那裏。 :( – 2010-03-25 10:00:45

+1

我測試過我發現:當第二條路徑爲空時,CombinePath不會返回第一條路徑,所以我們應該注意到與NAnt path :: combine相比這個小差異。 – 2010-03-25 11:20:35

0

更新這個帖子較新的MSBuild的版本。從MSBuild的4.0及以上,你可以使用property functions

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