Starting with .net core 2.0 the default framework for the class library template is
netstandard2.0. This makes it quite simple to build libraries that can be used with both .net core and .net framework.
My approach to creating a new class library is from the terminal in VS Code by running the following commands from the root folder of a new git repo.
mkdir src mkdir test dotnet new sln -n <sln name> cd src dotnet new classlib -o . -n <project name> cd .. cd test dotnet new xunit -o . -n <project name> dotnet add reference ..\src\<project name>.csproj cd .. dotnet sln add .\src\<project name>.csproj .\test\<project name>.csproj dotnet build
This will create a
src directory in my root folder and inside that folder it will create a new .net standard 2.0 class library project. The
<project name> will become the name of the dll and also the default namespace so choose wisely.
Next it will create a
test directory alongside the
src directory and inside that folder it will create a new xunit test project.
Up next, it will create a new solution file that includes both the .net standard class library project and the xunit test project.
Then it adds a reference from the class library project to the test project so that the test project has the ability to instantiate and test the class library.
Finally it performs a build to ensure that everything was setup correctly.
Once you have build and tested your library you are ready to publish it to NuGet to share with others.