NuGet 包 – 令牌替换有时会失败



在过去的几天里,我在尝试通过TFS为特定项目部署持续交付时遇到了非常令人沮丧的经历。该项目是一个内部库,必须在专用 NuGet 存储库上发布,因此其中一个步骤是打包 nupkg 文件。

我现在遇到的问题是,nuget pack抱怨在某些情况下缺少AuthorsDescription,而在其他情况下则没有。我的AssemblyInfo.cs对于失败的最简单的项目来说,就像它们一样香草:

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("A.B.C")]
[assembly: AssemblyDescription("Some description here")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Company // Department")]
[assembly: AssemblyProduct("A.B.C")]
[assembly: AssemblyCopyright("Copyright ©  2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("88888888-8888-8888-8888-888888888888")]
// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]

我清理了这些值,但我保留了我正在使用的实际值的格式(例如,我们有"LibraryName.Module.Submodule"代替"A.B.C")。

nuspec 文件同样无聊:

<?xml version="1.0"?>
<package >
<metadata>
<!-- Mandatory, static stuff -->
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<description>$description$</description>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<!-- Mandatory stuff you should review upon re-packaging -->
<releaseNotes>The first internal release.</releaseNotes>
<copyright>Copyright 2018</copyright>
<!-- Optional stuff you should only include if you need it -->
<projectUrl>http://www.example.com/</projectUrl>
<!-- <licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl> -->
<!-- <iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl> -->
<!-- <tags>Tag1 Tag2</tags> -->
</metadata>
</package>

运行时nuget pack有时会失败,并显示臭名昭著的">需要作者;描述是必需的"。我随机取得了成功,摆弄了不应该影响该过程的事情,例如添加或删除依赖项,或者在文件系统中移动 nuget 二进制文件。是的,我确实检查过,在所有实验中,二进制路径上的任何地方都没有nuget.config文件——尽管如此,在一些非常精心设计的设置中它可以工作,而在另一些设置中则不然。

我目前在代理池中有两台服务器;在其中一个服务器上,它适用于 nuget 4.6.2,不适用于 4.7.0。另一方面,它与两者都不起作用。当我遇到它工作的设置时,每次我运行构建时它都一致地工作——但现在我有一个服务器可以工作,另一个不能,我完全不知道为什么会发生这种情况(而且它们在构建中都是一致的)。

我发现了一个错误报告,由于与 AssemblyInfo.cs 格式有关的原因,令牌替换失败并出现我遇到的错误,但我认为我的项目并非如此——再说一次,我学会了期待任何事情。

以下是完整的执行日志:

C:Program Filesnuget.4.6.2.exe pack "C:TFS-Agent_work2sA.B.CA.B.C.csproj" -OutputDirectory "C:TFS-Agent_work2spublish" -Properties Configuration=release -Verbosity detailed
NuGet Version: 4.6.2.5055
Attempting to build package from 'A.B.C.csproj'.
MSBuild auto-detection: using msbuild version '14.0' from 'C:Program Files (x86)MSBuild14.0binamd64'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
Packing files from 'C:TFS-Agent_work2sA.B.CbinRelease'.
Using 'A.B.C.nuspec' for metadata.
Authors is required.
Description is required.
System.Exception: Authors is required.
Description is required.
at NuGet.Packaging.Manifest.Validate(Manifest manifest)
at NuGet.Packaging.Manifest.ReadFrom(Stream stream, Func`2 propertyProvider, Boolean validateSchema)
at NuGet.CommandLine.ProjectFactory.ProcessNuspec(PackageBuilder builder, String basePath)
at NuGet.CommandLine.ProjectFactory.CreateBuilder(String basePath, NuGetVersion version, String suffix, Boolean buildIfNeeded, PackageBuilder builder)
at NuGet.Commands.PackCommandRunner.BuildFromProjectFile(String path)
at NuGet.Commands.PackCommandRunner.BuildPackage()
at NuGet.CommandLine.PackCommand.ExecuteCommand()
at NuGet.CommandLine.Command.ExecuteCommandAsync()
at NuGet.CommandLine.Command.Execute()
at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)
System.Exception: Unexpected exit code 1 returned from tool nuget.4.6.2.exe
at Microsoft.TeamFoundation.DistributedTask.Task.Internal.InvokeToolCmdlet.ProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()

直到错误的输出在其工作的服务器上是相同的(即最多并包括Using 'A.B.C.nuspec' for metadata.)。唯一的区别是...井。。。它有效。

如果您可以提出任何方向,请告诉我,我可以进一步调查。

更多详情

  • 代理版本均为 2.112.0
  • 工作的服务器运行Windows Server 2012 R2(Agent.OSVersion =
  • 6.3.9600),不工作的服务器运行Windows Server 2012 Standard(Agent.OSVersion = 6.2.9200)
  • 我尝试将 AssemblyInfo.cs 中的准静态作者和描述复制/粘贴到 nuspec 文件中,但这会破坏数据包版本控制(它们都是使用 1.0.0 版本生成的)。每次手动在两个地方更新版本不是我想要忍受的。
  • 作为临时解决方案,我最终通过对 Agent.OSVersion 功能添加约束来约束服务器上的构建。我不喜欢这个。

我也有类似的问题。我必须在 csproj 中包含描述元素并设置为一个值。这个文档很有帮助。 https://learn.microsoft.com/en-us/nuget/reference/msbuild-targets

我们在 Azure Devops 中有一个生成定义,其中包含一个自定义的 powershell 生成步骤,该步骤在基于生成定义中的变量生成之前修改了 AssemblyInfo.cs 文件。我们使用它来将包的版本标记为 Alpha、Beta 等。

我遇到了同样的错误,只需要在排队构建时在该变量中放置下划线。

最新更新