将 Wix 属性设置为 TFS 构建位置

发布于 2024-11-25 03:14:04 字数 3307 浏览 0 评论 0原文

我一直试图找到我的问题的答案,但找不到;因此我将把解决方案放在这里。我希望它对其他人有帮助。

问题:

我希望我的 Wix 项目在 TFS 2010 构建过程中构建。作为其中的一部分,我希望 Wix 的源文件位置指向 TFS 的构建位置。例如,我希望:

<File Id="ABC" KeyPath="yes" source="C:\Builds\1\MyBuild\assembly.dll" />

成为:

<File Id="ABC" KeyPath="yes" source="$(var.TFSLOCATION)\assembly.dll" />

'TFSLOCATION' 是一个 wix 属性,需要使用 TFS 构建的位置进行填充。这需要在构建过程中发生,其中构建位置路径被传递到 Wix 项目。

解决方案:

我阅读了以下文章:

http://www. ageektrapped.com/blog/setting-properties-for-wix-in-msbuild/

这就是我对 Wix 项目文件 (wixproj) 所做的操作:

为了从 TFS MSBuild 进程设置 wix 属性,wix项目文件需要两次更改:

<PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <ProductVersion>3.5</ProductVersion>
    <SourceLocation Condition="'$(SourceLocation)' == '' ">UNKNOWN</SourceLocation>
    <ProjectGuid>{cae7e273-2de5-4a60-9c4f-9da5f094caf5}</ProjectGuid>
    <SchemaVersion>2.0</SchemaVersion>
    <OutputName>N4S.MSO.BAM.Installer</OutputName>
    <OutputType>Package</OutputType>
    <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
    <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
    <SccProjectName>SAK</SccProjectName>
    <SccProvider>SAK</SccProvider>
    <SccAuxPath>SAK</SccAuxPath>
    <SccLocalPath>SAK</SccLocalPath>
  </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> 
  <OutputPath>bin\$(Configuration)\</OutputPath> 
  <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
  <DefineConstants>LOCATION=$(SourceLocation)</DefineConstants>
</PropertyGroup>

在上面的xml中,请注意以下两行:

<SourceLocation Condition="'$(SourceLocation)' == '' ">UNKNOWN</SourceLocation>

<DefineConstants>LOCATION=$(SourceLocation)</DefineConstants>

第一行指定属性“SourceLocation”并将其设置为默认“UNKNOWN”值,如果是 >未设置。第二行在“Release”配置中定义了一个名为“LOCATION”的常量。该常量的值设置为“SourceLocation”属性的值。

现在,您需要对 Product.wxs 文件(或 wxs 文件的名称)进行以下更改。

  • 首先定义一个wix属性。
<?define TFSLOCATION="$(var.LOCATION)"?>
  • 现在,更新 File 元素。
<File Id="ABC" KeyPath="yes" source="$(var.TFSLOCATION)\assembly.dll" />

TFS 2010 构建模板更改

  • 打开 TFS 2010 构建模板。
  • 查找任务“运行 MSBuild for Project”。
  • 打开此任务的属性并转到“CommandLineArguments”属性。
  • 将此属性的值设置为:
String.Format("/p:SourceLocation={0}", BinariesDirectory)

完成

您现在已经有了一个从 TFS 构建过程填充的 wix 属性。

I have been trying to find an answer to my question and could not find it; hence I will put the solution here. I hope it is helpful to others.

Problem:

I want my Wix project to build in TFS 2010 build process. As part of this, I want the source files location for my Wix to point to the build location of the TFS. For example, I want:

<File Id="ABC" KeyPath="yes" source="C:\Builds\1\MyBuild\assembly.dll" />

to be:

<File Id="ABC" KeyPath="yes" source="$(var.TFSLOCATION)\assembly.dll" />

The 'TFSLOCATION' is a wix property that needs to be populated with the location of TFS build. This needs to happen during the build process, where the build location path is passed to the Wix project.

Solution:

I read the following article:

http://www.ageektrapped.com/blog/setting-properties-for-wix-in-msbuild/

So this is what I did to my Wix project file (wixproj):

In order to set wix property from TFS MSBuild process the wix project file needs two changes:

<PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <ProductVersion>3.5</ProductVersion>
    <SourceLocation Condition="'$(SourceLocation)' == '' ">UNKNOWN</SourceLocation>
    <ProjectGuid>{cae7e273-2de5-4a60-9c4f-9da5f094caf5}</ProjectGuid>
    <SchemaVersion>2.0</SchemaVersion>
    <OutputName>N4S.MSO.BAM.Installer</OutputName>
    <OutputType>Package</OutputType>
    <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
    <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
    <SccProjectName>SAK</SccProjectName>
    <SccProvider>SAK</SccProvider>
    <SccAuxPath>SAK</SccAuxPath>
    <SccLocalPath>SAK</SccLocalPath>
  </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> 
  <OutputPath>bin\$(Configuration)\</OutputPath> 
  <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
  <DefineConstants>LOCATION=$(SourceLocation)</DefineConstants>
</PropertyGroup>

In the above xml, please note the following two lines:

<SourceLocation Condition="'$(SourceLocation)' == '' ">UNKNOWN</SourceLocation>

<DefineConstants>LOCATION=$(SourceLocation)</DefineConstants>

The first line specifies a property 'SourceLocation' and sets it to a default 'UNKNOWN' value, if is is not set. The second line defines a constant called 'LOCATION' in the 'Release' configuration. The value of this constant is set to the value of 'SourceLocation' property.

Now, you need to make the following changes to your Product.wxs file (or whatever the name of your wxs file is).

  • Define a wix property first.
<?define TFSLOCATION="$(var.LOCATION)"?>
  • Now, update the File elements.
<File Id="ABC" KeyPath="yes" source="$(var.TFSLOCATION)\assembly.dll" />

TFS 2010 build template change

  • Open the TFS 2010 build template.
  • Look for a task 'Run MSBuild for Project'.
  • Open the properties for this task and go to 'CommandLineArguments' property.
  • Set the value for this property to:
String.Format("/p:SourceLocation={0}", BinariesDirectory)

Done

You now have a wix property populated from your TFS build process.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尘世孤行 2024-12-02 03:14:04

如果您在 wixproj 文件中设置对正在构建的项目的引用,则可以引用它们的目标路径。因此,如果您有两个项目 MyProject 和 MyProjectInstaller,请将 MyProjectInstaller 中的引用设置为 MyProject。

现在,在 Product.wxs 文件中,您的 File 元素将如下所示:

<File Id='EXE' Name='$(var.MyProject.TargetDir)\MyProject.exe' />
<File Id='DLL' Name='$(var.MyProject.TargetDir)\MyProject.dll' />
...

这样做的好处是,无论您是在本地构建还是在构建服务器上构建,目标目录都是正确的。

If you set a reference in your wixproj file to the project(s) you are building you can reference their target paths. So if you have two projects MyProject and MyProjectInstaller, set a reference in MyProjectInstaller to MyProject.

Now in the product.wxs file your File elements would look like this:

<File Id='EXE' Name='$(var.MyProject.TargetDir)\MyProject.exe' />
<File Id='DLL' Name='$(var.MyProject.TargetDir)\MyProject.dll' />
...

The benefit to this is that the target dir is correct regardless of whether you're building locally or on a build server.

疾风者 2024-12-02 03:14:04

回答问题,这样即使问题中有答案,也不会出现没有答案的情况。

Answering the question so it doesn't show up with no answers even though the answer is in the question.

淡紫姑娘! 2024-12-02 03:14:04

我最终使用了相同的方法,但有一些重要的改进。

1) 我将 SourcesDirectory 和 BinariesDirectory 作为单独的属性从 TFS 构建过程模板传递到 MSBuild,以便我可以访问它们。

2) 为了使生成的 MSBuild 属性可用于 MSBuild 项目中执行的每个任务,我将它们添加到 BeforeBuild 目标中的 $(CustomPropertiesForBuild) 中。

3) 我没有将 DefineContants 元素添加到 PropertyGroup,而是将 CreateProperty 添加到 BeforeBuild 目标。

完成 2 和 3 的原因如下:与在单个 TFS 构建中运行多个 Wix 项目解决方案有关。如果您按照最初的建议定义常量,则可能会发生两种情况。

首先,如果您在 WiX 项目中作为具有多个 WiX 项目的构建的一部分运行 heat.exe,则可能会出现问题:DevEnv 保留进程句柄,并且每次运行时不会重新定义常量,除非您清理输出文件夹并释放文件句柄。

其次,如果由于任何原因您的 Wix 项目之一未构建(配置未指定构建它或指定的配置对于项目无效),则由于某种原因,MSBuild 属性将重置为 null,因此常量被重新定义为 null,因此您将丢失该属性。另一方面,如果您通过覆盖 BeforeBuild 目标来定义属性,则一切正常。

请注意,您必须重写 BeforeBuild 属性,而不是 BeforeEndToEndIteration 属性,才能正常工作。

I ended up using the same approach, but with a few important improvements.

1) I passed both the SourcesDirectory and the BinariesDirectory from TFS build process template to MSBuild as separate properties, so that I have access to both of them.

2) So that the resulting MSBuild properties are available to every task executed in the MSBuild project, I added them to $(CustomPropertiesForBuild) in the BeforeBuild target.

3) Rrather than adding the DefineContants element to the PropertyGroup, I added a CreateProperty to the BeforeBuild target.

2 and 3 were done for the following reason having to do with running multiple Wix project solutions in a single TFS build. If you define the constant as originally suggested, two things can happen.

First, if you run heat.exe in your WiX project as part of a build that has multiple WiX projects, an issue can occur where the DevEnv holds onto the process handles and the constant is not redefined on each run unless you clean the Output folder and release the file handle.

Second, if for any reason one of your Wix projects does not get built (the configuration does not specify to build it or the specified configuration is invalid for the project) then for some reason, the MSBuild property gets reset to null and thus the constant is redefined as null, so you lose the property. If on the other hand, you define the property by overriding the BeforeBuild target, everything works properly.

Note that you have to override the BeforeBuild property, not the BeforeEndToEndIteration property, for this to work correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文