.NET Console Applications
  • 12 Jan 2023
  • 2 Minutes to read
  • Dark
  • PDF

.NET Console Applications

  • Dark
  • PDF

Article Summary

Building .NET Console Applications

Console applications are designed to be used through a text-only interface or to be executed without an interface by another automated tool. The functionality or behavior of a console application is controlled by its arguments, and the complexity of applications can range from a simple "hello world" application to a cornerstone of a platform (e.g., Git) or even monoliths.

Several technology platforms are capable of building console applications, including NET. End users are generally tech-savvy, and console applications are typically used on desktops or servers, either manually or as part of a script.

In terms of distribution within an organization, locating these console applications can be challenging and is often done manually in one of the following ways:

  • sent via email
  • shared via Slack
  • stored on a file share
  • published to an internal website

These options make keeping track of console application releases tricky, particularly when they are used often by many folks throughout an organization.

Building .NET Console Applications

In general, the method for building console applications is platform specific. For .NET specifically, a developer would use Visual Studio, dotnet build for .NET Core applications, or in the case of automated tooling for example, a CI server would use MSBuild.

Example MSBuild Command

MSBuild.exe "ProfitCalc.Console.csproj" "/p:Configuration=Release" "/p:OutDir=C:\tmp\build-output\\"

After this command is run, ProfitCalc.Console.exe would be available in C:\tmp\build-output

Automation with BuildMaster

At a high level, the process in BuildMaster follows the general pattern:

  • Get source code from the source control repository
  • Compile project with MSBuild
  • Capture artifact for deployment

Compiling a Console Application

To build a .NET console application, the first step is to acquire the source code from your SCM of choice, e.g. using Git::Get-Source. Once the source code is obtained, simply run the MSBuild::Build-Project operation:

MSBuild::Build-Project ~\Source\ProfitCalc.Console\ProfitCalc.Console.csproj
    To: ~\Output

While this works for the standard .NET framework, compiling .NET Core applications involves a different set of steps.

Testing the Build

Once your project or solution is compiled, BuildMaster can run unit tests or other automated tests against the build using VSTest, NUnit, or any other testing framework.

Capturing the Build Output for Deployment

After compilation of a console application is compelted, the output is usually an .exe file on Windows. This .exe file can be captured into a file for future deployment using the Create-Artifact operation.

To see an example of building a .NET console application in BuildMaster, create a new application using the ProfitCalc Tutorial sample application. Creating a new build of this application will compile the source code from https://github.com/Inedo/ProfitCalc.git, and captures a runnable executable into a build artifact.

Deploying Console Applications

Once the console application artifact is captured, it can be delivered in a variety of ways:

  • deployed to to a network drive
  • uploaded to a web site with a download link
  • emailed to users as an attachment

An example of deploying to a network drive would be:

Deploy-Artifact ProfitCalc
    To: \\hdars-share-us-east\$d\apps\$ApplicationName\$ReleaseNumber

Was this article helpful?