When a .NET 6, ASP.NET Core project is created by Visual Studio 2022 an "Enable Docker" checkbox is provided as part of the project creation wizard. Simply checking the "Enable Docker" checkbox adds Docker support to the ASP.NET core web application.
Other Visual Studio 2022 project types including .NET Core console projects are not afforded the option to enable Docker support during project creation. This post demonstrates how to add Docker support to a Windows .NET Core console application support created with Visual Studio 2022. Additionally this post will drill down into the changes made the project and solution when Docker support is added.
Microsoft does provide an excellent tutorial on how to create a .NET Core console application using Visual Studio Code, Tutorial: Containerize a .NET app. The aforementioned tutorial shows there are significantly more manual steps to Dockerize a console project using Visual Studio Code compared to Visual Studio 2022 (just a few clicks).
The steps to add Docker support to a console application are as follows:
1) Create a .NET Core console application (see: Docker: Create a .NET Core (.NET 6) Console Application in Visual Studio 2022 for future Containerization)
2) Setup the console application to be published (see: Docker: Publishing a .NET Core (.NET 6) Console Application with Visual Studio 2022 (a Containerization Prereq)). Technically a Docker Support can be added without configuring publish for the project but it is cleaner to configure publishing for the project.
3) Right click on the .NET Core console project in Solution Explorer (project ForensicDataPusher) and select Add | Docker Support:
4) Once Add | Docker Support is selected the Docker File Options dialog is displayed:
Changes Made by invoking "Docker support"
The startup project command changed from ForensicDataPusher (build the solution) to Docker (deploy to Docker).
The ForensicDataPusher .csproj is changed as follows (see the line demarcated in boldface)
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
</PropertyGroup>
No comments :
Post a Comment