Unable to update project to .NET 5 - c#

I've installed .NET 5 SDK both x64 and x86 and updated visual studio to the latest version. Restarted the computer and visual studio many times, the only options it allows me are .NET Framework up to version 4.8.
.NET 5 does not appear in the new project window of visual studio either.
How can I make .NET 5 appear so I can update my project to it?

.NET 5 is not an upgrade to .NET Framework 4.8 in the sense that .NET Framework projects can be seamlessly upgraded to later version. .NET 5 is .NET Core, so .NET Core 2.x and .NET Core 3.x can be upgraded to that path. You'll have to port your project instead, and that's far more involved than simply changing a dropdown.

As the .Net 5 is not released you will not find it in the list.
open the .csprj file by double-clicking on the project and change the framework manually.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>
Then in your project enable preview NuGet packages and update to the new pre-release framework.
have a look at https://learn.microsoft.com/en-us/aspnet/core/migration/31-to-50?view=aspnetcore-5.0&tabs=visual-studio, you will find some more tips there
UPDATE
I just now did the update of visual studio and installed 5.0 using the framework download at https://dotnet.microsoft.com/download/dotnet/thank-you/sdk-5.0.100-windows-x64-installer and I now have 5.0 in the drop-down at the top of my list of frameworks. looks like the order is not latest at the bottom.

Related

Migrate from .net standard to .net 6 using the upgrade tool

I tried upgrading a .NET standard project to a .NET 6 project using this upgrade assistant tool:
https://dotnet.microsoft.com/en-us/platform/upgrade-assistant/tutorial/install-upgrade-assistant
I ran the tool as the steps describe (installing it, using upgrade-assistant analyze with the project csproj path and then upgrade-assistant upgrade with the path), but after it was done, the project still remains with a target framework of .net standard 2.0.
Is there something else needs to be done in order to upgrade the framework?
I eventually simply edited the project file directly. To convert it to .net 6 all you need to do is change the <TargetFramework> to be like this:
<TargetFramework>net6.0</TargetFramework>
It's a 3 seconds work so no need for any tools
.NET standard works parallelly. That means you would have to update to .NET standard 2.1 if you need it for other old framework projects. Otherwise create new libraries in .NET 6 and migrate your code.
According to microsoft:
https://dotnet.microsoft.com/en-us/platform/dotnet-standard,
.NET 6 supports .NET Standard 2.1.
Future versions of .NET will also support .NET Standard 2.1 and earlier versions.
The interface Project > Property tools isn't the way to update version from .Net standard to other versions other than standard versions. The right/easiest way is updating the TargetFramework in .csproj file of the project directly.

How do I configure VS 2022 with .NET Framework 6.0?

I've searched the interwebs for a solution to this to no avail. I cannot for the life of me discover how to make a .NET 6.0 project in VS 2022. The weird part is when I go to the installer, the runtime for 6.0 is selected as installed. I cannot find an SDK option in the installer's list of packages however. I have installed the SDK for 6.0 and it shows as present when I check "dotnet --info." However, whenever I go to VS to create a project the latest version of .NET listed is 4.8.
Thanks!!
the project you build is targeting . Net Framework, which latest version is 4.8. For the .Net 6 you mentioned is more likely .Net Core6.0. Please refer to the related link:.Net Framework

Why creating an NUnit project into my solution it use an old version of .NET framework (2.1)?

I am pretty new in C# and .NET and I have the following problem.
I created a NUnit (version 3.10.1) project in my solution. The thing that I can't understand is: why the framework version is the 2.1? Is not a very old version? If I try to change it I obtain older version, I am attaching a screenshot:
The strange thing is that the other project into my solution uses the .NET 4.5.2 framnework version.
Why this NUnit project is using an old framework version? there is a way to update it?
What is wrong or what am I missing?
You are targetting .NET Core, which is a completely different framework than the Full .NET Framework.
When you create a new project, you specify the framework to target. You created this one to target .NET Core.
To change your project to target Full framework 4.5.2:
Right click the csproj and select edit <yourprojectname>.csproj
Locate the <TargetFramework> element
Change it from netcoreapp2.1 to net452
Close the csproj file
For more info on .NET Core, you should have a look at the About .NET Core documentation.
.NET Core is an open-source, general-purpose development platform maintained by Microsoft and the .NET community on GitHub. It's cross-platform (supporting Windows, macOS, and Linux) and can be used to build device, cloud, and IoT applications.
And taken from the .NET Core on Wikipedia

How do I target .NET Standard 2.0 in a freshly created .NET Core 2.0 web app?

I've just created a fresh project using dotnet new web. My Google-foo may be failing me, but I didn't find anything relating to my answer (please link to another SO answer, or relevant documentation if I've missed something obvious).
If I want to ensure this new project is .NET Standard 2.0 compliant, what do I now do?
It is not inherently possible to run a netstandard project as an executable. Since netstandard was designed to be used for libraries.
In order to develop your web application entirely in netstandard2.0, you would have to create a separate project that targets either .NET Core or .NET Framework to execute your library that contains your web app (developed using .NET Standard).
1. Executable Project (ex: console app)
-- Target Framework: netcoreapp2.0 / net462
2. Web Application Project (library)
-- Target Framework: netstandard2.0
You can use the following steps to change the target framework of your project.
Step 1. Target the desired framework
Right-click on your project and select Edit *****.csproj
In the .csproj file, you need to replace the target framework to the .NET Framework.
Example .csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web"> //<-- note the .Web for the web template
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>
For a list of the Target Framework Moniker (TFM) (ie, net47, netstandard2.0, netcoreapp2.0, etc.*) you can check this link out:
https://learn.microsoft.com/en-us/dotnet/standard/frameworks
Step 2. Run dotnet restore
Go to your output window and run dotnet restore.
Note: Sometimes Visual Studio may misbehave (depending on which update you have installed), so you may have to close and re-open your Visual Studio. Otherwise, sometimes a clean/re-build may do the trick.
Targeting both frameworks
You can pick one or the other, or even target both frameworks.
<TargetFrameworks>netcoreapp2.0; net47</TargetFrameworks> //<-- note the plural form!
NET Standard is for class libraries. Applications must target netcoreapp* where * is a version number. The following shows the compatibility matrix: https://learn.microsoft.com/en-us/dotnet/standard/net-standard
For example, .NET Core 2 can consume .NET Standard version 2 and below.

Both legacy and current dotnet core version support on Linux or Windows?

I have two dotnet core projects. One of them uses dotnet 1.0 (Preview 2 build 3131 and 3133) and other uses dotnet 1.1.1. As far as I know, I cannot run a project.json & xproj based projects with dotnet 1.1.1 and I also cannot run csproj based projects with dotnet 1.0.
I can migrate the legacy dotnet core project to csproj. But I am looking for a solution that I can work on both projects in Windows or Linux.
I checked using docker when compiling projects in Visual Studio and could not find any sufficient resource.
Thanks.
First, you seem to be confusing the version of .Net Core, with the version of .Net Core SDK.
The version of .Net Core (e.g. 1.0.4 or 1.1.1) is not directly related the the difference between project.json and csproj. That is the version of the runtime itself. You can easily switch between different versions of .Net Core on the same machine, just by editing your project file.
The version of .Net Core SDK (e.g. Preview 2 build 3131 or 1.0.3) is what decides what project format you can use. SDK Preview 2 only supports project.json, SDK 1.0.x only supports csproj. You can have multiple versions of SDK installed on the same machine, and thus have support for both project formats at the same time. But if you want to do that, you need to specify the version of SDK for each project using global.json.
As for Visual Studio, VS 2015 only supports project.json and VS 2017 only supports csproj (but should be able to migrate project.json projects).
That being said, I don't see any reason why you should keep using project.json, .Net Core SDK 1.0.x, which supports csproj, works fine on both Linux and Windows.
The csproj based tooling works with both .NET Core 1.0 and 1.1. There also is a tooling preview2 (project.json/xproj) build that has .NET Core 1.1 support (1.0.0-preview2-1-003177).
The point is that the versioning of the tools is independent of the the version of the .net core runtime at the moment, though the upcoming 2.0 releases will be csproj only, with both runtime and tooling having a 2.0 version.

Categories

Resources