【问题标题】:dotnet pack recently failingdotnet 包最近失败了
【发布时间】:2020-08-20 16:23:37
【问题描述】:

我们在 Azure Devops 中遇到 NU5118 错误很长时间了,但打包步骤通过了

Starting: Pack
==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version      : 2.167.1
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
C:\windows\system32\chcp.com 65001
Active code page: 65001
e:\vsts\a\_tool\dotnet\dotnet.exe pack e:\vsts\a\4674\s\src\Bentley.Interoperability.APM\Bentley.Interoperability.APM.csproj --configuration Release -o e:\vsts\a\4674\a/nuget /p:Version=1.0.86.0 --no-build --no-restore
Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

e:\vsts\a\_tool\dotnet\sdk\3.1.201\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): error NU5118: File 'C:\Users\prgremotebuilder\.nuget\packages\bentley.interoperability.identityservice.oracle\1.0.69\contentFiles\any\netstandard2.0\scripts\oracle\Create-Identity.sql' is not added because the package already contains file 'content\Create-Identity.sql' [e:\vsts\a\4674\s\src\Bentley.Interoperability.APM\Bentley.Interoperability.APM.csproj]
e:\vsts\a\_tool\dotnet\sdk\3.1.201\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): error NU5118: File 'C:\Users\prgremotebuilder\.nuget\packages\bentley.interoperability.identityservice.oracle\1.0.69\contentFiles\any\netstandard2.0\scripts\oracle\Create-Identity.sql' is not added because the package already contains file 'contentFiles\any\netstandard2.1\Create-Identity.sql' [e:\vsts\a\4674\s\src\Bentley.Interoperability.APM\Bentley.Interoperability.APM.csproj]
e:\vsts\a\_tool\dotnet\sdk\3.1.201\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): error NU5118: File 'C:\Users\prgremotebuilder\.nuget\packages\bentley.interoperability.identityservice.oracle\1.0.69\contentFiles\any\netstandard2.0\scripts\oracle\Identity-SP.sql' is not added because the package already contains file 'content\Identity-SP.sql' [e:\vsts\a\4674\s\src\Bentley.Interoperability.APM\Bentley.Interoperability.APM.csproj]
e:\vsts\a\_tool\dotnet\sdk\3.1.201\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): error NU5118: File 'C:\Users\prgremotebuilder\.nuget\packages\bentley.interoperability.identityservice.oracle\1.0.69\contentFiles\any\netstandard2.0\scripts\oracle\Identity-SP.sql' is not added because the package already contains file 'contentFiles\any\netstandard2.1\Identity-SP.sql' [e:\vsts\a\4674\s\src\Bentley.Interoperability.APM\Bentley.Interoperability.APM.csproj]
  Successfully created package 'e:\vsts\a\4674\a\nuget\Bentley.Interoperability.APM.1.0.86.nupkg'.
Info: Azure Pipelines hosted agents have been updated to contain .Net Core 3.x (3.0 and 3.1) SDK/Runtime along with 2.1. Unless you have locked down a SDK version for your project(s), 3.x SDK might be picked up which might have breaking behavior as compared to previous versions. 
Some commonly encountered changes are: 
If you're using `Publish` command with -o or --Output argument, you will see that the output folder is now being created at root directory rather than Project File's directory. To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
Finishing: Pack

但现在它失败了:

它具有相同的错误消息,但现在还有“Dotnet 命令失败,以下项目中的退出代码非零...”

Starting: Nuget: Pack
==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version      : 2.173.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
C:\windows\system32\chcp.com 65001
Active code page: 65001
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
e:\vsts\b\_tool\dotnet\dotnet.exe pack e:\vsts\b\6232\s\src\Bentley.Interoperability.APM\Bentley.Interoperability.APM.csproj --configuration Release -o e:\vsts\b\6232\a/nuget /p:Version=1.0.244.0 --no-build
Microsoft (R) Build Engine version 16.7.0-preview-20360-03+188921e2f for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

e:\vsts\b\_tool\dotnet\sdk\3.1.401\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): error NU5118: File 'C:\Users\prgremotebuilder\.nuget\packages\bentley.interoperability.identityservice.oracle\1.0.69\contentFiles\any\netstandard2.0\scripts\oracle\Create-Identity.sql' is not added because the package already contains file 'content\Create-Identity.sql' [e:\vsts\b\6232\s\src\Bentley.Interoperability.APM\Bentley.Interoperability.APM.csproj]
e:\vsts\b\_tool\dotnet\sdk\3.1.401\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): error NU5118: File 'C:\Users\prgremotebuilder\.nuget\packages\bentley.interoperability.identityservice.oracle\1.0.69\contentFiles\any\netstandard2.0\scripts\oracle\Create-Identity.sql' is not added because the package already contains file 'contentFiles\any\netstandard2.1\Create-Identity.sql' [e:\vsts\b\6232\s\src\Bentley.Interoperability.APM\Bentley.Interoperability.APM.csproj]
e:\vsts\b\_tool\dotnet\sdk\3.1.401\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): error NU5118: File 'C:\Users\prgremotebuilder\.nuget\packages\bentley.interoperability.identityservice.oracle\1.0.69\contentFiles\any\netstandard2.0\scripts\oracle\Identity-SP.sql' is not added because the package already contains file 'content\Identity-SP.sql' [e:\vsts\b\6232\s\src\Bentley.Interoperability.APM\Bentley.Interoperability.APM.csproj]
e:\vsts\b\_tool\dotnet\sdk\3.1.401\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): error NU5118: File 'C:\Users\prgremotebuilder\.nuget\packages\bentley.interoperability.identityservice.oracle\1.0.69\contentFiles\any\netstandard2.0\scripts\oracle\Identity-SP.sql' is not added because the package already contains file 'contentFiles\any\netstandard2.1\Identity-SP.sql' [e:\vsts\b\6232\s\src\Bentley.Interoperability.APM\Bentley.Interoperability.APM.csproj]
##[error]Error: The process 'e:\vsts\b\_tool\dotnet\dotnet.exe' failed with exit code 1
Info: Azure Pipelines hosted agents have been updated to contain .Net Core 3.x (3.1) SDK/Runtime along with 2.1. Unless you have locked down a SDK version for your project(s), 3.x SDK might be picked up which might have breaking behavior as compared to previous versions. 
Some commonly encountered changes are: 
If you're using `Publish` command with -o or --Output argument, you will see that the output folder is now being created at root directory rather than Project File's directory. To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
##[error]Dotnet command failed with non-zero exit code on the following projects : e:\vsts\b\6232\s\src\Bentley.Interoperability.APM\Bentley.Interoperability.APM.csproj
Finishing: Nuget: Pack

【问题讨论】:

  • 除此之外,还写着Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.

标签: .net azure-devops


【解决方案1】:

我可以确认我们已经看到了完全相同的行为,而我们没有对构建管道或源代码进行任何更改。第一个失败的构建在任务日志顶部的横幅中也有 Version : 2.173.0

在我们的例子中,错误是由于多个依赖的 nuget 包都包含一个 .targets 文件,其中一个元素是这个:

<Content Include="Deployment\**\*.*" Pack="true" PackagePath="\..\Deployment\" />

该错误一直被任务记录,只有以前的版本忽略它并仍然通过构建。这是可行的,因为尽管出现错误,nuget pack 仍会发出 .nupkg 文件。

我们的解决方法是在 include 之前添加一个 Remove 元素:

<Content Remove="Deployment\**\*.*" />
<Content Include="Deployment\**\*.*" Pack="true" PackagePath="\..\Deployment\" />

【讨论】:

  • 在我们的例子中,错误也一直被记录下来,但最近构建管道开始失败。为了解决这个问题,我已经为项目属性添加了抑制警告。 ;NU5118
【解决方案2】:

您提供的日志显示发生错误是因为您的 .NET Core SDK/运行时版本太旧。

推荐的解决方案是在原始任务之前添加UseDotNet 任务:

- task: UseDotNet@2
  inputs:
    version: {version}

您还可以将自托管代理与您想要的 .NET Core SDK/运行时版本一起使用,而不是使用托管代理或使用更新的版本。但这两种解决方案都会显着改变建筑环境,因此需要根据您的情况谨慎使用。

【讨论】:

  • 我们使用的是 3.1。在日志中显示:e:\vsts\a_tool\dotnet\sdk\3.1.201\Sdks\NuGet.Build.Tasks.Pack
  • @Derek 你有没有试过在本地运行它?会成功吗?
  • @Jane 我已经通过运行dotnet pack 在本地重现了该错误,它以红色显示为错误,但仍会生成 .nupkg。改变的是管道任务在 2.173.0 或 2.172.x 版本中无法构建。以前的版本在构建日志中记录了错误,但构建通过了。
【解决方案3】:

dotnet 包最近失败

根据报错信息:

错误 NU5118:未添加文件“Create-Identity.sql”,因为 包已经包含文件'content\Create-Identity.sql'

您的项目中似乎有IncludeSource=true,并且有多个文件具有相同的文件名。这就是为什么它说包已经包含文件的原因。

要解决此问题,最简单的方法是删除相同的文件或尽可能重命名它们。

如果我们无法删除或重命名这些文件,我们可以尝试使用不同目标路径中的这些文件来自定义 nuspec 文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-08
    • 2017-02-01
    • 2018-12-17
    • 1970-01-01
    • 2022-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多