58

at the moment I have a microservice made in c # with web api and net core 2.0

in the nutget packages I have already found a version 2.1 of net core and I have decided to install it, in order to update my app. I changed the target as shown below

enter image description here

But when I try to compile it generates this bug

enter image description here

The project was restored using Microsoft.NETCore.App version 2.1.0, but with current settings, version 2.1.0-rtm-26515-03 would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore.

And my dependencies remained that way

enter image description here

dasuma
  • 781
  • 1
  • 6
  • 12

7 Answers7

109

The project was restored using Microsoft.NETCore.App version 2.1.0, but with current settings, version 2.1.0-rtm-26515-03 would be used instead

This is a known issue at this moment. To resolve this issue, you can try following workarounds:

  • Add TargetLatestRuntimePatch attribute in .csproj file:

    <PropertyGroup>
      <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
    </PropertyGroup>
    

Or

  • set RuntimeFrameworkVersion and RuntimeIdentifier in .csproj file:

     <PropertyGroup>
       <RuntimeFrameworkVersion>2.1.1</RuntimeFrameworkVersion>
       <PlatformTarget>AnyCPU</PlatformTarget>
       <RuntimeIdentifier>win-x64</RuntimeIdentifier>
     </PropertyGroup>
    

If above workaround not work for you, please check more workarounds on the investigation issue.

See Self-contained deployment runtime roll forward for more information.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • 1
    For me the first option worked. I added the suggested TargetLatestRunTimePatch node to the csproj file that was reported in the error pane. After that the publish worked. The specific csproj file it was complaining about wasn't even the project I'm trying to publish, but is one of many referenced by it. – David Gunderson Oct 05 '18 at 05:18
  • I only needed the `` tag. The `` tag was not needed. First option didn't help me. – daniel.caspers Apr 01 '19 at 21:36
  • I have tried various versions of .Net Core, neither of these worked for me. – johnstaveley Sep 27 '19 at 10:09
  • In my case it started spontaneously. I closed VS2019 and reopened. All clear... – Erik Oct 10 '19 at 15:29
  • Don't forget to add the 1st option's tag to other projects involved in the build/publish/restore. Check the error message to confirm which project the restore is failing on. – Luke Dec 09 '19 at 13:22
8

I wanted to publish an ASP.NET Core 2.1 Console app and got errors about colliding versions 2.1.0 and 2.1.6.

Since I had lot of projects in my solution (and VS did not give me any hints on which projects were problematic, I created a file Directory.Build.props with the following contents and placed it in the directory where my .sln file was

<Project>
  <PropertyGroup>
    <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
    <GenerateFullPaths>true</GenerateFullPaths>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>
</Project>

The important thing here is the <TargetLatestRuntimePatch> entry.

This way, all the projects use the same settings and I did not have to synchronize those manually.

Doc of Directory.Build.props is here https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2017

ToastedSoul
  • 1,296
  • 1
  • 17
  • 27
3

I have solved the issue as follows:

First, add following code into .csproj file

<PropertyGroup>
   <RuntimeFrameworkVersion>2.1.1</RuntimeFrameworkVersion>
   <PlatformTarget>AnyCPU</PlatformTarget>
   <RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>

Next, check Microsoft.AspNetCore.App version is 2.1.1. if not please install this version.

Lastly, restore your package with 2.1.1 version. To restore run following code from package manager console

Install-Package Microsoft.NETCore.App -Version 2.1.1
Alamgir
  • 686
  • 8
  • 14
2

As @Leo Liu-MSFT mentioed, I had to set the RuntimeFrameworkVersion and RuntimeIdentifier in .csproj file:

 <PropertyGroup>
   <RuntimeFrameworkVersion>2.1.1</RuntimeFrameworkVersion>
   <PlatformTarget>AnyCPU</PlatformTarget>
   <RuntimeIdentifier>win-x64</RuntimeIdentifier>
 </PropertyGroup>

But then importantly, I had to restore packages for the solution.

ViqMontana
  • 5,090
  • 3
  • 19
  • 54
0

I got this today with respectively version 2.2.7 and "but with current settings 2.2.8... etc." after upgrading Visual Studio to version 16.4.0. Also, Nuget PackageManager would crash afterwards with

the composition produced multiple composition errors... (lots of crazy stuff here)

Ended up solving it by wiping (i.e. deleted all files in) C:\Users\my.username\AppData\Local\Microsoft\VisualStudio\16.0_79dcc3fa\ComponentModelCache

Frederik Struck-Schøning
  • 12,981
  • 8
  • 59
  • 68
0

I built projects separately, discovered a missing reference and it seemed to fix it - no thanks to the low-quality error message.

Ian Warburton
  • 15,170
  • 23
  • 107
  • 189
0

I my case. The Visual Studio created a *.tmp file in AppData\Local\Temp. After I deleted all *.tmp files the publish worked.