.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.
.NET Core has the following key features that makes it stand apart from its predecessors.
- It runs on various platforms such as Windows, macOS and Linux operating systems.
- Due to it being consistent across various architectures you can run your code with the same behavior on multiple architectures, including x64, x86, and ARM.
- It includes easy-to-use command-line tools that can be used for local development and in continuous-integration scenarios.
- It has a flexible deployment system, where you can include it in your app or install it side-by-side (user-wide or system-wide installations).
- .NET Core is compatible with .NET Framework, Xamarin and Mono, via .NET Standard.
- The .NET Core platform is open source, using MIT and Apache 2 licenses. .NET Core is a .NET Foundation project.
- .NET Core is supported by Microsoft, per .NET Core Support.
Porting desktop applications to .net core
.NET Core 3 and Visual Studio 2019 are important necessities to porting your desktop apps to core.
Step 1 – Running the Portability Enhancer
Before going for porting, it is important to check the compatibility of the application with .NET Core. This can be easily achieved through .NET Portability Analyzer.
- You need to check for 100% compatibility score that will confirm that your app’s compatibility with .NET Core
- Incase the score isn’t 100%, you’ll need to find the incompatible features of the application from developer resources to see if they have a .NET Core or Standard version available.
- Incase they are not available, then you’ll need to go to Column assembly and recreate the incompatible features and rewrite the code so as to not use the .NET Core API or use alternative APIs of .NET Core.
Step 2 – Migrating to SDK-styl .csproj
Review the Solution Explorer in your project. Incase your “edit project file” option is reflected then it confirms that you’re using the SDK-style project file. Incase it doesn’t show up then you can follow the following steps
- Look for packages.config file. Then right-click the packages.config and choose Migrate packages.config to PackageReference. Click OK to proceed. Incase you don’t find the packages.config file then it’s fine and you can skip this step
- Next, we need to open the application project file and choose Unload Project. Then choose Edit
.csproj after right clicking the project file
- Next step is to delete everything from your project file in Visual Studio replace the following code.
For a WinForms application:
For a WPF application:
- Then search for PackageReference. Once found, copy the entire ItemGroup that contains PackageReference. Repeat this step in your Visual Studio project file for each occurrence of PackageReference that could not be found. The final block should ideally look like the following:
- Repeat the above steps for ProjectReference. Incase you did’nt find this, the file should look similar to the following
- You also can delete any lines with Project and Name properties, as they may not be required in the new project file style. In any ProjectReference that you may have found only copy the ItemGroup and ProjectReference as shown below:
- Last but not the least, Save everything. Once you close the project file, right click on your project in the Solution Explorer and select Reload Project. Once loaded up go ahead and rebuild while making sure no errors crop up..
This is an effective way of uploading your application project file in SDK-style.This will target the .NET Core framework going forward.
Step 3 – Retargeting the App to .NET Core
Open your project file in Solutions Explorer. Look for the TargetFramework property and change the value to netcoreapp3.0. It should look like the following.
Go ahead and build your project and run it. It should have completed your porting to .NET Core 3!
If you’re looking for help in porting or creating applications based on .Net Core, contact us today!