What email address or phone number would you like to use to sign in to Docs.com?
If you already have an account that you use with Office or other Microsoft services, enter it here.
Or sign in with:
Signing in allows you to download and like content, and it provides the authors analytical data about your interactions with their content.
Embed code for: Building Libraries with .NET Standard
Select a size
Building Libraries with .NET Standard
About the presenter
Principal Architect, BlueMetal
What is this thing, where did it come from?
Minimal class library
How did we get here?
Portable Class Libraries, released in 2010
Least common denominator
The more platforms you support, fewer APIs available
Requires library author to choose platform support
Has us talking about “Profiles”
What is this thing?
Set of common surface areas
Decouple the API set from the platform
.NET Standard is like HTML5
.NET Core, UWP, .NET Desktop, Xamarin are like browsers
.NET Standard versions
Currently 1.0 – 1.6
2.0 is in preview
Each version defines a larger surface area
Platforms implement surface area up to version
What to choose?
Use lowest version that has the types you need
In general – Profile PCL’s are up to 1.2
Most new API comes in at 1.3
UWP is currently 1.4
.NET 4.6 is 1.3, 4.6.1 is 1.4/2.0
Xamarin, .NET Core are 1.6
Visual Studio 2017
Visual Studio Code
Visual Studio for Mac
.NET Core SDK CLI tools
OmniSharp-based plugins for Sublime, Emacs, Atom, Vim, Brackets
Demo: Getting started
A minimal class library
Adding a NuGet package
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
Referencing another project
<ProjectReference Include="..\LibraryB\LibraryB.csproj" />
References are transitive
Project references (watch-out)
You do not need to add NuGet references to all of your projects!
<ItemGroup Condition="'$(TargetFramework)' == 'net45'">
<PackageReference Include="Some.Net.Lib" Version="1.0.0" />
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.4'">
<PackageReference Include="Some.Other.Lib" Version="1.0.0" />
Packaging with NuGet
Creating packages is built-in
Add the NuGet properties to your project file
Supports SemVer 2.0
Private feeds (MyGet)
Run either dotnet pack or msbuild /t:pack
NuGet.org does not yet support SemVer 2.0 (in progress)
Auto-version with Nerdbank.GitVersioning
NuGet Package Explorer in the Windows Store
NuGet project properties
Demo: Converting a PCL to .NET Standard
Released as an update to VS 2010
Goal was to allow you to use a single binary on all of the .NET platforms
Works by developer selecting which platforms they want to support
“Platform first approach”
Runs into roadblocks quickly.
Requires lib authors to update to support new platform
Many libraries may not “need” to be updated
Set of API’s defines a standard level
Platforms can support a standard version
.NET has seen a resurgence in the last few years and has a wide variety of tools across platforms
File -> New Class Library (.NET Standard)
SDK – “Sdk style”
Add a package reference
With Visual Studio’s NuGet UI
CLI: dotnet add ….
Same thing, just ProjectReference
Today, in VS, you have to reference each project directly.
You have to reference each package in each project
Hard to maintain
Can get out of sync
“shouldn’t have to”
Multi-targeting is the ability to create more than one output from a single project
If you have platform specific code
If you want to support downlevel platforms and provide more in newer platforms
You’ve created your library, now you want to distribute it to others
How many people have used NuGet before?
How many have created a package before?
NuGet.org / MyGet / VSTS
CI / CD, great way to distribute internal libraries so consuming apps can pick up revisions when appropriate to them
No need for separate nuspec files anymore
Versioning becomes a hot issue. Tools like Nerdbank.Gitversioning and GitVersionTask can help
How many people have heard of SemVer?
There are many properties that are used in NuGet. Most are exposed in the UI, so don’t worry about not remembering what they all are
.NET has seen a resurgence in the l