No option to create .NET 5.0 library in Visual Studio 2019 - c#

I can create .NET Framework and .NET Core but there is no option to create .NET library which is supposed to be the new .NET 5.0
I have seen the I can't create console application with .NET 5.0 as well (option missing) but I can create WPF application with that.
I want to create .NET library so to be able to use with WPF project and ASP project created with .NET 5.0 as well, so why is that option not there? I don't need it terribly in console but it would be nice to so I can test/access the library there as well.
My visual studio is up to date with everything.

First, we need to check your .net version
please check your dotnet SDKs by command below (in git bash or Windows cmd)
dotnet --info
for example, this is my dotnet SDKs
If you had no problems with SDKs check your Visual Studio for support .net5
whatever you can change the Target Framework version OR the c# Lang Version
manually in .csproj file
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
OR
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

For the sake of completion. I found a better way how to accomplish that and I answered the linked question with my solution here.
Essentially you just create .NET Core library and then change the version to .NET 5. See complete answer with screenshot in the linked proved above.

Step 1
Open Visual Studio Installer and make sure following are installed:
ASP.NET and Web Development
.NET desktop development
.NET Core cross-platform development
Step 2
Open Visual Studio 2019
Go to File Menu --> New --> Project
In Create New Project Window make sure all the filters are clear in the right pane
In Create New Project Window enter "library" in the "Search for templates" box at the top and hit enter to display library project type templates below
Step 3
After creating class Library Project follow instructions in following post to change type of class library project to target .NET 5.0
How to create .Net 5.0 Class Library project in Visual Studio 2019 16.8.1?

Related

Migrate ASP.NET Core 3.1 to .NET 5.0

I have ASP.NET Core 3.1 project with React and Redux in VS Profession 2019 and use included SubProject Library with .NET Standard 2.1 in Solution.
After the release of .NET 5, I change via Project => Properties => Application:
Library from .NET Standard 2.0 to .NET Standard 2.1
ASP MVC Core from .NET Core 3.1 to .NET 5
The application works perfectly, but if I want to edit Controller, where I include a dependency to Libraries from other projects I see Interface with the red color name:
I am not sure where is the problem, and why VS does not find a reference to the libraries.
Because program works, I have added references, but only VS do not see this
Intellisense sometimes misbehaves. You can
Close VS (do not skip this step)
Delete all 'bin' and 'obj' folders for all your projects.
Re-open VS and do a clean re-build on the solution.
This will either expose issues you may have missed or fix the red underlining.
Easy Solution
Change in each .NET Standard library *.csproj from:
<TargetFramework>netstandard2.1</TargetFramework>
to:
<TargetFramework>net5.0</TargetFramework>
Update Nuget packages

How to change .NET Framework to .NET Standard/Core in Visual Studio?

I have a solution in C# in Visual Studios. It was first created in .NET Framework. I want to convert the project to .NET Standard/Core. If I go into project --> properties I see the attached screen, where Target Framework is .NET Framework. How am I able to change that to .NET Standard/Core?
As Roman Ryzhiy mentions in the comments, this is the way to go:
https://learn.microsoft.com/en-us/dotnet/core/porting/
This worked fine for me, I upgraded a .NET Framework 4.7.2 projekt. It was a small project, so I had few aftermath-problems. After the upgrade, the Target Framework in the Application tab will say ".NET 5.0".
Install upgrade-assistant:
dotnet tool install -g upgrade-assistant
Go to your solution folder
Run the assistant:
upgrade-assistant upgrade your-project-name.csproj
Follow the steps in the assistant, it's really straight-forward.
Also, here are the steps more detailed:
https://learn.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-overview#installation-steps

Targeting .NET Core 2.0

I just create a simple ClassLibrary project with VS2017 preview 2.1.
I create using .NET Core project template. When I check in project details, I see it targets .NET standard 2.0. How I may target .NET Core 2.0 (that implement a larger number of API according to a test made with API-Port tool)
Update: The templates have been fixed in a recent update to VS 2017 15.3 Preview.
This really looks like an issue with the templates, I also created a project from the "Class Library (.NET Core)" template and it targeted .NET Standard 2.0.
However, this can easily be fixed by editing the csproj file manually from
<TargetFramework>netstandard2.0</TargetFramework>
to
<TargetFramework>netcoreapp2.0</TargetFramework>
This project type allows editing the csproj file while the project is loaded by right-clicking on the project and selecting "Edit {project}.csproj".
It looks you may create a .NET Core app with VS2017 targeting .NET Core 2.0, but as soon you create a .NET Core project library, it targets .NET standard, it might be a limitation of this preview of VS2017.
The issue is gone with VS2017 15.3.0 Preview 3!
I'm on Visual Studio 2017: Community.
I installed the SDK found here: https://www.microsoft.com/net/download/thank-you/dotnet-sdk-2.1.3-windows-x64-installer
You should be able to see the NET Core 2.0 as the target framework when creating your project.

How to prevent Visual Studio to prompt to upgrade projects .NET 4 to .NET 4.5

I have a solution in with project in C#, C++/CLI targeted to .NET 4 and with some dependencies in .NET4. When I open this solution in Visual Studio 2013 it prompts for upgrading the solution. Some developers in our remote teams don't read the messagebox and just press OK. The dependencies are not compatible after project upgrade and then they are mailing me that the solution cannot be built.
Is there some way to turn off this prompts for .NET Framework upgrade?
Put the following line in the global property section of your project file.
<VCProjectUpgraderObjectName>NoUpgrade</VCProjectUpgraderObjectName>
in context:
<PropertyGroup Label="Globals">
...
<VCProjectUpgraderObjectName>NoUpgrade</VCProjectUpgraderObjectName>
</PropertyGroup>
Works for Visual Studio 2015 & 2017 as well.
You will need to remove it when you want to do the upgrade.
Source: https://blogs.msdn.microsoft.com/dsvc/2015/12/13/migration-from-vs2012-to-vs2015-ide-only-throws-compiler-upgrade-warning/

How to create .NET Platform Standard project

I read up on the new .NET Platform Standard concept replacing the old Portable Class Libraries, which seems nice. However, I can't seem to figure out how to create such a library, yet.
Is there a Project Template for Visual Studio where I could choose the target generation / netstandard? Or do I have to manually change a PCL project.json file for this?
(Got VS15, Update 3 installed)
If you create a PCL project and then double click properties, you should see an option to change your target platform. That will let you choose a .net standard version. Same thing as doing it yourself in the project.json but is the closest thing I have found so far to having a VS template do it for you
You can follow this Create .NET Standard Packages with Visual Studio 2015
From the article:
This guide will walk you through creating a nuget package targeting
.NET Standard Library 1.4. This will work across .NET Framework 4.6.1,
Universal Windows Platform 10, .NET Core, and Mono/Xamarin.
On Visual Studio 2019 it is possible to create projects that target .NET standard, just as you create another type of project. To do so, you just need to add new project, and then if you search for .net standard it will show several types of projects in which you can target .NET standard, as shown below.
You can also create new .NET Platform Standard projects from a template by using Visual Studio 2017 RC.

Categories