Azure DevOps:资产文件没有“ .NETCoreApp,版本= v2.2 / linux-x64”的目标

时间:2019-09-02 08:56:11

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

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

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

--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管道有关的内容。

1 个答案:

答案 0 :(得分:2)

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

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

默认情况下,如果未指定--runtime linux-x64,则还原的软件包的RID为win-x64。您可以使用自托管代理在Azure Devops中仅运行 dotnet restore 任务进行测试,然后检查project.assets.json文件:

enter image description here

您将看到,未指定,恢复的软件包的默认RID为win-x64。与 dotnet构建任务相同,因为从.NET Core 2.0 SDK开始,当您运行dotnet build 时,dotnet还原会隐式运行:

enter image description here

这时,如果您在--no-restore中指定了dotnet build,则默认情况下,它将使用由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,然后重试

enter image description here

错误消息应该消失了。