Visual Studio 2017 project referencing old version of Microsoft.AspNetCore.App - visual-studio

I was using .Net Core 2.1.1, and recently updated the SDK to 2.1.401 (.Net Core Runtime 2.1.3). When i create a new project the version of Microsoft.AspNetCore.App under Dependencies > SDK is still 2.1.1. Looking at the properties of Dependencies > NuGet, the package is being referenced from "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.app\2.1.1"
I tried installing Package 2.1.3 using NuGet package manager, and it downloaded all dependencies from NuGet despite that i have 2.1.3 already installed on my machine.
How do i force existing / new project to use the latest version of packages from the SDK install ?

You shouldn't need to update the version of Microsoft.AspNetCore.App manually in your project. 2.1.1 is perfectly fine. Your application will run on the latest 2.1.* framework installed on the machine.
If you publish a self-contained application, the tooling will automatically switch to the latest known version of 2.1.* at build time for the self-contained build only. (-r win-x64 argument)
This may or may not change for the 2.2 or 3.0 releases, read/follow this GitHub issue and thread for more information.

This is a bug as it has already been reported but for now this can be the solution.
In ProjectName.csproj file:
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.1.3</RuntimeFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.3" />
</ItemGroup>

Related

All nuget packages requiring net6.0 are "not compatible with net6.0" even after complete Windows reset

After booting up my PC I tried to continue using a previous project I had been working on:
ASP.NET MVC Core 6.0.
All of a sudden Microsoft.EntityFrameworkCore was not installed in the solution.
After trying to reinstall the Microsoft.EntityFrameworkCore nuget package I received the following errors:
Package restore failed. Rolling back package changes for 'BulkyBook' (my project)
NU1202: Package Microsoft.Extensions.Logging 6.0.0 is not compatible with net6.0 (.NETCoreApp,Version=v6.0). Package Microsoft.Extensions.Logging 6.0.0 does not support any target frameworks.
NU1202: Package Microsoft.Extensions.Options 6.0.0 is not compatible with net6.0 (.NETCoreApp,Version=v6.0). Package Microsoft.Extensions.Options 6.0.0 does not support any target frameworks.
... for all dependencies AND
NU1202: Package Microsoft.EntityFrameworkCore 6.0.5 is not compatible with net6.0 (.NETCoreApp,Version=v6.0). Package Microsoft.EntityFrameworkCore 6.0.0 does not support any target frameworks.
When trying to install ANY nuget packages requiring net6.0 I get the same issue.
I have done a reset of Windows (keeping files but losing all programs) and fully reinstalled Visual Studio 2022.I still have the same issue.
This is killing me, I'm willing to try anything.
Image for proof:

How to upgrade a project to .NET Core 3.1.18

I'm not sure if it's possible or not, the target framework in project properties is .NET Core 3.1
I also installed version 3.1.18 and upgraded all related Nuget packages to 3.1.18
is there a way to indicate that the project is using .NET Core 3.1.18? (or is it using the latest by default)
You need only to indicate the major release as described here:
https://learn.microsoft.com/en-us/dotnet/standard/frameworks#latest-versions
Then it depends on your target output, like:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-ios14.0</TargetFramework>
<SupportedOSPlatformVersion>13.0</SupportedOSPlatformVersion> (minimum os platform version)
</PropertyGroup>
...
</Project>
or:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<Description>Sample project that targets multiple TFMs</Description>
</PropertyGroup>
</Project>
If you read the documentation you see:
netcoreapp3.1
Then the project will be upgraded at the latest version available on target system.
If you have installed version 3.1.18 on your target system that version will be used.
The nuget packages are, instead, related of your configured nuget sources.
If you have configured your system with the standard sources, the build system or VS will download the version declaration json file from the sources. This file contains the latest stable (or preview, in case you selected it) version number, so the build system will use this file to verify the version number of the package you indicated.
If the package number is compatible with your target framework that package will be downloaded from the related source.
When using .NET Core 3.1 in VS 2019, there is no option to tell the project to use a specific framework version (for example - 3.1.16 or 3.1.18), it will simply use the latest installed version.

The specified framework 'Microsoft.NETCore.App', version '2.2.0' was not found

I am using Visual Studio 2019 Version 16.3.7. I assume it is the latest update.
When I try to compile a basic .NET Core 2.2 console application:
...I get the following error:
It was not possible to find any compatible framework version
The specified framework 'Microsoft.NETCore.App', version '2.2.0' was not found.
- The following frameworks were found:
1.0.1 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.0.9 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.1.11 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.1.12 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.1.13 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
3.0.0 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
You can resolve the problem by installing the specified framework and/or SDK.
The .NET Core frameworks can be found at:
- https://aka.ms/dotnet-download .
My understanding is that .NET Core 3.0 is backward compatible. Why Visual Studio installer installed all versions of .NET Core except 2.2?
How do I solve this problem?
For whatever reason, .NET Core 2.2 is not installed by the ".NET Core cross-platform development" workload.
Open up the Visual Studio installer then go to the "Individual components" tab and you can install it from there:
In my case was missing x86 .NET Core 2.2.x Platform SDK (Visual Studio .NET 16.4 + .NET Core 3.1 SDK ; xUnit Test Project).
You can try this:
Exist directory 2.2.x in: C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App ?
When no, try Download latest 2.2.x SDK for x86 platform from this URL: https://dotnet.microsoft.com/download/dotnet-core/2.2
Install and try ...
For more info about installed SDK and Runtime you can use command: dotnet --info
For those trying to deploy a file to a non-developer machine and you see this error, use the Project -> Publish option with a Folder Profile and update the settings to be "Deployment mode: Self-contained". Then "Publish" it.
This will embed the runtime into the .exe, making it much larger, but also simple to "just work" on a client machine.
You can install x86 .NET Core 2.2.x Platform SDK as #Martin said.
If you do not need x86 version like me, you can also set
<PlatformTarget>AnyCPU</PlatformTarget>
to
<PlatformTarget>x64</PlatformTarget>
in both main project and test project 's .csproj file
to avoid this problem.
Two options are to run the Visual Studio Update application to see if any missing requirements will be installed for you or to install the net core 2.2 SDK manually from https://dotnet.microsoft.com/download/dotnet-core/2.2 (or https://aka.ms/dotnet-download as mentioned in the error message).
.NET Core 2.2.0 is not supported anymore.
Waiting for the .NET 5

Visual Studio Mac incompatible with dotnet core 2

I've been using Visual Studio Mac for a little while and have just updated it to the released version. I've also downloaded and installed .NET Core 2.0 Preview 1. From a shell prompt I can generate a new Web API project:
dotnet2 davec$ dotnet --version
2.0.0-preview1-005977
dotnet2 davec$ dotnet new webapi
The template "ASP.NET Core Web API" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/template-3pn for details.
Processing post-creation actions...
Running 'dotnet restore' on dotnet2/dotnet2.csproj...
Restore succeeded.
I can build and run that project from the shell. But when I open it in Visual Studio for Mac, the IDE tries and fails to restore:
Errors in dotnet2/dotnet2.csproj
Unable to resolve 'Microsoft.NETCore.App (>= 2.0.0)' for '.NETCoreApp,Version=v2.0'.
Unable to resolve 'Microsoft.NETCore.App (>= 2.0.0)' for '.NETCoreApp,Version=v2.0 (win)'.
Unable to resolve 'Microsoft.NETCore.App (>= 2.0.0)' for '.NETCoreApp,Version=v2.0 (win-x64)'.
Unable to resolve 'Microsoft.NETCore.App (>= 2.0.0)' for '.NETCoreApp,Version=v2.0 (win-x86)'.
NuGet Config files used:
~/.config/NuGet/NuGet.Config
Feeds used:
https://api.nuget.org/v3/index.json
Restore failed for 'Microsoft.NETCore.App (>= 2.0.0)'.
Restore failed.
For the sake of completeness, documenting the answer here following #jmoerdyk's comment:
My Environment:
MacOSX 10.12.4
dotnet version: 2.0.0-preview1-005977
Open the csproj file in a text editor (vi, TextEdit, VS Code)
Modify the Target framework and RuntimeFrameworkVersion to be this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeFrameworkVersion>2.0.0-preview1-002111-00</RuntimeFrameworkVersion>
</PropertyGroup>
</Project>
Run nuget restore, build the project and you should be good to go
Visual Studio for Mac 7.1 is compatible with .NET Core 2.0 Preview 2, but it is currently in beta. Select "Check for Updates" from the main menu and switch to "Beta" channel. See Xamarin docs and preview release notes.
Now you can get .NET Core 2.0 from here, and then install pkg. Next step is changing target framework in solution in vs. Have fun!

Npgsql nuget installation failed

I have .NET 4.6.1 and 4.5.1 and VS 2013
I am installing Npgsql 3.2.0 (PostgreSQL .NET provider).
It fails:
Attempting to resolve dependency 'NETStandard.Library (≥ 1.6.1)'.
'NETStandard.Library' already has a dependency defined for 'Microsoft.NETCore.Platforms'.
Any ideas?
Thanks!
The culprit is likely VS2013, or rather your version of nuget. Can you make sure you have the latest version of the nuget extension and retry?
This was resolved by installing the latest NuGet Package Manager, the latest version is 2.12.0.817
https://visualstudiogallery.msdn.microsoft.com/4ec1526c-4a8c-4a84-b702-b21a8f5293ca
Note that: Don't forget to restart VisualStudio.

Resources