2011-06-29 83 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