Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After upgrading to ASP.NET Core 2.1, get error that project will use 2.1.0-rc1. How to fix? #3221

Closed
Tgueth opened this issue Jun 13, 2018 · 30 comments
Assignees
Labels

Comments

@Tgueth
Copy link

Tgueth commented Jun 13, 2018

Here is the error I receive when I build the application after upgrading to 2.1,

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

The error refers to line 1 in csproj, but line 1 does not refer to rc1. How do I fix this?

@mkArtakMSFT
Copy link
Member

Thanks for contacting us, @Tgueth.
Can you please share a repro project for us to investigate?

@mkArtakMSFT
Copy link
Member

@dougbu, can you please look into this after @Tgueth will share a repro? Thanks!

@michael-freidgeim-webjet
Copy link

michael-freidgeim-webjet commented Jun 20, 2018

I have similar error:
csproj : 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.
csproj has
<TargetFramework>netcoreapp2.1</TargetFramework>
but

<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1" />
  <PackageReference Update="Microsoft.NETCore.App" Version="2.1.1" />  

Please see attached a new project, that I want to use with .Net 2.1.1
ViewBooking.zip

@seriouz
Copy link

seriouz commented Jun 20, 2018

I have a similar problem:

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

<TargetFramework>netcoreapp2.1</TargetFramework>

<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0" />

@ewmccarty
Copy link

ewmccarty commented Jun 20, 2018

I added the following lines to my .csproj files and this particular error went away

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

Now during testing I'm getting a series of errors similar to this

[6/19/2018 5:48:54 PM Informational] ------ Run test started ------
[6/19/2018 5:49:04 PM Informational] ========== Run test finished: 255 run (0:00:10.1299802) ==========
[6/19/2018 5:49:10 PM Informational] ------ Run test started ------
[6/19/2018 5:50:10 PM Error] Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Testhost process exited with error: It was not possible to find any compatible framework version
The specified framework 'Microsoft.AspNetCore.App', version '2.1.1' was not found.

at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyExecutionManager.StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsHandler eventHandler)

@seriouz
Copy link

seriouz commented Jun 20, 2018

I solved it via adding a global.json to my Project with:

{
    "sdk": { "version": "2.1.300" }
}

@ewmccarty
Copy link

Running "dotnet --info" in the Package Manager Console yielded:

PM> dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.1.300
 Commit:    adab45bf0c

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17134
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.300\

Host (useful for support):
  Version: 2.1.0
  Commit:  caa7b7e2ba

.NET Core SDKs installed:
  1.1.0 [C:\Program Files\dotnet\sdk]
  2.0.2 [C:\Program Files\dotnet\sdk]
  2.0.3 [C:\Program Files\dotnet\sdk]
  2.1.2 [C:\Program Files\dotnet\sdk]
  2.1.4 [C:\Program Files\dotnet\sdk]
  2.1.104 [C:\Program Files\dotnet\sdk]
  2.1.300 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
PM>

I installed dotnet-hosting-2.1.1-win(1).exe from actually version 2.1.1 Product build: cli build 20180605-09-1764970 and it seems to have resolved the problem with tests

https://github.com/dotnet/versions/tree/7a833dddfddc27f2074b755b94234a25b9757637/build-info/dotnet/product/cli/release

PM>  dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.1.300
 Commit:    adab45bf0c

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17134
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.300\

Host (useful for support):
  Version: 2.1.1
  Commit:  6985b9f684

.NET Core SDKs installed:
  1.1.0 [C:\Program Files\dotnet\sdk]
  2.0.2 [C:\Program Files\dotnet\sdk]
  2.0.3 [C:\Program Files\dotnet\sdk]
  2.1.2 [C:\Program Files\dotnet\sdk]
  2.1.4 [C:\Program Files\dotnet\sdk]
  2.1.104 [C:\Program Files\dotnet\sdk]
  2.1.300 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
PM> 

@bmarder
Copy link

bmarder commented Jun 22, 2018

Removing <MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish> from my .csproj solved the issue for me.

@granthoff1107
Copy link

I'm getting this same error on publish as well.

@granthoff1107
Copy link

It turns out this feature is explicitly outlines in the docs. In my case My publish was using a different runtime because I was publishing using Any CPU.

If none of the other options outline work for you the easiest way to avoid this issue is to build using the same configuration that you want to publish using and then run
dotnet publish --no-restore -r win10-x64 or whatever runtime you expect to publish to

@dougbu
Copy link
Member

dougbu commented Jun 26, 2018

All, thanks very much for your thoughts in this issue.

Given the docs @granthoff1107 mentioned, are there any open questions here?

@MNF
Copy link

MNF commented Jun 26, 2018

@dougbu,
As a VisualStudio user, I am working with automatically generated csproj, not with cli commands.
I am not aware, do I use the --no-restore argument with dotnet publish or not. I even not sure does my project use the framework-dependent or self-contained behavior.
I’ve installed the new version of SDK on my machine, and then existing ( not changed) solution start to failed with the above error.

It will be nice to have error message be more csproj specific, suggest RuntimeFrameworkVersion and global.json setting as possible fixes and include a link to the article explaining possible reasons/solutions for the error.

@granthoff1107
Copy link

@MNF I don’t use the Cli either that’s just a quote from the docs. I solved my issue by matching my configuration for publishing to the configuration for my build, and then everything started working.

My post was more help other find a work around, it seems like this is a known issue, and my guess is Microsoft will fix this in a few builds.

In my opinion this is still a bug, there’s no reason I should use these work arounds, considering visual studio stores your build and publish configurations, it should know how to resolve this.

@MNF
Copy link

MNF commented Jun 27, 2018

@granthoff1107, sorry, I meant to address my comment to @dougbu

@pikax
Copy link

pikax commented Jul 4, 2018

Sorted changing *Profile.pbxml
from:

 <TargetFramework>netcoreapp2.0</TargetFramework>

to:

 <TargetFramework>netcoreapp2.1</TargetFramework>

@rob-glas
Copy link

rob-glas commented Jul 8, 2018

I had this problem and adding

<PlatformTarget>AnyCPU</PlatformTarget>

to the .csproj as suggested by @ewmccarty worked. Note: didn't need the RuntimeIdentifier or RuntimeFrameworkVersion tag. Turns out it's the CPU target that causes the issue.

@leniel
Copy link

leniel commented Jul 10, 2018

Holy crap... removing <MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish> from my .csproj solved the issue for me too @bmarder. :)

I was getting this error:

It is not supported to build or publish a self-contained application without specifying a RuntimeIdentifier. Please either specify a RuntimeIdentifier or set SelfContained to false.

guess what: I had the RuntimeIdentifier specified already. I was going crazy with this error...

@emrecavunt
Copy link

emrecavunt commented Jul 18, 2018

Thanks to @AliDoganKim, he's answer worked for me.
Short Desc: You have to shoure exact SDK's and Runtimes installed only! not both " .net core sdk 201 & .net core sdk 202 & .net core sdk 301". It may have a conflict each other. Who knows..

StackOverflow/emre

(@MNF link edited ! tnx )

@MNF
Copy link

MNF commented Jul 18, 2018

@dougbu
Copy link
Member

dougbu commented Aug 3, 2018

@JunTaoLuo does the following error come from the Web SDK or anything else our group handles? (If not, seems we should redirect any remaining questions on this long thread to the CLI team.)

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

@fontanaricardo
Copy link

fontanaricardo commented Aug 9, 2018

Adding <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch> in my Project.csproj, works for me:

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

You can also set the nuget app version:

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

Reference: https://stackoverflow.com/a/51404441

@dougbu
Copy link
Member

dougbu commented Aug 15, 2018

@JunTaoLuo ping

@JunTaoLuo
Copy link
Contributor

JunTaoLuo commented Aug 15, 2018

There seems to be multiple issues here so there's also no specific fix. However, we do have documentation at https://docs.microsoft.com/en-us/aspnet/core/fundamentals/metapackage-app?view=aspnetcore-2.1 to explain how the metapackages should be used.

In general, we recommend not explicitly specifying the Microsoft.NETCore.App dependency in your project as that will be implicitly added by the dotnet SDK. Under the current design, we also do not recommend explicitly adding the version number for the Microsoft.AspNetCore.App dependency if you are using the Microsoft.NET.Sdk.Web SDK which implicitly adds the version. In effect, the .csproj file should look like:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

</Project>

This is what our templates currently produce and we recommend following this pattern if you are upgrading from previous releases (1.x and 2.0 templates will look different for example).

In cases where explicit references are added and explicit versions are specified, (either directly on the dependency or via properties such as RuntimeFrameworkVersion), it will be the responsibility of the user to ensure:

  1. The metapackage version exists on nuget.org so the project can be successfully restored
  2. The metapackage is compatible with the TargetFramework specified (for example Microsoft.NETCore.App 2.1.x and Microsoft.AspNetCore.App 2.1.x will be compatible with netcoreapp2.1 but not netcoreapp2.0)
  3. The entire publish procedure is re-executed from a clean state if any of the metapackage versions are updated (i.e. restore, build and publish)
  4. The shared framework corresponding to the version of the specified metapackage is installed on the deployment target machine (or the local dev machine if you are running locally) so the published application can execute on the specified metapackage.
  5. The version of Microsoft.NETCore.App is specified via the RuntimeFrameworkVersion property, i.e. <RuntimeFrameworkVersion>2.1.1</RuntimeFrameworkVersion>

Due to these extra precautions required, we recommend using implicit versions as much as possible to avoid errors and conflicts as mentioned above. I'm not familiar enough with the VS tooling, templates, and publish/deployment scripts to say how the errors reported in this issue came about.

To address specific concerns, the project file I saw in ViewBooking.zip looks mostly correct if the 2.1.1 shared framework is installed. However, it did not follow rule 5. If the line <PackageReference Update="Microsoft.NETCore.App" Version="2.1.1" /> is removed and replaced with the property <RuntimeFrameworkVersion>2.1.1</RuntimeFrameworkVersion>, the project will build (but I'm seeing other errors such as missing types).

The self-contained deployment route will have a separate set of considerations and it is outlined in https://docs.microsoft.com/en-us/dotnet/core/deploying/runtime-patch-selection.

Note that the implicit metapackage versions have also caused a separate set of confusion and difficulties for users and we considered alternatives in #3292. Although we did not choose to revert back to explicit versions in 2.1.x, further discussions regarding this area are ongoing and may change in the future.

Since the problems outlined in this issue may have different causes, please feel free to file a new issue and link your project file and environment (i.e. dotnet --info) so we can give more specific solutions.

@j0nscalet
Copy link

@JunTaoLuo Thank you for the detailed answer. I found it helped me actually understand the cause of the problem, which I very much prefer, to a simple fix. (Duct taping things always bites me.)

@max-favilli
Copy link

For anyone who got here having this problem.
It affected me today, just after updating Visual Studio to 15.8.2, when publishing.
I re-installed the Net Framework and the issue was solved.
In case you face it, I would give it a try to just re-install the framework.

@pkrey
Copy link

pkrey commented Aug 31, 2018

@JunTaoLuo
Copy link
Contributor

I'm going to close this issue now since I think most of the issues have been addressed. Please feel free to open new issues in case anyone has more specific questions!

@silkfire
Copy link

silkfire commented Oct 29, 2018

Adding <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch> in my Project.csproj, works for me.

This worked for me as well! Make sure you add this line to all included .csproj files in your solution.

@pagex
Copy link

pagex commented Dec 7, 2018

switched in project properties from Target from AnyCPU to x64, clean, rebuild, no error this time.

@koo9
Copy link

koo9 commented Dec 22, 2018

adding this true works for me

doug144 added a commit to pub-comp/caching that referenced this issue Jan 28, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests