Azure DevOps:资产文件没有 '.NETCoreApp,Version=v2.2/linux-x64' 的目标

问题描述 投票:0回答:2

我正在使用任务组在 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 管道相关的内容。

azure-devops azure-pipelines-release-pipeline nuget-package-restore
2个回答
6
投票

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

--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 隐式运行:

此时,如果在

--no-restore
中指定
dotnet build
,默认情况下,它将使用任务“dotnet restore”恢复的包,RID为
win-x64
但是在您的构建任务中,您将构建的
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
并重试

错误信息应该消失了。


0
投票

删除

--no-restore
并不总是有效。您可能正在管道中使用专用的
dotnet restore
任务,因此您的恢复来自私有 ADO Artifacts 提要。隐式恢复可能不会引用您的私人提要。您可以编辑
.csproj
文件并按照错误提示添加运行时 ID,在同一属性组中,如下所示:

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <RuntimeIdentifiers>linux-x64;win-x86;win-x64</RuntimeIdentifiers>
  </PropertyGroup>

这会让你把

--no-restore
留在原地。

© www.soinside.com 2019 - 2024. All rights reserved.