Page 36 - MSDN Magazine, May 2019
P. 36
WINFORMS
Create a Centralized Pull Request Hub with WinForms in
.NET Core 3.0
Eric Fleming
Windows Forms, or simply WinForms, has been used for years to develop powerful Windows-based applications with rich and interactive interfaces. The investments in these desktop applications across businesses of every type are profound, with some 2.4 million developers using Visual Studio to create desktop- style apps every month. The benefits of leveraging and extending existing WinForms code assets are compelling, but there are others, as well. The WinForms drag-and-drop designer experience empow- ers users to build fully functional UIs with no special knowledge or training. WinForms applications are easy to deploy and update, can work independent of Internet connectivity, and can offer improved security by running on a local machine that doesn’t expose configurations to the Internet. Until recently, WinForms applications could only be built using the full .NET Framework, but the release of the .NET Core 3.0 preview changes all that.
The new features and benefits of .NET Core go beyond Web development. With .NET Core 3.0, WinForms adds capabilities like easier deployment, improved performance, support for .NET Core-specific NuGet packages, the .NET Core command-line interface (CLI) and more. Throughout this article, I’ll touch on
many of these benefits, why they matter and how to use them in WinForms applications.
Let’s jump right into building our first .NET Core 3.0 WinForms application. For this article, I’m going to build an application that retrieves and displays open pull requests for one of the open source Microsoft repositories hosted on GitHub. The first step is to install the latest versions of Visual Studio 2019 and the .NET Core 3.0 SDK, after which you’ll have access to the .NET Core CLI commands to create a new WinForms application. This wasn’t possible for WinForms applications before the addition of .NET Core support.
Coming soon is a new Visual Studio template that lets you cre- ate a WinForms project targeting .NET Core 3.0. It’s not available just yet, so for now let’s generate a new WinForms project named PullRequestHub by running the following command:
dotnet new winforms -o PullRequestHub
In order to ensure that the project was created successfully, nav- igate into the new directory created by the dotnet new command and use the CLI to build and run the project, like so:
cd .\PullRequestHub\
Because you have access to the .NET Core CLI, you also have access to the commands to restore, run and build. Before running, try out the restore and build commands, as follows:
dotnet restore dotnet build
These commands work just as they would when run in the com- mand line for a .NET Core Web application. And note that when you execute the dotnet run command, it actually performs both a restore and a build before executing the app (bit.ly/2UCkEaN). Now let’s run the project to test it out by entering dotnet run at the command line.
This article discusses:
• Creating a WinForms project in .NET Core 3.0
• Creating a self-contained deployable package
• Benefits of using .NET Core 3.0 for WinForms applications
Technologies discussed:
.NET Core 3.0, Windows Forms
30 msdn magazine