Is there a recommended approach to configuring a NuGet package targeting multiple frameworks in TeamCity using MSBuild?

元气小坏坏 提交于 2019-12-02 16:20:06

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\release\v3.5\*.*" target="lib\net35" />
    <file src="bin\release\v4.0\*.*" target="lib\net40" />
</files>

Here is a solution taking the second approach:

The project contains the following build configurations and template:

The Shared Build Number Generator is the first build in the chain. It does nothing other than create a build number that the dependent builds will share. I am using the TeamCity-referenced plugin Shared Build Number by Nicholas Williams.

And here are the notable configurations in the build template:

Note the build number is coming from the build ID of the Shared Build Number Generator mentioned above. So, in my case, that build's ID is 14. Also note the variable %TargetFrameworkVersion% in the artifact path. Fortunately, TeamCity supports variable interpolation almost everywhere.

In order for the template to leverage the build number, it must have a snapshot dependency on that build configuration:

And, finally (regarding the template), the build parameters are nearly identical to the parameters in my preferred solution. Note the additional Configuration Parameter, however. This is what will be overridden by the inheriting build configurations:

Then, in the dependent builds, you must wire up a snapshot dependency so that the build number (inherited from the template) actually works by also taking a dependency on the shared build number build configuration:

And, of course, you need to set the actual targeted framework:

With the actual builds configured, you can now configure the NuGet pack build configuration. You do not need to attach to a VCS root:

But you do need to configure a bunch of dependencies (both snapshot and artifact):

And, finally, you're done.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!