Sponsor: Do you build complex software systems? See how NServiceBus makes it easier to design, build, and manage software systems that use message queues to achieve loose coupling. Get started for free.I have a tiny library that I wanted to convert to .NET Standard Library. After all was said and done, I figured it might be useful to even point out some minor things I had to deal with along the way. So here’s a mini guide on converting a library to netstandard.
.csproj conversionFirst was I was going to convert the older csproj to the new style used for NetStandard and NetCoreApp. You have few different options here:
- Create a new NetStandard Library project and copy all the files over.
- Rewrite the existing csproj file
- Use a conversion tool (CsprojToVs2017)
Package ReferencesAll your package references are now in the csproj and no longer in the packages.config. Which is glorious. This means just looking at your existing packages.config and adding the relevant <PackageReference> to your csproj.
AssemblyInfoAll the assembly info is now also in the .csproj instead of being in a Properties/AssemblyInfo.cs file. This is easily translated over as well.
Slim .csprojThe end result is a much smaller csproj file. Prior the file was 126 lines, and now after conversion is 18.
xUnit TestsI could not get the Visual Studio Test Runner or by calling
dotnet test to recognize the tests that are inside a netstandard library. Because of this I changed my test project to be a
netcoreapp1.1, which then worked.
NuSpecIf you are building a NuGet package, the files to be included in your nuspec file will likely have to change since the output of your assemblies will be prefixed with the
TargetFramework. In my case this now resulted in the assemblies being outputted to:
AppVeyorThere were a couple of changes I need to make in AppVeyor as well. First I needed to change my build worker image to Visual Studio 2017. This can be found in Settings > Environment, if you’re using the UI. As of this post, since I converted my test project to .NET Core, the tests were no longer running. This is a known issue. Current workaround is to change your Tests to be executed by a script rather than auto discovered. This way you can execute