【问题标题】:Azure DevOps: Assets file doesn't have a target for '.NETCoreApp,Version=v2.2/linux-x64'Azure DevOps:资产文件没有“.NETCoreApp,Version=v2.2/linux-x64”的目标
【发布时间】:2019-09-02 08:56:11
【问题描述】:

我正在使用一个任务组在 Azure DevOps 中为 AspNet Core Web Api 创建一个构建管道,该任务组首先安装 .Net Core SDK (2.2),然后使用 dotnet restore(使用 VSTS 源)进行包还原然后构建项目。

在构建步骤中,我提供以下参数:

--configuration Release --runtime $(Target Platform) --no-restore /p:Version=$(Major Version).$(Minor Version).$(Build.BuildNumber).

直到build 步骤的所有步骤都成功。但是,我在构建步骤中收到以下错误:

[command]C:\windows\system32\chcp.com 65001
Active code page: 65001
[command]C:\hostedtoolcache\windows\dotnet\dotnet.exe build D:\a\1\s\WebApp\WebApp.csproj --configuration Release --runtime linux-x64 --no-restore /p:Version=1.0.40
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

C:\hostedtoolcache\windows\dotnet\sdk\2.2.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(208,5): error NETSDK1047: Assets file 'D:\a\1\s\WebApp\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v2.2/linux-x64'. Ensure that restore has run and that you have included 'netcoreapp2.2' in the TargetFrameworks for your project. You may also need to include 'linux-x64' in your project's RuntimeIdentifiers. [D:\a\1\s\WebApp\WebApp.csproj]

Build FAILED.

C:\hostedtoolcache\windows\dotnet\sdk\2.2.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(208,5): error NETSDK1047: Assets file 'D:\a\1\s\WebApp\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v2.2/linux-x64'. Ensure that restore has run and that you have included 'netcoreapp2.2' in the TargetFrameworks for your project. You may also need to include 'linux-x64' in your project's RuntimeIdentifiers. [D:\a\1\s\WebApp\WebApp.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.53
##[error]Error: The process 'C:\hostedtoolcache\windows\dotnet\dotnet.exe' failed with exit code 1
##[error]Dotnet command failed with non-zero exit code on the following projects : D:\a\1\s\WebApp\WebApp.csproj
##[section]Finishing: Build

我查看了与 Visual Studio 相关的旧答案,但找不到与 Azure DevOps 管道相关的内容。

【问题讨论】:

  • 本地我猜没有问题?
  • @ShaykiAbramczyk 是的,本地没问题。
  • 在构建之前尝试在本地和管道中运行dotnet --info,并检查是否存在差异。
  • .Net Core SDK 的补丁版本等存在差异。我应该寻找什么样的差异?
  • 如果只是补丁,我认为它应该可以工作。您是否将 obj/bin 文件夹上传到源代码管理?

标签: azure-devops azure-pipelines-release-pipeline nuget-package-restore


【解决方案1】:

要解决这个问题,请尝试删除--no-restore

解释为什么在本地没有问题,那是因为当你在本地构建项目时,如果当前文件不满足编译,它使用的是缓存中存在的旧版本 obj 文件健康)状况。您可以尝试在本地删除 binobj 文件,然后再次运行这些命令。您还将看到相同的错误。这是我在本地遇到的错误,通过删除 --no-restore 解决。

默认情况下,如果你没有指定--runtime linux-x64,它恢复的包的RID是win-x64。您可以使用自托管代理在 Azure Devops 中仅运行 dotnet restore 任务进行测试,并检查 project.assets.json 文件:

你会看到,如果没有指定,它恢复的包的默认 RID 是win-x64。与 dotnet build 任务相同,因为从 .NET Core 2.0 SDK 开始,当您运行 dotnet build 时,dotnet restore 会隐式运行

此时,如果你在dotnet build中指定了--no-restore,默认会使用RID为win-x64的任务“dotnet restore”恢复的包。 但是在您的构建任务中,您将构建的runtime 指定为linux-x64。这与包不匹配。这就是您收到消息的原因:error NETSDK1047: Assets file 'D:\a\1\s\WebApp\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v2.2/linux-x64'.

只需删除--no-restore,然后重试

错误信息应该消失了。

【讨论】:

  • 我同意我收到错误的原因。但不确定我是否可以删除dotnet restore,因为我的项目中没有 Nuget.config,因此管道不会知道它需要使用私有 nuget 提要。我想我应该在构建步骤之前的步骤中使用dotnet restore -r linux-x64 -s "path/to/nuget/config"
  • 不需要删除dotnet restore,在dotnet build中删除--no-restore就可以了。
  • 如果我删除它,它会尝试进行隐式还原,对吗?但它没有 Nuget.config 来执行此还原。那么,它将使用哪些 Nuget 源来进行这种隐式还原?
  • 是的,它会的。而且,您无需担心在您的存储库中没有 Nuget,config 文件。请参阅此文档:docs.microsoft.com/en-us/nuget/consume-packages/…。如果服务器在项目文件的根路径中找不到 Nuget.config,它将使用构建机器中存在的全局 Nuget.config。默认情况下,如果计算机是 Windows,则全局 Nuget.config 位于 %appdata%\NuGet\NuGet.Config
  • 所以,即使您指定了--no-restore。它还可以恢复相关的包。
猜你喜欢
  • 2020-03-09
  • 2021-01-09
  • 1970-01-01
  • 2022-06-14
  • 2022-07-22
  • 1970-01-01
  • 2018-06-07
  • 2018-06-20
  • 2018-10-21
相关资源
最近更新 更多