Slides for my talk given at local user groups and community events on building .NET based SDK-style libraries using .NET Standard, multi-targeting and continuous integration/deployment through Azure DevOps and public GitHub repositories!
3. @jamesmcroft jamesmcroft@jamesmcroft jamesmcroft@jamesmcroft jamesmcroft
•Moving from PCL to .NET Standard
•Multiple target frameworks in one project
•Generating NuGet packages
•Automating build and release with Azure DevOps &
GitHub
What will be covered
6. @jamesmcroft jamesmcroft@jamesmcroft jamesmcroft@jamesmcroft jamesmcroft
What is a PCL?
•Stands for ‘Portable Class Library’
•Supports cross-platform .NET library development
•But only for subsets of .NET based on profiles
•Old & outdated, not recommended for new projects
7. @jamesmcroft jamesmcroft@jamesmcroft jamesmcroft@jamesmcroft jamesmcroft
•Specification based on .NET APIs across all .NET
implementations
• Think .NET Framework, .NET Core, Mono, etc.)
•Allows the development of libraries reducing
conditional compilation on .NET APIs
•Supports multi-platform targeting
•Ease of shipping as package library for consumption
How is .NET Standard better?
10. @jamesmcroft jamesmcroft@jamesmcroft jamesmcroft@jamesmcroft jamesmcroft
Migrating from PCL to .NET Standard
• Remove ‘Properties’ folder
• .NET Standard csproj format adds all files as part of the project
• Removed files may end up re-adding if they weren’t deleted from source
12. @jamesmcroft jamesmcroft@jamesmcroft jamesmcroft@jamesmcroft jamesmcroft
•Provides support for multiple frameworks
•Benefit of having one project which can provide
outputs for all declared frameworks
•Also, packaging is made easier
•Potential downside, #ifdef conditional everywhere
What is multi-targeting?
<TargetFrameworks>netstandard1.4;netstandard2.0;net45</TargetFrameworks>
13. @jamesmcroft jamesmcroft@jamesmcroft jamesmcroft@jamesmcroft jamesmcroft
• MSBuild.Sdk.Extras NuGet package from Oren Novotny provides
additional framework support
• Drawback that is requires a desktop/VS msbuild.exe to work
(currently doesn’t work with dotnet build)
• Provides TargetFramework options for Windows Phone 8.1 (wpa),
Windows 8/8.1 (win), Windows 10 (uap), Windows Phone 7 (wp),
Silverlight (sl), Tizen (tizen), Xamarin (monoandroid, xamarin.ios,
etc), & legacy PCL (portable-net45+win8+wpa81+wp8)
Multi-targeting extended edition
<TargetFrameworks>netstandard1.4;xamarin.ios10;monoandroid81;uap10.0</TargetFrameworks>
14. @jamesmcroft jamesmcroft@jamesmcroft jamesmcroft@jamesmcroft jamesmcroft
•Additional changes required to csproj to provide
support
•Provides ability to also create conditional item
groups for new TargetFramework options
Multi-targeting extended edition
<ItemGroup>
<PackageReference Include="MSBuild.Sdk.Extras" Version="1.5.4" PrivateAssets="All" />
</ItemGroup>
<Import Project="$(MSBuildSDKExtrasTargets)“
Condition="Exists('$(MSBuildSDKExtrasTargets)')" />
16. @jamesmcroft jamesmcroft@jamesmcroft jamesmcroft@jamesmcroft jamesmcroft
•nuspec is a specification for defining a NuGet
package
•They are hard to maintain but can be automated to
a certain level
•.NET Standard csproj format fixes this
No more nuspec
19. @jamesmcroft jamesmcroft@jamesmcroft jamesmcroft@jamesmcroft jamesmcroft
•For public GitHub projects, Azure DevOps pipelines
is available for free!
•Easy to install and get setup within GitHub
Marketplace
•Setup CI for your main branch & pull requests, and
setup Release Pipeline to push to a NuGet package
source of your choice!
Taking advantage of GitHub + Azure DevOps
20. @jamesmcroft jamesmcroft@jamesmcroft jamesmcroft@jamesmcroft jamesmcroft
•.NET Standard is the future, use it now!
•Keep all of your code neat in simpler projects with
multi-target frameworks
•Use the power of .NET Standard to build your own
NuGet packages
•Automate your build and deployment free in the
cloud with Azure DevOps and GitHub
Recap
21. @jamesmcroft jamesmcroft@jamesmcroft jamesmcroft@jamesmcroft jamesmcroft
•Microsoft Docs for .NET Standard
• https://docs.microsoft.com/en-us/dotnet/standard/net-standard
•Introducing .NET 5
• https://devblogs.microsoft.com/dotnet/introducing-net-5/
•Integrate your GitHub projects with Azure Pipelines
• https://www.azuredevopslabs.com/labs/azuredevops/github-integration/
•MSBuild SDK Extras project
• https://github.com/onovotny/MSBuildSdkExtras
•XPlat Windows APIs project
• https://github.com/XPlat-Apps/XPlat-Windows-APIs
Useful resources