Chapter 11. Multiple frameworks and runtimes

 

This chapter covers

  • The .NET Portability Analyzer
  • Building projects that work on multiple frameworks
  • Handling code that’s operating-system specific

There are two features of .NET Core that we’ll look at in this chapter. One is the ability to run .NET Core applications on many different operating systems. The other is the ability to write .NET code specific to each .NET framework if you need the code to operate differently.

You can take advantage of these capabilities in your own applications and libraries, which is particularly useful when you have to extend beyond the .NET Standard. It’s also useful when you’re trying to use OS-specific features or native components as the interfaces, because these will be different on each OS.

11.1. Why does the .NET Core SDK support multiple frameworks and runtimes?

The .NET Core SDK supports building for multiple frameworks. You can specify the desired framework with a command-line option.

Consider these examples:

dotnet build --framework netcoreapp2.0
dotnet run --framework netcoreapp2.0
dotnet test --framework netcoreapp2.0

So far in this book we’ve only targeted one framework at a time—either netstandardxxx or netcoreappxxx—so there was no occasion to exercise this capability.

11.2. .NET Portability Analyzer

11.3. Supporting multiple frameworks

11.4. Runtime-specific code

Additional resources

Summary

sitemap