12
votes

I've created a sample project using dotnet, but I get the following error when building the project:

error : The project was restored using Microsoft.NETCore.App version 2.1.0-rc1, but with current settings, version 2.1.0-preview3-26411-06 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.

What's the problem? I'm using Visual Studio 2017 build 15.7.0.

10

10 Answers

18
votes

I had a similar error message:

The project was restored using Microsoft.NETCore.App version 2.0.7, but with current settings, version 2.0.0 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

I added the RuntimeFrameworkVersion setting to the .csproj file, and it fixed an issue for me:

<PropertyGroup>
   <TargetFramework>netcoreapp2.0</TargetFramework>
   <RuntimeFrameworkVersion>2.0.7</RuntimeFrameworkVersion><!--here is the fix-->
</PropertyGroup>

<ItemGroup>
   <PackageReference Update="Microsoft.NETCore.App" Version="2.0.7" />
</ItemGroup>
15
votes

It seems Visual Studio is using different .NET Core versions for restore/build/publish.

To resolve this issue, you could add TargetLatestRuntimePatch attribute in the .csproj file:

<PropertyGroup>
   <TargetFramework>netcoreapp2.0</TargetFramework>
   <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>

For details, please see this page.

2
votes

In my case, in the .csproj file I changed

<ItemGroup>
    <PackageReference Update="Microsoft.NETCore.App" Version="2.0.5" />
</ItemGroup>

to:

<ItemGroup>
    <PackageReference Update="Microsoft.NETCore.App" Version="2.1.0" />
</ItemGroup>

And it worked.

1
votes

I’ve installed .NET SDK 2.2.0 and found out that this isn't the correct version and the correct one was renamed to 2.1.300 to be in sync with the .NET Core application whose the last version is 2.1.0. I installed 2.1.300 and everything runs correctly.

1
votes

Just because you have the latest SDK installed doesn't mean you have the latest runtime installed. I'll never quite understand that.

Run dotnet --info.

I got the following (only the latest installed versions are shown here).

 .NET Core SDKs installed:
   2.1.300 [C:\Program Files\dotnet\sdk]

 .NET Core runtimes installed:d\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  • So I installed 2.1.1 runtime, and now dotnet --info gives me 2.1.1 as well.

  • Oh and 2.1.3 actually is 2.1.1, but they had to increment it for some reason I don't fully understand about or care about.

  • I restarted Visual Studio, because it never seems to be able to keep versions in sync

  • I added the following to PropertyGroup in my .csproj file (unload project + edit)

    netcoreapp2.1 2.1.1

Now I thought we didn't need to specify this this any more, and this .csproj file was just created brand new today and it didn't have a runtime version at all. Whatever we're supposed to be doing, this worked for me. I also found this massive thread about versioning with 2.1.1 which I skimmed over, but it seems there are complications with point releases right now, so maybe this specific version is necessary.


I ended up here because of this error:

error : The project was restored using Microsoft.NETCore.App version 2.1.1, but with current settings, version 2.1.0 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.

Adding RuntimeFrameworkVersion was the specific fix for that that worked.

Unfortunately there isn't any linked article for this error message, which would be helpful.

0
votes

Use:

<Project Sdk="Microsoft.NET.Sdk.Web">

    <PropertyGroup>
        <TargetFramework>netcoreapp2.1</TargetFramework>
        <UserSecretsId>aspnet-...............245435</UserSecretsId>
        <RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
        <RuntimeIdentifier>win10-x64</RuntimeIdentifier>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore.App" />
        <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" PrivateAssets="All" />
    </ItemGroup>
    <ItemGroup>
        <PackageReference Update="Microsoft.NETCore.App" Version="2.1.1" />
    </ItemGroup>
</Project>
0
votes

In my case the issue was fixed by ensuring I had two projects, with one depending on the other.

One project had a RuntimeIdentifier specified in the .csproj file, but the other did not. Once I ensured both had matching RuntimeIdentifiers, the problem was fixed.

0
votes

The specific error I was getting was

error : NETSDK1061: The project was restored using Microsoft.NETCore.App version 2.0.5, but with current settings, version 2.1.1 would be used instead.

I had

<ItemGroup>
    <PackageReference Update="Microsoft.NETCore.App" Version="2.0.5" />
</ItemGroup>```

further down the file. Once I removed this and did a clean, the project built successfully.

0
votes

I have a somehow different solution, working for ASP.NET 2.1, as I had problems with both building and publishing processes:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>netcoreapp2.1</TargetFramework>
        <RuntimeFrameworkVersion>2.1.0</RuntimeFrameworkVersion> --> fix publishing issues
        <PlatformTarget>AnyCPU</PlatformTarget> --> fix publishing issues
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Update="Microsoft.NETCore.App" Version="2.1.0" /> --> fix building issues
        <ProjectReference Include="..\PublicSonar.Monitor.Persistent.Json\PublicSonar.Monitor.Persistent.Json.csproj" />
    </ItemGroup>
</Project>
0
votes

I experienced the same:

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

Removing the explicitly set --self-contained false from the dotnet publish command seemed to do the trick for us. It defaults to the same, so why it makes a difference, I have no idea.

This was with SDK version 2.1.400.