Azure Pipeline: dotnet publish fails - assets.json doesn't have a target for '.NETCoreApp,Version=v3.1/win-x64'

Viewed 1848

I have a .NetCore 3.1 commandline app. When buidling locally and publishing, it works completely fine using below commandline

dotnet publish -c dev -r win-x64 --self-contained true

In the Azure pipeline - I had to do the dotnet restore before doing a publish using the above command. Whilst publishing I had to add extra param --no-restore, as per Microsoft's recommendation here as I have private nuget feeds. dotnet publish -c dev -r win-x64 --self-contained true --no-restore

Most dotnet commands, including build, publish, and test include an implicit restore step. This will fail against authenticated feeds, even if you ran a successful dotnet restore in an earlier step, because the earlier step will have cleaned up the credentials it used.

To fix this issue, add the --no-restore flag to the Arguments textbox.

Now, the publish part of the pipeline has started failing with the error -

C:\Program Files\dotnet\sdk\3.1.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1047: Assets file 'MyProject\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v3.1/win-x64'. Ensure that restore has run and that you have included 'netcoreapp3.1' in the TargetFrameworks for your project. You may also need to include 'win-x64' in your project's RuntimeIdentifiers.

Am not using a publish xml, but specifying all the arguments as shown above in the command line. I've checked the csproj has the target framework specified

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <Configurations>Debug;Release;dev;test;pre;prod</Configurations>
  </PropertyGroup>

Need any pointers as to what might be going wrong here?

Thanks

1 Answers

Please add RuntimeIdentifier as mentioned in the error message:

<PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <Configurations>Debug;Release;dev;test;pre;prod</Configurations>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>

Please also check PlatformTarget.

 <PlatformTarget>AnyCPU</PlatformTarget>

I guess the local machine has a different OS than the build agent.

Related