我很好奇,是否可以在MSBuild的命令行屬性分配上引用宏?在msbuild上引用宏(12.0)命令行屬性分配
E.g:
msbuild.exe MySolution.sln /p:CustomBeforeMicrosoftCSharpTargets="$(SolutionDir)\custom.targets"
會變成這樣也當指定爲從Visual Studio連接到TFS從 「編輯生成定義」 「MSBuildArguments」/ 「隊列新建設」 的工作?
E.g:
/p:CustomBeforeMicrosoftCSharpTargets="$(SolutionDir)\custom.targets"
因爲它似乎並沒有被導入這些目標對我來說。但是在構建工作區中,目標文件與解決方案一起絕對存在。
我不想指定絕對路徑。不知道如何使用相對路徑在這裏工作,在Internet上找不到任何建議,並且調試它非常困難,因爲它是使用工作流在構建代理上調用的。工作流日誌記錄絕對是報告它使用這些參數調用MSBuild,但是在詳細日誌記錄輸出中的任何地方我都可以看到它正在引用CustomBeforeMicrosoftCSharpTargets
目標,或者調用它。
編輯
我寫了一個小測試,構建項目buildme.proj
進一步我的理解。
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SetMe>NotInTheSandbox</SetMe>
</PropertyGroup>
<PropertyGroup>
<SomeMacroValue>c:\Sandbox\BuildTest</SomeMacroValue>
</PropertyGroup>
<PropertyGroup>
<AlreadySet>$(SomeMacroValue)\InTheSandbox</AlreadySet>
</PropertyGroup>
<Target Name="Build">
<Message Text="I am building!" />
<Message Text="Some macro value: $(SomeMacroValue)" />
<Message Text="$(SetMe)" />
<Message Text="$(AlreadySet)" />
</Target>
</Project>
當我用命令執行:
msbuild buildme.proj /p:SetMe="$(SomeMacroValue)\StillNotInSandbox"
我得到以下輸出:
Microsoft (R) Build Engine version 12.0.31101.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 10/12/2015 22:12:08.
Project "C:\Sandbox\BuildTest\buildme.proj" on node 1 (default targets).
Build:
I am building!
Some macro value: c:\Sandbox\BuildTest
$(SomeMacroValue)\StillNotInSandbox
c:\Sandbox\BuildTest\InTheSandbox
Done Building Project "C:\Sandbox\BuildTest\buildme.proj" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.02
所以很明顯,它不表現我沒有料到:宏觀標識符出現在輸出消息文本中。
有沒有解決方案?
如何通過'/ P:MyCustomBeforeMicrosoftCSharpTargets = 「custom.targets」'到項目,項目設置裏面的屬性CustomBeforeMicrosoftCSharpTargets爲 「$(SolutionDir)\ $(MyCustomBeforeMicrosoftCSharpTargets)」? – stijn