Azure devops Azure DevOps:资产文件没有';我没有';的目标;。NETCoreApp,版本=v2.2/linux-x64';

Azure devops Azure DevOps:资产文件没有';我没有';的目标;。NETCoreApp,版本=v2.2/linux-x64';,azure-devops,azure-pipelines-release-pipeline,nuget-package-restore,Azure Devops,Azure Pipelines Release Pipeline,Nuget Package Restore,我正在使用一个任务组为Azure DevOps中的AspNet Core Web Api创建一个构建管道,该任务组首先安装.Net Core SDK(2.2),然后使用dotnet restore(使用VSTS提要)执行包还原,然后构建项目 在构建步骤中,我提供以下参数: ——配置发布——运行时$(目标平台)——无恢复/p:Version=$(主版本)。$(次版本)。$(Build.BuildNumber) 到build步骤的所有步骤都成功。但是,我在构建步骤中遇到以下错误: [command]

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

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

——配置发布——运行时$(目标平台)——无恢复/p: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管道相关的内容。

若要解决此问题,请尝试删除
--无还原

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

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

您将看到,在不指定的情况下,它还原的包的默认RID是
win-x64
。与“dotnet build”任务相同,因为从.NET Core 2.0 SDK开始,“dotnet restore”在运行“dotnet build”时隐式运行:

此时,如果您在
dotnet build
中指定了
--no restore
,则默认情况下,它将使用由任务“dotnet restore”还原的包,该任务是
win-x64
但是在构建任务中,您将构建的
运行时
指定为
linux-x64
。这与软件包不匹配。这就是您收到消息的原因:
error NETSDK1047:Assets文件“D:\a\1\s\WebApp\obj\project.Assets.json”没有“.NETCoreApp,Version=v2.2/linux-x64”的目标。

只需删除
--不恢复
,然后重试


错误消息应该消失。

本地我想没有问题?@Shaykibaramczyk是的,本地没有问题。尝试在生成之前在本地和管道中运行
dotnet--info
,检查是否有差异。有差异,如.Net Core SDK的补丁版本。我应该寻找什么样的差异?如果只是补丁的话,我认为应该有效。您是否将obj/bin文件夹上载到源代码管理?我同意出现错误的原因。但我不确定是否可以删除
dotnet restore
,因为我的项目中没有Nuget.config,因此管道不会知道它需要使用私有的Nuget提要。我想我应该在构建步骤之前的步骤中使用
dotnet restore-r linux-x64-s“path/to/nuget/config”
?不需要删除
dotnet restore
,只需删除
——dotnet build中的不还原就可以了。如果我删除它,它会尝试执行隐式还原,对吗?但它没有用于执行此还原的Nuget.config。那么,它将使用哪些Nuget源进行隐式还原?是的,它将使用。而且,您不必担心repos中没有Nuget、config文件。请参阅此文档:。如果服务器在项目文件的根路径中找不到Nuget.config,它将使用生成计算机中存在的全局Nuget.config。默认情况下,如果计算机是Windows,则全局Nuget.config位于
%appdata%\Nuget\Nuget.config
中。因此,即使您指定了
--no restore
。它还可以恢复相关的软件包。