The current .NET SDK does not support targeting .NET Core 2.1.3 - sdk

I want to make sure that my application is built against .NET Core 2.1.3, so I installed version 2.1.401 of the SDK and set the TargetFrameworkVersion of the project to 2.1.3.
This gives me the following error message (emphasis mine):
C:\Program Files\dotnet\sdk\2.1.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 2.1.3. Either target .NET Core 2.1 or lower, or use a version of the .NET SDK that supports .NET Core 2.1.3.
So the interesting thing is that the build seems to use the freshly installed SDK (2.1.401) - which is supposed to support .NET Core 2.1.3 - but it is still complaining that .NET Core 2.1.3 is not supported. This doesn't make sense to me...
What could be wrong here?

(For my answer I will assume that you're building a framework-dependent application and not a self-contained application.)
You cannot set 2.1.3 directly as the <TargetFramework> in the .csproj because it's just the patch version that's different.
Only the following entries are allowed: https://learn.microsoft.com/en-us/dotnet/standard/frameworks
So in your case the .csproj needs to have <TargetFramework>netcoreapp2.1</TargetFramework>.
But as Damir pointed out in the comment, you can force the version if you also add <RuntimeFrameworkVersion>2.1.3</RuntimeFrameworkVersion> to the <PropertyGroup>.
You can check the effect of this change if you open the "Manage NuGet Packages" dialog and look at the version of the metapackage Microsoft.NETCore.App that is implicitly being used.
Without the <RuntimeFrameworkVersion> it's 2.1.0, otherwise it should be 2.1.3.
But aside from that there are sometimes other factors as well that will implicitly determine the version that's being used.
For example, if you want to build a self-contained application you have to specify the <RuntimeIdentifier> which will also force the framework version to 2.1.3 because it will publish the highest patch runtime on your machine automatically.
That said, I wouldn't recommend to set any <RuntimeFrameworkVersion> manually for the most part.
Starting with .NET Core 2.1 all framework-dependent applications (that are built using .NET Core 2.0 or later) will automatically roll forward to the latest minor version that is installed if the original version of the runtime isn't present on the system.
So if you only have .NET Core 2.1.3 installed on the target system, your framework-dependent .NET Core 2.1.0 application will automatically use that runtime and framework.
You can read a bit more about the .NET Core version selection mechanism here.

I had the same issue and and was at the time using visual studio 2017 and had latest .net sdk installed(which at time of the post 2.2.401). Installing sdk 2.2.107 and adding it to the global.json file (I have it my project root) solved
the problem for me.
{
"sdk": {
"version": "2.2.107"
}
}
Also see this related post on the visual studio developer community forum.

Related

I cannot change the Target Framework from .NET 5.0 to .NET 4.8 for a C# .NET Framework Class Library in Visual Studio 2019

I am trying to build a .NET 4.8 Class Library that I can make COM-Visible as a support library from an Access application.
There are no prompts for the version of .NET Framework when I create the solution.
When I look at the Project Properties, the .NET Framework is set to 5.0.
Although I have the .NET Framework 4.8 installed, it does not appear in the combo-box for the Target framework. The only options are shown below.
I have also noticed that the Startup object combobox does not reflect the selected startup assembly.
Do I need to drop back to Visual Studio 2017 to create a .NET Framework 4.8 library?
Which SDK is installed?
If you only have the .net 5 SDK installed, it might suffice for making a .net core 3 app but it will not cover .net Framework.
Install the .net Framework SDK for the version you want to target.
And/or install a targeting pack if you want to target .net 4.8 and 4.7.2 for example.
(Maybe helpful: What's the difference between the .NET Framework SDK and the Targeting pack)
This happened to me because I had choosen the wrong kind of project.
I had choosen a project library for C#, Windows Linux, macOS.
By this the same thing, that one could only had .NET 5.0 and higher as Framework.
I had to create a new library project with only C# and Windows.
Than I could choose all installed .NET frameworks

.NET Core 3.1 Not available in as Target Framework in VS2019 v16.6

I have downloaded and installed VS2019 Community v16.6.0
I have downloaded and installed .NET Core 3.1 (v3.1.4) with SDK version v3.1.300
.NET Core 3.1 is not available as an option for a target framework in Visual Studio. Am I missing something here?
I've followed several suggestions in other similar questions of enabling preview SDKs (which shouldn't apply, because 3.1 is not in preview) with no success.
Images Attached
v16.6.1 of VS2019 just dropped today. Fixed the issue.

using .NET Standard 2.1 with UWP

I made the big mistake of taking some NuGet library updates today. It forced me to either roll back a week's worth of work or upgrade to ASP .NET Core 3.0. I hate to use stuff that's not production, but I didn't want to untangle the libraries either, so I upgraded. Then it forces me to retarget .NET Standard 2.1 libraries. Which I did.
My problem now is with the client UWP code. When I try to compile, I get:
error : Project '..\ClassLibrary1\ClassLibrary1.csproj' targets 'netstandard2.1'. It cannot be referenced by a project that targets 'UAP, Version=v10.0.10586'.
This happens even with a virgin UWP and .NET Standard 2.1 library. Any clues on how to make Visual Studio 2019 client code work with the latest upgrade?
All Windows 10 SDKs currently don't support .NET Standard 2.1.
Windows 10 19H2 is using the same SDK number as 19H1, so it is unlikely that it will support .NET Standard 2.1. (But I certainly hope it does.)
Microsoft hasn't made an official announcement, but Windows 10 20H1 is getting a meaningful SDK update, so it is likely that it will support it. And once that's the case, UWP apps will require 20H1 to run (so that will become the minimum supported version).
One of the big issue with this situation is that Entity Framework Core 3.0 requires .NET Standard 2.1, so it can't be used in UWP apps for now (Update: This issue is resolved with Entity Framework Core 3.1 supporting .NET Standard 2.0).
By the way, as an experiment, I was able to fork Entity Framework Core 3.0 (for SQLite) and make it compile on .NET Standard 2.0. I basically had to manually copy a few new APIs from .NET Core 3.0 (like IAsyncXXX). And it worked, so it is an option for people who really need it. Note that, I did not try it with the SQL Server provider.
Update: The UWP team is planning to enable UWP apps to use .NET 5 and that's when UWP will support .NET Standard 2.1 (and more). This could happen in 20H2 or 21H1.
UWP does not support .Net standard 2.1 yet. It only support till .Net standard 2.0 and that too from windows 1709 onwards.
If you look at the link for 2.1 it states
Platform Support
An upcoming version Universal Windows Platform
so it may be 19H2
UPDATE
Microsoft is going to release a new framework called WinUI 3, this is going to support UWP as well as Win32 based application model. WinUI 3 would support .Net 5 for both the platforms. WinUI 3 preview is going to be available in mid May 2020, with final release in late 2020. WinUI 3 would be supported on windows 10 1803+.

.Net Core Vs .Net framework to create a new mvc web application

I have visual studio 2015 professional editton, and i want to create my first MVC web application which should be a .net core. now i am watching an online learning demo, which mentioned to create this project:-
while inside my visual studio i have these options:-
so which option i need to chose?
second question, how i can be sure that i am using the latest version of MVC?
Thanks
First, there is no such thing as MVC 6. It's ASP.NET Core. Second, the decision of whether to use .NET Core or .NET Framework comes down to what you need to do. .NET Core is cross-platform (Windows, Mac and Linux), whereas .NET Framework is Windows-only. .NET Core is also lighter weight, faster, and has a number of new CLR features, compared to .NET Framework. Virtually the only reason to use .NET Framework is if you have a dependency on something that utilizes Windows-specific APIs, meaning it can't be run cross-platform. Otherwise, you should always use .NET Core, if you can get away with it.
ASP.NET Core is really just a collection of NuGet packages, and like other NuGet packages, they can be updated easily. However, the difference is that these NuGet packages are generally tied to a particular version of .NET Core, and thus, the appropriate version of the packages are installed based on which version of .NET Core you're targeting. For example, if you're targeting netcoreapp2.2 then you'll see that that packages like Microsoft.AspNetCore.App will be brought in with versions like 2.2.x.
So, to answer your question about staying up to date, it essentially entails installing the latest version of the .NET Core SDK, and then changing your project to target that new version. Then, all the ASP.NET Core NuGet packages will naturally update accordingly.

Correct version of Fsharp.Core

I am building an F# console application with Visual Studio 2013 Ultimate. The target framework is .Net 4.5
The version of FSharp.Core installed on my computer (presumably by installing VS 2013) is 4.3.1.0.
On NuGet there are two versions of FSharp.Core, 4.0.0 published April 12, 2012 and one with an ID of Fsharp.Core.3 verison 0.0.2 published March 5, 2013.
I am looking for guidance as to when one should use each of these versions, the version numbering is confusing me and I would have expected to find the latest production release on NuGet.
Am I missing something?
You should not be obtaining FSharp.Core from nuget. Microsoft does not publish any official F# bits to nuget today (though this could potentially change in the future). It's common for 3rd-party packages to bundle FSharp.Core (since presumably that's the version used for testing/validation of that 3rd-party component), but nuget should not currently be used as a mechanism for getting FSharp.Core updates or new versions.
The versioning story for FSharp.Core is sadly rather complex, and definitely not as simple as "higher version means newer." A key thing to realize is that there are 2 axes - what F# version does the runtime support, and what .NET framework version/profile does it target.
Below are the official FSharp.Core versions that ship with VS 2013 (find these dropped under %ProgramFiles(x86)%\Reference Assemblies\Microsoft\FSharp).
4.3.1.0 (F# 3.1/.NET 4) This is the most recent official version. Unless you have a requirement to target .NET 2, or you are using some legacy F# component that won't work with 3.1, this is the version you should use for any new desktop app.
4.3.0.0 (F# 3.0/.NET 4) These are the same bits that shipped with VS 2012. It is included so that you can continue working on F# 3.0 projects in VS 2013 without retargeting them to 3.1. You should use this if you have a legacy F# 3.0 desktop project that you are not ready to move to 3.1 yet.
2.3.0.0 (F# 3.0/.NET 2) These are the same bits that shipped with VS 2012. The only reason to use this is if you are targeting .NET 2. The .NET 2 side of things is not being developed further, btw - new features, versions, etc will be done for FSharp.Core targeting .NET 4+; the .NET 2 FSharp.Core is still fully supported, but it is frozen.
3.3.1.0 (F# 3.1/"Portable") This version targets .NET portable profile 7 (.NET 4.5/Windows Store). Use this if you are creating a component for a Windows store app and you don't care about Silverlight. This profile is newly supported in VS 2013.
2.3.5.1 (F# 3.1/"Portable (Legacy)") This version targets .NET portable profile 47 (.NET 4/Silverlight 5/Windows Store). Use this if you are creating a Silverlight component. This profile was also supported in VS 2012, and referred to at that time as simply "Portable."
2.3.5.0 (F# 3.0/"Portable (Legacy)") This version targets .NET portable profile 47 (.NET 4/Silverlight 5/Windows Store). These are the same bits that were included in VS 2012. Included in VS 2013 to enable you to continue working on F# 3.0 portable/silverlight projects.
.NET portable profiles are a big PITA and cause a ton of complexity. This site has a good summary to help understand: http://blog.stephencleary.com/2012/05/framework-profiles-in-net.html
So for your specific scenario (new console app) use 4.3.1.0.
Edit 7/2015:
Here's a table that probably explains the story better than the wall of text above. I've tried to use colors to indicate the motivation for the version numbers. You'll see the versioning of the portable libraries was a bit ad hoc and inconsistent in VS 2012 and 2013, but is finally consistent and predictable starting with VS 2015. This is up to date with F# 4.0, which just released.
Today I would probably rather follow these guidelines
In short, you can/should reference FSharp.Core from NuGet

Resources