How to update from Microsoft.NetCore.App 2.0 to 2.1.4 - asp.net-core

I created an ASP.NET Core Web API project in Visual Studio 2017 version 15.7.2.
When I created it, it was Microsoft.NetCore.App 2.0.
Now I want to update to Microsoft.NetCore.App 2.1.4 but I can't because Visual Studio tells me:
Implicitly referenced by an SDK. To update the package, update the
SDK to which it belongs
I download the latest version of .NET Core and I installed it, but I got the same issue.
Any ideas?

Don't confuse SDK (=> Build tools) versions with .NET Core versions.
The 2.1.* SDK versioning was unfortunate, the versioning scheme has since been changed and the scheme transition will be (mostly) complete with the release of .NET Core 2.1.
You don't need to update the Microsoft.NETCore.App NuGet package as it only contains build references needed to build your application.
For self-contained applications, you can also set the <RuntimeFrameworkVersion> property inside the csproj file, but starting with the .NET Core SDK 2.1.300, you no longer need to as it will know about the latest versions.

As Martin points out above, the SDK and .Net Core Runtime are separate entities.
I went to https://www.microsoft.com/net/download/windows and downloaded the latest SDK (2.1) and installed it on my local machine. You'll need to close any open VS instances to complete the SDK installation.
Open your project's csproj file and update netcoreapp2.0 to netcoreapp2.1 and while you're at it you can update the "Microsoft.AspNetCore.All" to version 2.1. This will save you from having to update the nuGet package.
Worked for me. Best of luck.

Related

.NET confused, too many files

I have a server running tons of apps like IIS, VS, VS Code etc. Can someone tell me what these folders are:
%programfiles%\dotnet\shared\Microsoft.NETCore.App\
Microsoft.AspNetCore.App
Microsoft.WindowsDesktop.App
I have an old version of .NET Core but .NET Core uninstall tool cannot find it, it doesn't even show up in add or remove program.
Can I download the latest binaries of the SDK and just swap the directories?
shared/Microsoft.NETCore.App/<runtime version> This framework contains the .NET runtime and supporting managed libraries.
shared/Microsoft.AspNetCore.{App,All}/<aspnetcore version> contains the ASP.NET Core libraries. The libraries under Microsoft.AspNetCore.App are developed and supported as part of the .NET project. The libraries under Microsoft.AspNetCore.All are a superset that also contains third-party libraries.
Microsoft.WindowsDesktop.App.Ref describes the API of x.y version of Windows Desktop applications. These files are used when compiling for that target. This isn't provided on non-Windows platforms.
For more packaging details ,you can refer to this document.
If you can't uninstall the old version of .net core, you can download the version you want and specify to use this version in your project. You can take a look at this case.

ASP.NET Core - 2.1 to 2.2 Issue

Visual Studio 2017 15.9.18 on Windows 10
I have an ASP.NET Core Project that I need to update the Target Framework from 2.1 to 2.2
After changing the Target Framework, I cleaned an re-built the project.
I now get a compile error saying that says one of the assemblies in my project uses 'Microsoft.AspNetCore.Http.Abstractions, Version=2.1.1.0 which has a higher version than referenced assembly 'Microsoft.AspNetCore.Http.Abstractions' with identity 'Microsoft.AspNetCore.Http.Abstractions, Version=2.0.1.0
In my project dependencies I have Microsoft.NETCore.App 2.2.0 installed. I was going to update this but in package manager the Update button is disabled, saying "Implicitly referenced by an SDK. To update the package, update the SDK to which it belongs." The versions available show they go up to 2.2.8
Using Nuget Package Manager I installed Microsoft.AspNetCore.Http.Abstractions 2.1.1.0 and that seemed to work in debug, but after publishing, my site fails to load.
Should I be manually updating the version of Microsoft.NETCore.App, or is it fine to just update the Microsoft.AspNetCore.Http.Abstractions?
I added the following to my project file:
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RuntimeFrameworkVersion>2.2.0</RuntimeFrameworkVersion>
</PropertyGroup>
I also noticed some invalid sections in my publish profile:
I also read somewhere that I should add:
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
but SetCompatibilityVersion does not appear as a method.
I would discourage upgrading from .NET Core 2.1 to .NET Core 2.2 at this time.
Today's date is 1/4/2020 and as of December 23, 2019 .NET Core 2.2 is at the End of Lifecycle (EOL)
If you're going to spend the time migrating your code at this time, you should move to a version of .NET Core that is going to receive patches if there is anything broken or there are any vulnerabilities.
You can see the EOL dates here https://dotnet.microsoft.com/platform/support/policy/dotnet-core

Nuget for Microsoft.NETCore.App 3.0.0 not available?

We are facing memory leak with ConfigurationRoot. Looking at this thread, it's now been fixed:
https://github.com/aspnet/Extensions/issues/861
This requires us to upgrade to Microsoft.NETCore.App 3.0.0
https://www.nuget.org/packages/Microsoft.Extensions.Configuration.Abstractions/
But, I am not able to locate Microsoft.NETCore.App 3.0.0 nuget anywhere. Any idea where I can find this?
Microsoft.NETCore.App is a metapackage, which references all commonly used library for an .NET Core application. Install a new .NET SDK Runtime on the target system.
The version will still be 3.0.0, but when you run the application it will roll-forward to the newest patch version.
If its an self-contained application (vs. portable application which requires a .NET Core runtime installed on target system), then update the SDK on the build system and recompile your application to cause build system putting the latest .NET Core artefacts in the publish directory.

What am I missing to upgrade asp.net mvc .net core 2.2.0 apps to .net core 2.2.1

I have the latest version of visual studio, the sdk and runtimes for x64 and x86 version 2.2.1, but my asp.net mvc .net core applications will only recognize being 2.2.0. I can install 2.2.1 into .net core libraries.
What do I need to change to allow my web projects to be 2.2.1 instead of 2.2.0?
(It can't be done through nuget, it provides the statement: Implicitly refrenced by an SDK. To update the package, update the SDK to which it belongs
Since the project is referencing a library with 2.2.1, I see the error: Error NU1605 Detected package downgrade: Microsoft.AspNetCore.App from 2.2.1 to 2.2.0. Reference the package directly from the project to select a different version.)
According to Microsoft documentation packages Microsoft.AspNetCore.App and Microsoft.NETCore.App have special versioning semantics which is handled outside of NuGet.
Also note that specifying a version number on Microsoft.AspNetCore.App package does not guarantee that desired version will be chosen. In general, you should not explicitly specify Microsoft.AspNetCore.App version unless you have a good reason to do so (applies to .NET Core 2.1 and later).
You can read more about that here: Microsoft.AspNetCore.App metapackage
If you want to target specific SDK used in your project or solution, add global.json file to project folder (if you want to target only that specific project) or solution folder if you want to target all projects in the solution.
global.json example:
{
"sdk": {
"version": "2.2.103"
}
}

Visual Studio 15.3.1 can't find core DLLs after update

I'm getting the runtime error:
InvalidOperationException: Can not find assembly file mscorlib.dll at '...\bin\Debug\net462\refs,...\bin\Debug\net462\'
This had not been a problem until I updated to version 15.3.1 this morning, and installed the .Net Core 2.0 SDK.
The DLL's are present in my ~\.nuget\packages folder. I'd had the same issue with the "Microsoft.Csharp.dll" assembly until I copied and pasted it into the stated folder.
I tried specifying to use .Net Core 1.1.0 via a global.json file, but then I get the build error:
The version of Microsoft.NET.Sdk used by this project is insufficient to support references to libraries targeting .NET Standard 1.5 or higher. Please install version 2.0 or higher of the .NET Core SDK.
This error goes away if I clean the solution then restore Nuget packages via Command Line- not via the GUI. However it comes back if I change the version of a nuget package.
OK, this seem slightly different to my issue here: Visual Studio update 2017 15.3.1 forces ASP.NET Core SDK 2.0, which then doesn't find "reference assemblies"
If you install the SDK 2.0 from https://www.microsoft.com/net/download/core
You will then "probably" be able to build and run the project again but you'll be back to having the missing Microsoft.CSharp.dll / mscorelib.dll error.
If you then make sure the dependency is correct for the netstandard version:
<DependsOnNETStandard>netstandard1.5</DependsOnNETStandard>
See here: https://learn.microsoft.com/en-us/dotnet/standard/net-standard for the right version for you. My project is using core 1.1 targeting the full framework 4.6.1 and targeting netstandard1.6 has worked for me.
The final piece of the puzzel, was found on the GitHub issues here: https://github.com/dotnet/sdk/issues/1488
Add the following to your references in the .csproj file:
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="2.0.0" />
This will then build the project as a 1.1 project, but using the 2.0 SDK (which from what I can tell, it's supposed to do!). I can now run the project, update packages and generally got on with my work!