是否有推荐的方法使用MSBuild在TeamCity中配置针对多个框架的NuGet包? [英] Is there a recommended approach to configuring a NuGet package targeting multiple frameworks in TeamCity using MSBuild?

查看:142
本文介绍了是否有推荐的方法使用MSBuild在TeamCity中配置针对多个框架的NuGet包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了几篇文章(请参阅下面的参考资料),但是还没有找到针对我的技术堆栈的最佳实践指南.

I've read a handful of posts (see references below) and have yet to find a guide on best practices that is specific to my tech stack.

目标:创建单个NuGet包,以通过TeamCity使用MSBuild和NuGet从单个.csproj文件构建的多个.NET框架为目标.

The goal: Create a single NuGet package targeting multiple .NET frameworks built from a single .csproj file via TeamCity using MSBuild and NuGet.

约束:

  1. 仅从VCS中提取一次代码.
  2. 所有编译的程序集的版本应相同.
  3. 单个.csproj(每个目标框架都不一个).

我想到了两种方法:

  1. 创建单个构建配置.它包含三个构建步骤:编译.NET 3.5,编译.NET 4.0,与NuGet打包在一起.每个构建步骤将取决于最后一个步骤的成功.我看到的唯一真正的问题是这种方法(希望有一个我不知道的解决方案)是每个构建步骤都需要使用自己的一组构建参数(例如system.TargetFrameworkVersion和system.OutputPath)来指定DLL所在的唯一位置(例如bin \ release \ v3.5和bin \ release \ v4.0),以便NuGet打包步骤能够根据.nuspec文件中的Files部分执行其操作.

  1. Create a single build configuration. It would contain three build steps: compile .NET 3.5, compile .NET 4.0, pack with NuGet. Each build step would be contingent upon success of the last. The only real problem I see with this approach (and hopefully there's a solution that I'm not aware of) is that each build step would require its own set of build parameters (e.g., system.TargetFrameworkVersion and system.OutputPath) to designate the unique location for the DLL to sit (e.g., bin\release\v3.5 and bin\release\v4.0) so that the NuGet pack step would be able to do its thing based upon the Files section in the .nuspec file.

创建多个构建配置.按照上面概述的构建步骤进行一个构建配置.使用这种方法,可以轻松解决TargetFrameworkVersion和OutputPath构建参数问题,但是现在我必须创建快照依赖项,并在各个构建之间共享程序集版本号.它还占用了构建配置插槽,对我们来说这是可以的(但不是最佳选择),因为我们确实拥有企业许可证.

Create multiple build configurations. One build configuration per the build steps outlined above. With this approach, it is easy to solve the TargetFrameworkVersion and OutputPath build parameters issue but I now have to create snapshot dependencies and share the assembly version number across the builds. It also eats up build configuration slots which is ok (but not optimal) for us since we do have an Enterprise license.

选项1似乎是显而易见的选择.选项#2感觉很脏.

Option #1 seems like the obvious choice. Options #2 feels dirty.

所以我的两个问题是:

  1. 是否可以创建对于构建步骤唯一的参数?
  2. 还有第三种更好的方法吗?

参考文献:

  1. 多框架NuGet构建带有内部符号依赖管理
  2. Nuget-将解决方案与多个项目打包在一起(针对多个框架)
  3. http://lostechies.com/joshuaflanagan/2011/06/23/tips-for-building-nuget-packages/
  4. http://msdn.microsoft.com/en-us/library /hh264223.aspx
  5. https://stackoverflow.com/a/1083362/607701
  6. http://confluence.jetbrains.com/display/TCD7/Configuring + Build +参数
  7. http://docs.nuget.org /docs/creating-packages/creating-and-publishing-a-package
  1. Multi-framework NuGet build with symbols for internal dependency management
  2. Nuget - packing a solution with multiple projects (targeting multiple frameworks)
  3. http://lostechies.com/joshuaflanagan/2011/06/23/tips-for-building-nuget-packages/
  4. http://msdn.microsoft.com/en-us/library/hh264223.aspx
  5. https://stackoverflow.com/a/1083362/607701
  6. http://confluence.jetbrains.com/display/TCD7/Configuring+Build+Parameters
  7. http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package

推荐答案

以下是我的首选解决方案(选项1):

魔术依靠一个不幸的解决方法.如果您愿意为此做出让步,则此解决方案确实有效.如果不是,则可以关注我在JetBrains的问题跟踪器上打开的问题.

The magic relies on an unfortunate workaround. If you're willing to make this compromise, this solution does work. If you are not, you can follow the issue that I opened on JetBrains' issue tracker.

单个构建配置如下:

记下前两个构建步骤的名称.实际上,它们分别被明确命名为.NET 3.5和4.0的TargetFrameworkVersion值.

Note the name of the first two build steps. They are, in fact, named explicitly as the TargetFrameworkVersion values for .NET 3.5 and 4.0, respectively.

然后,在构建参数"部分中,配置了以下参数:

Then, in the Build Parameters section, I have configured the following parameters:

最后,Nuget Pack步骤根据我的.nuspec的文件部分执行文件路径转换:

And finally, the Nuget Pack step does the file path translation according to my .nuspec's files section:

<files>
    <file src="bin\release\v3.5\*.*" target="lib\net35" />
    <file src="bin\release\v4.0\*.*" target="lib\net40" />
</files>

这篇关于是否有推荐的方法使用MSBuild在TeamCity中配置针对多个框架的NuGet包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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