C# NuGet pack–;令牌替换有时会失败

C# NuGet pack–;令牌替换有时会失败,c#,tfs,nuget,nuget-package,C#,Tfs,Nuget,Nuget Package,在过去的几天里,我有过一次非常令人沮丧的经历,那就是试图通过TFS为特定项目部署连续交付。该项目是一个内部库,必须在私有NuGet repo上发布,因此其中一个步骤是打包nupkg文件 我现在遇到的问题是,nuget pack在某些情况下抱怨缺少作者和描述,而在其他情况下则没有。My AssemblyInfo.cs对于失败的最简单的项目来说就像它们一样普通: using System.Reflection; using System.Runtime.CompilerServices; using

在过去的几天里,我有过一次非常令人沮丧的经历,那就是试图通过TFS为特定项目部署连续交付。该项目是一个内部库,必须在私有NuGet repo上发布,因此其中一个步骤是打包nupkg文件

我现在遇到的问题是,
nuget pack
在某些情况下抱怨缺少
作者
描述
,而在其他情况下则没有。My 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>
错误之前的输出在其工作的服务器上是相同的(即,使用“A.B.C.nuspec”作为元数据,直到并包括
)。唯一的区别是。。。好。。。它起作用了

请让我知道,如果你能建议任何方向,我可以进一步调查这一点

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

    • 我也有类似的问题。我必须在csproj中包含Description元素并设置为一个值。这个医生很有帮助。

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


      我遇到了同样的错误,在对生成进行排队时,只需在该变量中不加下划线即可。

      您使用的是哪个版本的TFS?构建代理是否也适用于NuGet版本4.6.2.5055?尝试使用项目文件运行
      nuget pack
      ,而不仅仅是
      .nuspec
      ,以查看它是否有帮助:。nuget二进制文件在构建过程中部署,因此保证相同。正如您在最终输出中所看到的,nuget包的目标是csproj,而不是nuspec(请查看该片段顶部的实际命令行)。我不明白TFS的版本会如何影响nuget的行为方式;在这方面我有什么需要注意的地方吗?我想知道TFS的版本,以便在我这边进行测试。您的构建代理是同一版本吗?您可以尝试删除文件夹%BuffdAgNET%x工作,看看结果如何?微软VisualStudio Team Foundation Server版本15112.26307.0,我不确定构建代理是同一版本,我至少安装了6个月;如何检查版本?根据记录,有效的安装时间早于无效的安装时间。清理工作没有帮助。两台服务器之间的一个显著区别是,其中一台是Windows Server 2012 R2(运行正常的服务器),而另一台是Windows Server 2012 Standard。您可以在代理队列中检查生成代理版本--功能。您正在使用TFS 2017.1,请尝试将您的TFS 2017升级到最新的TFS 2017.3.1,然后再试一次。
      C:\Program Files\nuget.4.6.2.exe pack "C:\TFS-Agent\_work\2\s\A.B.C\A.B.C.csproj" -OutputDirectory "C:\TFS-Agent\_work\2\s\publish" -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)\MSBuild\14.0\bin\amd64'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
      Packing files from 'C:\TFS-Agent\_work\2\s\A.B.C\bin\Release'.
      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()