Reputation: 5389
I'm creating a build pipeline for a AspNet Core Web Api in Azure DevOps using a task group that first installs .Net Core SDK (2.2), then does a package restore using dotnet restore
(that uses a VSTS feed) and then builds the project.
At the build step, I supply the following arguments:
--configuration Release --runtime $(Target Platform) --no-restore /p:Version=$(Major Version).$(Minor Version).$(Build.BuildNumber)
.
All the steps up to build
step are successful. However, I get the following error at the build step:
[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
I checked out older answers related Visual Studio however, could not find something related to Azure DevOps pipelines.
Upvotes: 5
Views: 4078
Reputation: 741
Deleting --no-restore
isn't always going to work. You may be using a dedicated dotnet restore
task in your pipeline so your restore comes from a private ADO Artifacts feed. The implicit restore may not reference your private feed. You can edit your .csproj
file and add the runtime IDs as the error suggests, in the same property group like this:
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifiers>linux-x64;win-x86;win-x64</RuntimeIdentifiers>
</PropertyGroup>
This will let you leave the --no-restore
in place.
Upvotes: 1
Reputation: 18958
To solve this issue, please try with deleting --no-restore
.
To explain why it's no issue locally, that's because while you build the project locally, it is using the previous version of obj file which exists in the cache if the current file does not satisfied the compile condition. You can try with deleting the bin and obj files locally, and run these commands again. You will also see the same error. It was the error I ever meet locally, and solved with deleting --no-restore
.
As default, if you did not specified the --runtime linux-x64
, the RID of package it restored is win-x64
. You can test with only run dotnet restore task in Azure Devops by using self-hosted agent, and check the project.assets.json file:
You will see that without specifying, the defaulted RID of the package it restored is win-x64
. Same to the dotnet build task, since starting with .NET Core 2.0 SDK, dotnet restore runs implicitly when you run dotnet build:
At this time, if you specified --no-restore
in dotnet build
, as default, it will use the package which restored by the task "dotnet restore" which RID is win-x64
. But in your build task, you specified the runtime
of build as linux-x64
. This does not match the package. That's why you receive the message: 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'.
Just delete --no-restore
and try again
the error message should disappeared.
Upvotes: 6