Page 24 - MSDN Magazine, November 2018
P. 24
.NET CORE
Publishing Options with
.NET Core
Jamie Phillips
The advent of .NET Core brings a new paradigm for publishing your applications with the introduction of two new techniques: framework-dependent deployments (FDDs) and self-contained deployments (SCDs). Each option has advantages and disadvantages that need to be considered before publishing. In this article, I explore both approaches by building a sample appli- cation and discussing the strengths and weaknesses of each. I then take a brief look at an additional deployment option—CoreRT— that’s in the early stages of development.
Publishing with .NET Core brings a lot of information to con- sider. Traditionally, the typical deployment option for a desktop or console application in the .NET Framework has been an execut- able. For an ASP.NET application, it’s a DLL. These were the only available options and they were dependent on the type of applica- tion being built. With the new paradigm, the significant aspect is whether .NET Core is installed or not. The FDD technique requires that .NET Core be installed while the SCD technique brings the .NET Core runtime with it, which means it can run on a machine that doesn’t have .NET Core installed. An ASP.NET application can now additionally be packaged as a standalone console application because it brings its own Web server (Kestrel) as an executable.
For my exploration of the two approaches, I’ll use .NET Core SDK 2.1alongwithacommand-lineinterface.Youcanfindinstructions for installing .NET Core 2.1 at microsoft.com/net/download. I’m using PowerShell almost exclusively to run all the commands that I show in the article, but the command prompt (cmd.exe) should work just
fine, as well, and, in fact, these commands will execute on the shells of other OSes, including macOS and Linux. Finally, to experiment with SCDs, the Windows Subsystem for Linux (WSL) is invaluable for enabling first-hand testing of any executables created for Linux. You can learn more about WSL at bit.ly/2Nj7FuQ.
Sample Application
I’m going to create a very basic sample application for testing the two publishing methods using .NET Core 2.1. This will be a console application that prints hello along with the name provided. You can use either cmd.exe or PowerShell to input the following code:
> dotnet new console -o Publishing
Once the new console application has been created, I open Program.cs and enter the following code:
using System; namespace Publishing {
class Program {
static void Main(string[] args) => Console.WriteLine($"Hello {args[0]}!"); }
}
When I execute the application, I see this:
> dotnet run -- Jamie Hello Jamie!
As you can see, it works as expected. As a quick aside, the two hyphens syntax (--) is how parameters are passed to the application when using the “dotnet run” command. With my console applica- tion complete, I can dive into the publishing methods.
The Publish Command
First, let’s look at the options available with the publish command by executing it with the “-h” (help) option:
dotnet publish [<PROJECT>] [-c|--configuration] [-f|--framework] [--force] [--manifest]
[--no-build] [--no-dependencies] [--no-restore] [-o|--output]
[-r|--runtime] [--self-contained] [-v|--verbosity] [--version-suffix]
Note that two of these options are especially useful when pub- lishing .NET Core applications: --runtime and --self-contained. These options are used together; runtime specifies which runtime
CoreRT is currently in pre-release, so all information is subject to change.
This article discusses:
• Framework-dependent deployments
• Self-contained deployments
• CoreRT—natively compiled deployments Technologies discussed:
.NET Core, .NET Core CLI, CoreRT
18 msdn magazine

