Categories
Hard Skills

Convert .NET Core library to .NET Standard library

Today I just made a mistake to create a library as a .NETCoreApp1.1 Class Library while I really meant to create a .NetStandard Class Library.

It is not a big deal if you realise this before you would start to write a lot of code in it, because you can just delete it and recreate it. Although I did a few hour of coding inside of this library so I didn’t want to delete everything, or playing with copy pasting. I mean I tried to copy paste everything from one library to the other but it crashed Visual Studio 2017. So I started to freak out, but fortunately I made it.

This is how!

The new .csproj structure is very clean and easy to change as I just discovered.

When you open up a .netcoreapp .csproj file in a text editor you will see something similar

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
 <TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>

</Project>

 

Here you can see the root element specifying the sdk, then the most important thing, the TargetFramework where you only have to change netcoreapp1.1 to netstandard1.4 or to your desired version. And basically that is it.

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
 <TargetFramework>netstandard1.4</TargetFramework>
</PropertyGroup>

</Project>

Only one more thing I had to do because I messed up my file and folder structure with copy pasting and renaming. I had to open up MyProject.sln solution file and clear up the mess I created. It is really clean again. Here is how my solution file looks like now.

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.4
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Type1DiabetesSimulationConsole", "Type1DiabetesSimulationConsole\Type1DiabetesSimulationConsole.csproj", "{037AED63-56FA-4559-A699-965D43CE6EE8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Models", "Models\Models.csproj", "{F91471FA-118F-45DA-AC52-C275DC6699EB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BL", "BL\BL.csproj", "{BC627820-6199-4CAD-81A4-FCA8703E08BA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entities", "Entities\Entities.csproj", "{1CFDDE39-0792-4E71-903D-4C6EE9A08395}"
EndProject
Global
 GlobalSection(SolutionConfigurationPlatforms) = preSolution
 Debug|Any CPU = Debug|Any CPU
 Release|Any CPU = Release|Any CPU
 EndGlobalSection
 GlobalSection(ProjectConfigurationPlatforms) = postSolution
 {037AED63-56FA-4559-A699-965D43CE6EE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 {037AED63-56FA-4559-A699-965D43CE6EE8}.Debug|Any CPU.Build.0 = Debug|Any CPU
 {037AED63-56FA-4559-A699-965D43CE6EE8}.Release|Any CPU.ActiveCfg = Release|Any CPU
 {037AED63-56FA-4559-A699-965D43CE6EE8}.Release|Any CPU.Build.0 = Release|Any CPU
 {F91471FA-118F-45DA-AC52-C275DC6699EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 {F91471FA-118F-45DA-AC52-C275DC6699EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
 {F91471FA-118F-45DA-AC52-C275DC6699EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
 {F91471FA-118F-45DA-AC52-C275DC6699EB}.Release|Any CPU.Build.0 = Release|Any CPU
 {BC627820-6199-4CAD-81A4-FCA8703E08BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 {BC627820-6199-4CAD-81A4-FCA8703E08BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
 {BC627820-6199-4CAD-81A4-FCA8703E08BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
 {BC627820-6199-4CAD-81A4-FCA8703E08BA}.Release|Any CPU.Build.0 = Release|Any CPU
 {1CFDDE39-0792-4E71-903D-4C6EE9A08395}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 {1CFDDE39-0792-4E71-903D-4C6EE9A08395}.Debug|Any CPU.Build.0 = Debug|Any CPU
 {1CFDDE39-0792-4E71-903D-4C6EE9A08395}.Release|Any CPU.ActiveCfg = Release|Any CPU
 {1CFDDE39-0792-4E71-903D-4C6EE9A08395}.Release|Any CPU.Build.0 = Release|Any CPU
 EndGlobalSection
 GlobalSection(SolutionProperties) = preSolution
 HideSolutionNode = FALSE
 EndGlobalSection
EndGlobal

If you take a closer look at the highlighted areas you will find the

  • Project name
  • Relative location
  • Global id

in that order. Below you can find the build settings.

From here I had to clean up the unnecessary copies and I could fix the location settings for the broken projects. It basically complained about missing .csproj file, because it forgot to rename the path with the project name when I renamed it inside visual studio.

By Botond Bertalan

I love programming and architecting code that solves real business problems and gives value for the end-user.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.