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

查看:38
本文介绍了是否有推荐的方法来使用 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.

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

The constraints:

  1. Pull the code from the VCS only once.
  2. All compiled assemblies should be versioned the same.
  3. Single .csproj (not one per target framework).

I have two approaches in mind:

  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 eleasev3.5 and bin eleasev4.0) so that the NuGet pack step would be able to do its thing based upon the Files section in the .nuspec file.

  2. 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.

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

So my two questions are:

  1. Is it possible to create parameters that are unique to a build step?
  2. Is there a third, better approach?

References:

  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

解决方案

Here is my preferred solution (Option #1):

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.

The single build configuration looks like this:

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:

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

<files>
    <file src="bin
eleasev3.5*.*" target="lib
et35" />
    <file src="bin
eleasev4.0*.*" target="lib
et40" />
</files>

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

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