2011-06-29 82 views
2

我需要調用exec並構建一個wix安裝項目。msbuild exec任務調用msbuild

目前我已經在我的TFSbuild.proj以下

<PropertyGroup> 
     <WebRoot>$(DropLocation)\Latest\x86\Release\_PublishedWebsites\Web</WebRoot> 
     <DBRoot>$(DropLocation)\Latest\x86\Release\Database</DBRoot> 
    </PropertyGroup> 

<PropertyGroup> 
     <Msbuildexe>&quot;msbuild&quot;</Msbuildexe> 
     <Configuration>&quot;/p:Configuration:&quot;Release&quot;&quot;</Configuration> 
     <DefineConstants>&quot; /p:DefineConstants:&quot;WebRoot=$(WebRoot);DBRoot=$(DBRoot)&quot;&quot;</DefineConstants> 
     <WixSolution>&quot;$(MSBuildProjectDirectory)\Setup\Setup.sln&quot;</WixSolution> 
    </PropertyGroup> 

    <Message Text="Bulding setup solution" /> 
    <Message Text="$(Msbuildexe) $(Configuration) $(DefineConstants) $(WixSolution)" /> 
    <Exec Command="$(Msbuildexe) $(Configuration) $(DefineConstants) $(WixSolution)" /> 

我試圖簡單地儘可能多的,所以我就不會感到困惑的地方「的意思是,當我運行這個調試消息(第二最後的命令)輸出

「的msbuild」 「/ p:配置:」 釋放 「」 「 /p:DefineConstants:」 的WebRoot = \服務器\滴\應用\安裝程序生成\最新\ x86 \ Release_PublishedWebsites \ Web; DBRoot = \ server \ drops \ app \ Installer Build \ Latest \ x86 \ Release \ Database「」 「F:\建立\程序\安裝程序生成\ BuildType \ SETUP \ Setup.sln」

而且我得到以下錯誤日誌

' 「的MSBuild」' 沒有被識別爲一個 內部或外部命令,
可操作的程序或批處理文件。 F:\建立\應用\安裝 生成\ BuildType \ TFSBuild.proj(538,5): 錯誤MSB3073:該命令 「」 的msbuild 「 」/ P:配置:「 釋放 」「」 /P:DefineConstants :「WebRoot = \ server \ drops \ app \ Installer Build \ Latest \ x86 \ Release_PublishedWebsites \ Web; DBRoot = \ server \ drops \ app \ Installer Build \ Latest \ x86 \ Release \ Database」「 」f:\ builds \應用程序\安裝 構建\ BuildType \ SETUP \ Setup.sln「」 與代碼退出9009

我不知道這是由不能夠從命令行調用的MSBuild命令造成的或「一個問題,如果這是因爲我不能從命令l調用msbuild像這樣的我將如何去引用它,有沒有一個屬性指向它?

+0

我可能會錯過一些東西,但爲什麼你需要'Exec' MSBuild而不是僅僅添加一個[MSBuild Task](http://msdn.microsoft.com/zh-cn/library/z7f65y0d.aspx)? – Filburt

回答

1

首先,您不需要大多數引號,特別是如果您使用的路徑不包含空格,但我會將其修剪至此,從而允許路徑中的空格爲$(的WebRoot),$(DBROOT)和$(MSBuildProjectDirectory):

<PropertyGroup> 
    <WebRoot>$(DropLocation)\Latest\x86\Release\_PublishedWebsites\Web</WebRoot> 
    <DBRoot>$(DropLocation)\Latest\x86\Release\Database</DBRoot> 
</PropertyGroup> 
<PropertyGroup> 
    <MsbuildExe>{still-needs-a-path-to}\msbuild</MsbuildExe> 
    <Configuration>/p:Configuration:Release</Configuration> 
    <DefineConstants>/p:DefineConstants:&quot;WebRoot=$(WebRoot);DBRoot=$(DBRoot)&quot;</DefineConstants> 
    <WixSolution>&quot;$(MSBuildProjectDirectory)\Setup\Setup.sln&quot;</WixSolution> 
</PropertyGroup> 
<Message 
    Text="Bulding setup solution" 
    /> 
<Message 
    Text="$(MsbuildExe) $(Configuration) $(DefineConstants) $(WixSolution)" 
    /> 
<Exec 
    Command="$(MsbuildExe) $(Configuration) $(DefineConstants) $(WixSolution)" 
    /> 

但是,你仍然無法使用此執行的MSBuild,因爲未指定的MSBuild的路徑。它通常位於$(WINDIR)\ Framework \ Microsoft.Net \ v4.0.30319文件夾中。有幾種方法可以直接編碼,依賴環境變量(必須以某種方式設置),使用預定義的$(MSBuildBinPath)或使用MSBuild註冊表語法從註冊表中提取它,看起來像這樣:

$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0\MSBuildToolsPath) 

但是,它不清楚爲什麼你使用Exec而不是僅僅使用MSBuild任務運行MSBuild。與Exec的行改成這樣:

<MSBuild 
    Project="$(WixSolution)" 
    Properties="$(DefineConstants)" 
    /> 

刪除您聲明<配置>和改變<DefineConstants>這樣:

<DefineConstants>Configuration=$(Configuration);WebRoot=$(WebRoot);DBRoot=$(DBRoot)</DefineConstants> 
+0

define常量是一個屬性列表,我實際上需要重寫,它似乎是msbuild任務不能處理這個...請參閱http://stackoverflow.com/questions/506687/defining-multiple-values-in-defineconstants- in-msbuild-element。感謝你的回答! –

+0

和我不認爲我可以使用提出的解決方法,因爲我們正在使用tfs 2008,我認爲使用msbuild 3.5?即使我將在exec任務中調用4.0 msbuild,執行它的msbuild會是3.5我會想?可能是錯誤的! –

+0

如果您使用的是3.5,那麼路徑將是v3.5而不是v4.0.30319,註冊表路徑將具有3.5而不是4.0,但否則它的工作原理將相同。 MSBuild可以處理覆蓋構成DefineConstants的各個屬性或整個值,只需使用Condition =「'$(DefineConstants)'==''」這樣的條件,並且如果該屬性已有值,則重新聲明將被跳過。 –

0

對我的評論跟進我建議你嘗試使用MSBuild任務,而不是Exec

<?xml version="1.0" encoding="utf-8"?> 
<Project DefaultTargets="BuildWiXSolution"> 
    <!-- Include the custom build targets installed with WiX --> 
    <Import Project="$(MSBuildExtensionsPath)\Wix\Wix.targets"/> 

    <PropertyGroup> 
     <WebRoot>$(DropLocation)\Latest\x86\Release\_PublishedWebsites\Web</WebRoot> 
     <DBRoot>$(DropLocation)\Latest\x86\Release\Database</DBRoot> 
    </PropertyGroup> 

    <ItemGroup> 
     <WiXSolution Include="$(MSBuildProjectDirectory)\Setup\Setup.sln"> 
      <Properties>Configuration=Release</Properties> 
      <AdditionalProperties>WebRoot=$(WebRoot);DBRoot=$(DBRoot)</AdditionalProperties> 
     </WiXSolution> 
    </ItemGroup> 

    <Target Name="BuildWiXSolution"> 
     <MSBuild Projects="@(WiXSolution)" /> 
    </Target> 
</Project> 

它讓您可以將配置屬性和附加屬性與Wix解決方案一起保存。

+0

額外的屬性不會工作我相信,因爲DefineConstants實際上是一個屬性的列表中定義的屬性 –

+0

@Daniel應該可以將'DefineConstants'包裝起來就像你的代碼示例 - 我只是縮短它的可讀性。 – Filburt