使用msbuild构建多体系结构安装程序 [英] Building a multi-arch installer with msbuild

查看:112
本文介绍了使用msbuild构建多体系结构安装程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NSIS为C ++程序构建一个多体系结构安装程序.我正在使用Visual Studio2010.一切正常,除了我不知道如何使安装程序依赖于所有体系结构的构建.

I'm building a multi-architecture installer for a C++ program with NSIS. I'm using Visual Studio 2010. All is well except I don't know how to make the installer depend on the build for all architectures.

我已经创建了一个项目来运行makensis作为构建步骤,并将其配置为依赖于解决方案中的所有其他项目.我目前正在为Win32和X86_64体系结构进行构建. NSIS项目仅作为X86_64配置的一部分而构建.但它会打包以X86_64和Win32配置构建的文件.问题就在这里.如果我先构建Win32,然后立即构建X86_64,那么一切都很好.如果我以X86_64开头,则构建失败,因为它找不到Win32文件.更糟糕的是,如果我更改一些源代码并仅重建X86_64,则安装程序项目将很乐意拾取过期的Win32文件,而没有任何问题的提示.

I have created a project to run makensis as a build step, and configured it to depend on all other projects in the solution. I'm currently building for Win32 and X86_64 architectures. The NSIS project is only built as a part of X86_64 configuration. But it packs files built in both X86_64 and Win32 configurations. Here lies the problem. If I build Win32 and then immediately X86_64, all is well. If I start with X86_64, the build fails because it can't find Win32 files. Worse, if I change some source code and rebuild only X86_64, the installer project will happily pick up out-of-date Win32 files without any indication of a problem.

我可以从X86_64版本中强制Win32版本吗,还是可以做其他事情来使此工作正常?

Can I force a Win32 build from an X86_64 build, or do anything else to make this work?

我是Unix类型,Windows对我来说是一个陌生的世界.

I'm a Unix type, Windows is an alien world to me.

任何

推荐答案

至于万无一失"的解决方案,如果我正确理解您的话:

As for "foolproof" solutions, if I understand you correctly:

  • 您的解决方案包含多个项目(例如Test.sln)
  • 您要为多个平台构建此解决方案,
  • ...,然后使用MakeNSIS工具(我不知道这是什么)来创建针对所有平台构建的安装程序打包二进制文件.

如果我错了,请纠正我.因此,要完成此任务:

Please correct me if I am wrong. So, to achieve this task:

  • 我将完全删除您介绍的项目(一个正在运行MakeNSIS的项目)
  • 然后将创建Test.msbuild文件,例如以下文件,
  • 请注意 <Exec>元素,在该位置您想运行MakeNSIS,
  • 然后只需将msbuild运行为msbuild Test.msbuild
  • 使用此解决方案,您将首先为Win32构建然后再为x64构建的Test.sln中的所有项目,而MakeNSIS将仅在之后运行.
  • I would completely drop the project you introduced (the one running MakeNSIS),
  • Then would create Test.msbuild file such as the one below,
  • Notice the <Exec> element, that is the place where you want to run you MakeNSIS,
  • Then simply run the msbuild as msbuild Test.msbuild,
  • Using this solution you would have all the projects from Test.sln first built for Win32, then for x64, and MakeNSIS would only be run afterwards.
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="Build" DependsOnTargets="Build_Win32;Build_x64">
    <!-- Run whatever command you like, such as MakeNSIS .. ? -->
    <Exec Command="notepad.exe" />
  </Target>
  <Target Name ="Build_Win32">
    <MSBuild Projects="Test.sln" Properties="Configuration=Release;Platform=Win32" />
  </Target>
  <Target Name ="Build_x64">
    <MSBuild Projects="Test.sln" Properties="Configuration=Release;Platform=x64" />
  </Target>
</Project>

如果以上内容不是您所要的,请澄清您的实际问题.

Please provide clarification to your actual question if the above isn't what you asked for.

在评论中澄清您的要求后,我将提出以下解决方案.我更喜欢上述解决方案和Test.msbuild,但是在这里:

After clarifying your request in the comment, I would propose following solution. I like the above solution with Test.msbuild more, but here you go:

  1. 将新项目BuildInstaller添加到您的解决方案中,
  2. 配置管理器中,取消选中此新项目的构建"复选框,以查看配置/平台的所有组合,
  3. 仍然在 Configuration Manager 中,创建新配置,例如说安装程序
  4. 对于此新配置,请取消选中解决方案中所有项目的"Build"复选框,除了BuildInstaller
  5. 现在在文本编辑器中打开BuildInstaller.vcxproj,并在结束</Project>标记之前添加以下代码段:
  1. Add new project BuildInstaller into your solution,
  2. In Configuration Manager uncheck the checkbox "Build" for this new project for all combinations of Configuration/Platform,
  3. Still in Configuration Manager, create new configuration, lets say Installers,
  4. For this new configuration, uncheck the "Build" checkbox for all the projects from the solution, except for the BuildInstaller,
  5. Now open the BuildInstaller.vcxproj in text editor and append the following snippet right before the closing </Project> tag:

<ItemGroup>
  <ProjectsToBuild Include="..\**\*.vcxproj" Exclude="..\**\BuildInstaller.vcxproj"/>
</ItemGroup>
<Target Name="Build" DependsOnTargets="Build_Win32;Build_x64">
  <!-- Run whatever command you like, such as MakeNSIS .. ? -->
  <Exec Command="notepad.exe" />
</Target>
<Target Name="Build_Win32">
  <MSBuild Projects="@(ProjectsToBuild)" Properties="Configuration=Release;Platform=Win32" />
</Target>
<Target Name="Build_x64">
  <MSBuild Projects="@(ProjectsToBuild)" Properties="Configuration=Release;Platform=x64" />
</Target>

  1. 这样,您可以有效地覆盖默认的构建目标
  2. 所以现在:
    • 每次为发布/调试配置而构建时,都不会构建安装程序,出于多种原因,这是首选方法,
    • 每次为安装程序配置进行构建时,新的BuildInstaller.vcxproj都将接管,将构建win32和x64二进制文件,最后将运行自定义命令行可执行文件.当然,将使用所需的Release配置来构建二进制文件.
  1. This way you effectively override the default build target,
  2. So now:
    • Everytime you build for Release/Debug configuration, installer won't be built, that is preferred from many reasons,
    • Everytime you build for Installers configuration, your new BuildInstaller.vcxproj will take over, will build both win32 and x64 binaries and in the end will run the custom command line executable. Of course binaries will be built using Release configuration which should be desired.

最初,我以为我可以删除<ItemGroup>元素并使用Projects="..\Test.sln"而不是Projects="@(ProjectsToBuild)",因为应该没有循环依赖项(BuildInstaller.vcxproj不是为Release构建的),但是构建花费了很多时间,所以不得不有点问题,很奇怪...

Initially I thought I could drop the <ItemGroup> element and use Projects="..\Test.sln" instead of Projects="@(ProjectsToBuild)" as there should be no circular dependency (BuildInstaller.vcxproj is not built for Release) but the build took forever so there had to be some problem, weird...

这满足您的需求吗?

这篇关于使用msbuild构建多体系结构安装程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆