简体   繁体   English

VS2010构建脚本以将DLL打包到MSI并在GAC中注册

[英]VS2010 build scripts to package DLLs into an MSI & register in the GAC

I have a requirement to package up and release a .NET control library across multiple platforms and have a question on how to automate this deployment (or make as efficient as possible) through build scripts and VS2010 configurations. 我需要跨多个平台打包和发布.NET控件库,并且有关于如何通过构建脚本和VS2010配置自动化此部署(或尽可能高效)的问题。

The control library is to be released as a Silverlight version (separate builds for SL 3.0, 4.0, 5.0) and WPF version (separate builds for .NET3.5 / .NET4.0). 控件库将作为Silverlight版本(SL 3.0,4.0,5.0的单独版本)和WPF版本(.NET3.5 / .NET4.0的单独版本)发布。 I also need to specify release and trial versions of the same libraries. 我还需要指定相同库的发行版和试用版。 Trial versions will be differentiated in code with a preprocessor statement TRIAL. 试用版将在代码中与预处理程序语句TRIAL区分开来。 Both the trial and full version will be compiled in RELEASE mode. 试用版和完整版都将以RELEASE模式编译。

I'm wondering how to achieve this in the most efficient way possible. 我想知道如何以最有效的方式实现这一目标。 My VS2010 solution currently has one project for WPF (.NET 4.0) and one separate project for SL (SL 4.0). 我的VS2010解决方案目前有一个WPF(.NET 4.0)项目和一个SL(SL 4.0)项目。

  • Do I need to create further csproj projects for the missing versions, eg .NET 3.5 and SL 3.0 and 5.0? 我是否需要为缺少的版本创建更多的csproj项目,例如.NET 3.5和SL 3.0和5.0?
  • I wish to create one MSI for all Silverlight DLLs and one MSI for all WPF dlls. 我希望为所有Silverlight DLL创建一个MSI,为所有WPF dll创建一个MSI。 Do I need to create further MSIs for the versions compiled as Trial? 我是否需要为编译为试用的版本创建更多MSI? What about separate MSIs for each version of the .NET or Silverlight framework? 对于每个版本的.NET或Silverlight框架,单独的MSI怎么样?
  • Is it possible to achieve the above deployment packaging using build.targets or build scripts? 是否可以使用build.targets或构建脚本实现上述部署包装?

Basically if I create manually MSIs for all the above combinations and do a full rebuild that would work, but it is also a laborious process when releasing updates. 基本上,如果我为所有上述组合手动创建MSI并执行完全重建,但是在发布更新时这也是一个费力的过程。 I am looking for suggestions on how to achieve this with build scripts, build.targets, MSI configurations or a combination of the above. 我正在寻找有关如何使用构建脚本,build.targets,MSI配置或上述组合实现此目的的建议。

Finally when redistributing the control libraries, installation should ideally result in registration in the GAC. 最后,在重新分发控制库时,理想情况下安装应该在GAC中进行注册。

Any comments / suggestions welcome. 欢迎提出任何意见/建议。

Best regards, 最好的祝福,

If you are releasing for different versions of the framework, then you will need different projects. 如果您要发布不同版本的框架,那么您将需要不同的项目。 You probably could get away with switching the target framework at runtime, but there are so many variables, by the time you get them all figured out and tested, you could have easily created the additional projects. 您可能可以在运行时切换目标框架,但是有很多变量,当您将它们全部弄清楚并进行测试时,您可以轻松创建其他项目。

I think it would be well worth your money to invest in an Installation tool such as Installshield that has built-in support for the rest of the functionality that you desire. 我认为投资安装工具(例如Installshield)非常值得您花钱,该工具内置支持您想要的其他功能。

I believe that you should be able to accomplish all of your needs in a single installshield project using various switches and end user keys (to trigger trial or real installs), but you may potentially consider separating trial and real depending on your licensing scheme. 我相信您应该能够使用各种交换机和最终用户密钥在单个installshield项目中完成所有需求(以触发试用或实际安装),但您可能会考虑根据您的许可方案分离试用版和实际版。

Update 更新

You can also solve this issue through a pure VS2010 solution, it's just more complicated. 您也可以通过纯VS2010解决方案来解决这个问题,它只是更复杂。

Based on your goals, you will need to have a total of 5 projects and each solution will have 2 configurations, one for release one for trial (where the preprocessor define is set). 根据您的目标,您将需要总共5个项目,每个解决方案将有2个配置,一个用于试用版本(设置预处理器定义)。

You might be able to get away with a single build solution that contains all 5 projects since you can reference the output from each project separately within the VS setup project. 您可以使用包含所有5个项目的单个构建解决方案,因为您可以在VS安装项目中单独引用每个项目的输出。

On release, you will have to run the build twice, once for release and once for trial, but you can easily automate this with MSBuild. 在发布时,您必须运行构建两次,一次用于发布,一次用于试用,但您可以使用MSBuild轻松自动执行此操作。

What we did to ease the release process burden was create a small database to hold configuration information about the products (locations of solutions, project files, and assemblies) and a small UI application that builds the apps by first changing the version everywhere necessary and then building the installer solution through the visual studio build process. 我们为减轻发布流程负担所做的工作是创建一个小型数据库来保存有关产品的配置信息(解决方案,项目文件和程序集的位置)以及构建应用程序的小型UI应用程序,首先在必要时更改版本,然后通过visual studio构建过程构建安装程序解决方案。

One very important note that I just remembered as I was typing the above: at one point (it may have been fixed), it was not possible to build Visual Studio 2010 setup projects through MSBuild, which is why we went with building through devenv.com. 我记得的一个非常重要的注意事项是,当我输入上述内容时:在某一点(可能已修复),无法通过MSBuild构建Visual Studio 2010安装项目,这就是我们通过devenv构建的原因。 COM。

For posterities sake I'm recording the solution I came up with thanks to competent_tech 's very informative answer. 为了后人的缘故,我正在记录我提出的解决方案,这要归功于competent_tech的非常丰富的答案。

Solved using an msdos batch file as follows. 使用msdos批处理文件解决如下问题。

  • Dumped the idea of #If Trial switch. 倾倒了#If Trial开关的想法。 Instead component is licensed by licx file so trial build is the same as release build. 相反,组件由licx文件许可,因此试验版本与发布版本相同。 This means just one solution for dev work which build outputs are derived from 这意味着只有一个开发工作的解决方案,构建输出源自
  • Created a batch file to rebuild Silverlight and WPF output projects with MSBuild, switching toolsversion to create multiple versions 创建批处理文件以使用MSBuild重建Silverlight和WPF输出项目,切换toolversion以创建多个版本
  • Copied DLLs over to Nuget style directory structure, eg Build/lib/net40, Build/lib/sl4, Build/lib/sl5 etc... 将DLL复制到Nuget样式目录结构,例如Build / lib / net40,Build / lib / sl4,Build / lib / sl5等......
  • Obfuscate built libs in place 混淆构建的库
  • XCopy example projects over to Build/examples/ XCopy示例项目到Build / examples /
  • Use Powershell to edit example projects to reference new obfuscated output. 使用Powershell编辑示例项目以引用新的混淆输出。

For reference, please see the following questions and answers on removing/re-adding references and editing project files with powershell 有关删除/重新添加引用和使用PowerShell 编辑项目文件的信息 ,请参阅以下问题和解答

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM