This website uses cookies on its adverts and sponsored links. By clicking the "Accept" button you are consenting to their use.

Read more

Accept


Mobile Tech Tracker
≡ sections
Coding Courses

Tech Advice

Career Advice

Cybersecurity

Opinions

About

Welcome to Mobile Tech Tracker. Our mission is to help technically-minded people to become better versions of themselves and to help ordinary people to use modern smart technologies to their own advantage.

We can provide consulting or programming training services, including authoring of courses and books. For enquiries, please contact consulting@mobiletechtracker.co.uk.


Using .NET Core SDK projects in .NET Framework

As a software-building platform, .NET Core has already reached a sufficient level of maturity and can do many of the things that its predecessor - .NET Framework, can. Microsoft has even recommended to use it instead of .NET Framework, unless it's absolutely necessary to do otherwise.

.NET Core has many advantages over .NET Framework. One of such advantages is the SDK-type project file. If the content of any project file needs to be edited, a new SDK-type project file doesn't have to be unloaded, unlike a project file that uses classic .NET Framework format. The latter are also way less verbose than the former, which makes it easier to read and edit.

Unfortunately, despite all of its advantages, there are still many real-life situations where .NET Core cannot be used. There are many .NET Framework features that simply don't exist on .NET Core. Some of these features, such as playing audio, can be implemented by using third party libraries, while others, such as the ability to build full feature native GUI apps, isn't available on .NET Core at all (or, at least, not fully available yet).

However, even if you are stuck with .NET Framework, you don't have to be stuck with its ugly and awkward project file format. Even though it's not obvious how to apply SDK projects to .NET Framework, it's not difficult at all. And this trick will significantly improve your productivity.


Setting up your project

We will use a basic Console app as an example; however the concept can be easily applied to any other application types.

The first step is to create a new .NET Core Console application project.

So, instead of this:

.NET Framework project

the project file in our new application will look like this:

.NET Framework project

Our project has "netcoreapp" followed by the version number as the value of "TargetFramework" element. If we right-click on the project and click on its properties to access a more user-friendly way to edit the project, we can see that its framework can only be changed to various versions of .NET Core, depending on what SDK versions are installed on a given development machines.

It seems that changing the project type to .NET Framework isn't possible. However, all you need to do is to open the project file and change "netcoreapp" to "net". The version number that follows is the .NET Framework version that you will need, but with decimal points removed. For example, if you would need to use .NET Framework 4.6.1, you would type it as "net461".

That's it. If you open the project properties now, you will see the following:

.NET Framework project properties

And instead of old style dependencies:

.NET Core dependencies

The dependencies will be organised in .NET Core style:

.NET Framework dependencies

And, on top of all of these, you will not have to unload the project to edit it. All you'll have to do is right-click on your project and chose the "edit" option.

.NET Core edit project


Some effective solutions are often simple

After following these steps, you will not want to ever use the classic project file format again.

Of course, there are still certain project files where this technique isn't applicable, for example, an Azure Service Fabric application project cannot be created in SDK format. Likewise, there are several other project types that just can't be created in .NET Core to start with. However, there are still many real-life situations where the trick from this article can be applied.

Where this technique can be used, it will significantly improve your productivity. As well as making it easier to navigate your MSBuild script and giving you the ability to edit your project file at the same time as looking at the code inside the project, it will make make it much easier to perform code reviews. After all, it is always far easier to examine changes in a file that has fewer items in it.



Written by

Posted on 19 Feb 2019

Fiodar Sazanavets is a full stack software developer with several years of experience working in various industries. In his professional career, he has mainly worked with a number of different technologies from Microsoft stack, both back-end and front-end, and Java for Android. The main Fiodar's speciality is .NET. As well as being an experienced programmer, Fiodar has an Honours degree in Environmental Biology and a Masters degree in Environmental Informatics.



Tech Advice Articles


C# basics in practice - manipulating text files

C# basics in practice - manipulating text files


Differences between mono and .NET Core

Differences between mono and .NET Core


Applying clustering on OpenLayers map

Applying clustering on OpenLayers map


Why you absolutely need SignalR for ASP.NET development

Why you absolutely need SignalR for ASP.NET development


Pros and cons of Blazor for web development

Pros and cons of Blazor for web development


Web GIS: Making modal pop-up on an OpenLayers map

Web GIS: Making modal pop-up on an OpenLayers map


Learning .NET Core from scratch

Learning .NET Core from scratch


Playing audio on .NET Core with NetCoreAudio

Playing audio on .NET Core with NetCoreAudio


Building .NET Core sound application - part 3

Building .NET Core sound application - part 3


Building .NET Core sound application - part 2

Building .NET Core sound application - part 2


Share this:

Facebook Google LinkedIn Twitter Become a Patron!

More from Tech Advice











Privacy Policy

© Mobile Tech Tracker. All rights reserved. Unauthorised copying of any of this website's content is prohibited under international law.

For any queries, comments or suggestions, please write to info@mobiletechtracker.co.uk.