Page 26 - MSDN Magazine, September 2017
P. 26
.NET CORE
Write .NET Apps How
and Where You Want
Andrew Hall and Joe Morris
Hopefully you’ve heard by now that the Microsoft .NET isn’t just for Windows anymore. .NET Core brings the ability to write applications that run on any OS you choose (Windows, macOS or Linux) using the language you prefer (C#, Visual Basic or F#). Of course, with the ability to write applications targeting the platform of your choice, you expect the same great developer tools that have always been a hallmark of .NET development. The great news is, as our supported platforms have grown, so have the tools available for creating great .NET applications.
In this article, we’ll walk you through the development tools available based on your personal work style and OS. We’ll start with the command-line tools included with the SDK that you can pair with any editor (although we recommend Visual Studio Code), then we’ll show the great new capabilities of Visual Studio 2017 before introducing you to our newest member of the Visual Studio family, Visual Studio for Mac. Finally, we’ll conclude by showing how these tools empower you to leverage software con- tainers and try your apps seamlessly in the Microsoft Azure cloud.
Basic Concepts
For the purposes of this article, we’ll use the term “.NET Core” everywhere for the sake of consistency, but there are two important technologies covered by this name: .NET Core and .NET Standard. .NET Core is the cross-platform runtime that executes applications. .NET Standard is a compiler-enforced set of APIs that are used as a
target for class libraries, so a single library can run on any runtime that supports the standard. For example, .NET Core 2.0, .NET Framework 4.6.1 and Mono 4.8 support .NET Standard 2.0 (and previous) class libraries. For a better understanding of this concept, see the compan- ion article, “Demystifying .NET Core and .NET Standard” in this issue.
It’s also worth noting the languages supported by .NET Core and .NET Standard 2.0. At a high level, both technologies support C#, Visual Basic and F# in 2.0. However, our aim with Visual Basic this release was to enable .NET Standard 2.0 class libraries. This means Visual Basic only offers templates for class libraries and console apps, while C# and F# also include templates for ASP.NET Core 2.0 apps.
Improved Common Project File
One of the first things you’ll notice about working with .NET Core projects is that they share a highly simplified common project for- mat. This means that a project created with one tool (for example, the command-line tools) will work on anything that supports .NET Core (such as Visual Studio or Visual Studio for Mac). With our new proj- ect file format, we’ve removed the need for GUIDs, and for explicitly listing included files—which greatly reduces merge conflicts when committing updates to version control. The following code shows the entire contents of the project file for a new C# .NET Core console app:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework> </PropertyGroup>
</Project>
Additionally, the common format means that members of the same team can work using the device and platform of their choice. If one team member wants to work on a Mac, another on Windows, and a third on Linux, they can all seamlessly contribute to the same project. To learn more about the updated project format, visit aka.ms/newprojectfile.
Command-Line Tools
The foundation of any developer tool is the Software Development Kit (SDK), and .NET Core is no different. One of the integral parts of the .NET Core SDK is the command-line interface (CLI), which enables you to create, build and run apps from the command line.
This article discusses:
• The simplified common project format
• The command-line interface
• Unit testing support
• Visual Studio Code, Visual Studio, Visual Studio for Mac
• Using software containers and the Microsoft Azure cloud Technologies discussed:
.NET Core 2.0, Visual Studio 2017, Visual Studio Code, Visual Studio for Mac, Docker, Microsoft Azure
22 msdn magazine