Playing with Target Framework in Visual Studio 2017

By | July 18, 2018

Recently I met a problem: I created new C# application project in Visual Studio 2017 and I found that I cannot assign Target framework to .Net framework, instead of this I see only .Net Core option in Target framework dropdown list. In the same time if I open the project created in Visual Studio 2013 the Target framework show .Net Framework and old .Net framework project can be built in Visual Studio 2017 without any problem. It means that Visual Studio 2017 recognizes .Net framework targets but does not displays them in new projects.
If you type in Visual studio search box “.Net Framework” the Visual Studio presents the whole list of install .Net Framework targeting packs:

So let us start from beginning and create simple C# console application in Visual Studio 2017. From File->New->Project menu open New Project dialog, select project new console2017

as you see there is no .Net Framework option for Visual C# only “Windows Universal”, “.Net Core”, “Net Standard”.

When project is created let us check “Target framework” for this project: Solution explorer right click on the project name and select properties from context menu:

The Target framework does not show any “.Net framework” option. You may try to play with “Install other framework” option but it will not extend content of this dropdown list.

Let us create a simple code which displays main executable module:

rebuild, set breakpoint at the end and start it under the debugger, the result looks a bit strange instead of project name console2017 the output is dotnet.exe:

Why? If you check build result of the project, you will find that there is no executable EXE file is created, only DLL file – console2017.dll:

Definitely it is not possible to start dll directly from command prompt, a dotnet.exe as a starting executable should be used:

If .Net core is installed on Mac or Linux machine for example on Ubuntu this dll could be executed on other operation systems.
Now switch from “.Net core” to “.Net framework”, right click on the project name again and select Edit from context menu:

The project xml file is very short and very simple:

replace netcoreapp2.0 to net45 which corresponds to .Net framework 4.5 and save the project, after reload the project, check project properties:

Now instead of “.Net core” the Target framework dropdown list shows “.Net Framework”.
After rebuilding the project and stating it under debugger we get the following result:

Now the main executable module is console2017.exe instead of dotnet.exe.
After building Visual Studio creates new directory net45 where the console2017.exe is placed:


Leave a Reply

Your email address will not be published. Required fields are marked *