2015-12-10 66 views
0

我很好奇,是否可以在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 

所以很明顯,它不表現我沒有料到:宏觀標識符出現在輸出消息文本中。

有沒有解決方案?

+1

如何通過'/ P:MyCustomBeforeMicrosoftCSharpTargets = 「custom.targets」'到項目,項目設置裏面的屬性CustomBeforeMicrosoftCSharpTargets爲 「$(SolutionDir)\ $(MyCustomBeforeMicrosoftCSharpTargets)」? – stijn

回答

1

像$(SolutionDir)這樣的「宏」只存在於VisualStudio中,VS將這個值傳遞給MSBuild。

相反的MSBuild使得可以作爲properties環境變量,所以像這樣的

set SomeMacroValue=foo 
msbuild buildme.proj /p:SetMe="$(SomeMacroValue)\StillNotInSandbox" 

一個批處理文件,也可能是你在找什麼。 ,你可以設置每個用戶或每臺機器的環境變量(控制面板\所有控制面板項\ SYSTEM高級系統設置環境變量)。

+0

同意Giulio,@Rabid,你可以使用環境變量。並且有一些預定義的TFS環境變量可以在MSBuild參數中使用它。請參閱:https://msdn.microsoft.com/en-us/library/hh850448。aspx –

+0

謝謝,我遇到了這些變數。不幸的是我使用的是TFS 2012,所以它們不存在。但是,在我找到它們之後,我採用了它們的精神並修改了我的構建工作流,以便使用'string.replace()'將工作流變量中的等價值替換爲我的MSBuild參數。可悲的是,我並未處於最前沿。 – Rabid

相關問題