How to convert NetFramwork 4 code to NetCore 2? - visual-studio

I have a C# project which was created using NetFramework 4.6. I want to convert it to using the NetCore 2.1.
I checked the network, and people say I can just change the Target Framework value in the project's properties page. But on my computer, I cannot see options for NetCore.
I already have the NetCore 2.1 SDK installed.
Is there another way to convert the project? Is there something wrong with my project that prevents it getting converted?

People are wrong, there is no such "one step" approach.
Remember that .NET Core is not a higher version of .NET Framework, it is rather a rewrite from scratch. So it does not work like retargeting .NET Framework version form 4.0 to 4.5.
Porting to .NET Core from .NET Framework is a good place to get started.
Edit: This page lists some differences between .NET Core and .NET Framework.

You can't do this simply like this; because of their totally different frameworks, not different versions of same framework. You have to port your project to .net core; there is one of the nice extension for visual studio that generate a report for you about how portable your code is between .NET Framework and .NET Core.
This is also one of the article about the issue that may be useful for you.

Related

How can I switch an existing 'Class Libray' project to target .NET 5

I have multiple class library projects targeting .NET Framework 4.7.2. I want to upgrade to .NET 5. In the project properties I only see versions of the .NET framework, I don't see .NET 5. I know I could open the project as a file and modify the target framework but what is the correct way of doing it with the UI?
Microsoft provides here a good migration example. You can also check this post with another example.
If you intend to do this gradually, keeping common packages compatible with both .NET Framework and .NET 5, you may use .NET Standard projects/packages for that.

How do I convert a project from targeting .net core to target framework to a .net standard?

I created a new .net core 3.1 project and built it using VS2019 16.4.4
Now I want to change it to .Net Standard.
I know to go to the project properties and select the Target framework combo.
However no Standard framework options appear.
If I select Install other frameworks then I am taken to The download .Net SDKs for Visual Studio page
However the SDK I want is already installed on my machine.
Why am I not seeing what I want in the combo box.?
.NET Standard, like .NET Core and .NET Framework, is separate framework, so you can't switch that easily. You would need to create separate project targeting .NET Standard. Once you do it, you will see other options in 'Target framework'.
Worth to mention, you can't reference .NET Core and .NET Framework projects from your .NET Standard library, since .NET Standard is just an abstraction which is built differently depending on the executing environment (.NET Core or Framework)

In Visual Studio 2019, .net Core 2.1, how do I add .net Framework assembly to the project

I am working in Visual Studio 2019, and .net Core 2.1.1.
I am currently working on trying to get Identity Server 4's WsFederation integrated. In the latest instructions I could find, he mentions adding System.IdentityModel to the app through the project.json. Project.json seems to be deprecated now in .net core projects, and I am having a hell of a time figuring out how to add a freaking .net assembly to my project. Do I really need to just copy the file into the project and reference, cause that just seems wrong.
Instructions I am using:
https://www.scottbrady91.com/Identity-Server/IdentityServer-4-SharePoint-Integration-using-WS-Federation
Seems to all come back to the project type. I had created the project with AspnetCore and so I couldn't reference any .net framework assemblies, because you can't go back once you have made that choice. However, if you create the project specifically under the .net framework, you can move forward into the core frameworks, and hosting libraries of core. Which then allowed me to pull in the System.IdentityModel assemblies I needed to continue forward.

Xamarin cross platform .net2.0

I've created a Cross platform Application for Xamarin in Visual Studio. The application is running on .NET Standard 2.0 and it's not possible to select a higher version.
Isn't possible to run a Xamarin project on a newer .NET version? The problem is that a want to install nuget packages that requires at least .NET 4.5.
Thanks in advance.
You are confusing .net and .net standard. .net standard gathers many other .net platform (for example .net core, uwp, windows phone etc...) including the classical .net (from 4.5 to 4.6.1). Take a look at this table to have a better understanding.
This means that you should be able to include your library that targets .net 4.5.
Now that you know that, you can define a fallback version if the library does not target .net standard. To do so add this line in your .net standard .csproj in the PropertyGroup node
<PackageTargetFallback>$(PackageTargetFallback);portable-win+net45+wp8+win81+wpa8</PackageTargetFallback>
.NET Standard is a standard, official documentation is nicely covering it. Beside that must read, here is a compatibility table.
So please, read the official documentation. Setup your mind and come back with a proper question. Currently it does not make sense.
Good luck!
P.S.: Currently you are trying to use an outdated library that does not support .NET Standard, you might want to look for alternatives.

Class Library (Legacy Portable)?

I have one PC with Microsoft Visual Studio Community 2017
Version 15.2 and it has a project template for Class Library (Portable).
Another PC with Version 15.3.1 has a template for Class Library (Legacy Portable). Are PCLs now legacy ?
Any current news on what I should be using instead ?
Well, "should", I won't say that without seeing exactly what you're doing but yes, PCLs are now "legacy", the new way is .NET Standard and .NET Core.
Please note that legacy does not mean "will stop working" so there shouldn't be a need to do anything as of yet.
To figure out which kind of .NET Standard version you want to target to get-out-of-legacy, you can consult the compatibility list on the .NET Standard web page.
Specifically, you likely want to consult the other matrix on the same web page, the .NET Implementation Support matrix and figure out which platforms you want to target, then create a "Class Library (.NET Standard)" project targetting the highest .NET Standard version you can get away with.

Resources