本文介绍了适用于不同.NET Framework的TeamCity NuGet软件包构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在对.NET Framework目标版本的项目进行更新,这些项目更新到最新的.NET(4.6.2).

I've been doing updates to .NET Framework targeted versions of projects updating to latest .NET (4.6.2).

其中一些项目是在TeamCity 9.0.2中构建的NuGet软件包.

Some of these projects are NuGet packages, built in TeamCity 9.0.2.

我已使用指南为不同的.NET Framework版本创建多个构建配置,因为我尚未更新至4.6.2的某些项目引用了NuGet软件包.因此,我试图让TeamCity使用这些构建配置来输出各种Net40,Net45,Net46和Net462版本,以便我具有完全的兼容性,而不必在更新软件包时强制升级使用NuGet的所有项目.

I've use the steps in this guide to create multiple build configurations for different .NET Framework version as some of the projects I haven't updated to 4.6.2 reference the NuGet packages. So I am trying to get TeamCity to use these build configurations to output the various Net40, Net45, Net46 and Net462 versions so that I have full compatibility without forcing the need to upgrade all projects that use the NuGet when updating the packages.

我真的不知道如何在TeamCity中做到这一点.我相当确定应该在构建步骤"配置中完成此操作,但是到目前为止,我还没有设法使它生效.

I really can't figure out how to do this in TeamCity. I am fairly sure that this should be done in the "Build Steps" configuration, but so far I've not managed to get this to work.

所以我尝试了一件事情,我认为我需要做,但是不确定是否重复第一步,并将Configuration设置为Release-Net46.我认为这是必要的,否则将无法构建该版本的程序集(如果我对此有误,请纠正我!)

So one thing I've tried, which I think I need to do but am not sure is duplicate the first build step and set the Configuration to Release-Net46. I think this is necessary otherwise this version of the assembly wouldn't be built (please correct me if I'm wrong about that!)

我尝试的第二件事是复制NuGet Pack步骤并在Properties设置Configuration=Release-Net46中,但是所做的只是用Net46替换了Net462版本,并且没有像我希望的那样包含这两个工件

The second thing I've tried is to duplicate the NuGet Pack step and in Properties set Configuration=Release-Net46 but all that did was replace the Net462 version with Net46 and not include both in the artifacts like I'd hoped.

我还尝试在NuGet PackProperties中具有多个Configuration元素,例如Configuration=Release;Configuration=Release-Net46Configuration=Release,Release-Net46,但是这两个元素都导致构建完全失败,这不是答案.

I also tried in the Properties of NuGet Pack to have multiple Configuration elements like Configuration=Release;Configuration=Release-Net46 or Configuration=Release,Release-Net46 but both of those resulted in the build failing altogether so clearly that's not the answer.

我认为必须有一种方法可以执行此NuGet Pack生成步骤,以从其他生成配置中获取输出,并将程序集的所有可用版本输出到工件.

I think there must be a way to get this NuGet Pack build step to pick up the output from the other build configurations and output all available versions of the assembly to the artifacts.

有可能吗?我曾考虑过为TeamCity中的每个构建配置创建单独的项目,但是我不确定这是否正确,否则会导致软件包提要出现问题,对于每个.NET Framework版本,将项目重复四次似乎很麻烦.

Is that possible? I had thought about creating separate projects for each build configuration in TeamCity but I'm unsure if that's the correct way or it that would cause issues with the package feed and it would seem untidy to duplicate the project four times for each .NET Framework version.

推荐答案

好吧,我最终通过反复试验解决了这一问题,并了解了NuSpec.请注意,我没有找到一种完全使用TeamCity设置的方法,但这同样好.

Ok I ended up solving this through trial and error and learning about NuSpec. Note, I didn't find a way to do this using purely TeamCity settings but this is equally good.

我是正确的,您需要额外的构建步骤来在解决方案/项目级别的构建配置中构建程序集,并将每个Configuration指向Release-NetX.

I was correct that you need extra build steps to build the assemblies in the solution/project level build configurations and point each Configuration at Release-NetX.

EDIT 我发现上面最好将NetX构建步骤指向.csproj而不是.sln.这样,您就不需要解决方案级别的构建配置,只要它们存在于.csproj中,那么它们就可以很好地构建.

EDIT I've found it's actually best in the above to point the NetX build steps at the .csproj rather than the .sln. That way you don't need the build configurations at a solution level, as long as they exist in the .csproj then it will all build fine.

完成此操作后,TC将把所有版本构建到各自的bin\Release-NetX目录中.

Once this is done, TC will then be building all versions into their respective bin\Release-NetX directories.

下一步是将.nuspec文件添加到解决方案项目的根目录中,以为其构建NuGet.

Next was to add a .nuspec file to the root directory of the solution project to build the NuGet for.

<?xml version="1.0"?>
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <id>Foo.Bar.Package</id>
    <version>1.0.23</version>
    <authors>FooBar Industries</authors>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>FooBar Industries package</description>
  </metadata>
  <files>
    <file src="bin\Release\*.dll" target="lib\net462" />
    <file src="bin\Release-Net46\*.dll" target="lib\net46" />
    <file src="bin\Release-Net45\*.dll" target="lib\net45" />
    <file src="bin\Release-Net4\*.dll" target="lib\net40" />
  </files>
</package>

下一步是更改NuGet Pack TeamCity构建步骤,并在Specification files部分中,将其指向您的.nuspec文件. Prefer project files to .nuspec有一个复选框.只需取消选中它即可为我工作,我什至无需指向.nuspec文件.

Next is to alter the NuGet Pack TeamCity Build Step and in Specification files section and point this to your .nuspec file. There's a checkbox for Prefer project files to .nuspec. It worked for my just by unchecking this and I didn't even need to point to .nuspec file.

然后,在触发构建时,将输出所有版本,然后可以使用它们,而无需升级所有引用此软件包的项目.

Then on triggering a build, all versions are outputted and are then available to use without upgrading all projects that reference this package.

这篇关于适用于不同.NET Framework的TeamCity NuGet软件包构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 02:15