Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Fast Mode optimizations
When you build in the Debug configuration, there are several optimizations that Visual Studio does that help with the performance of the build process for containerized projects. The build process for containerized apps isn't as straightforward as simply following the steps outlined in the Dockerfile. Building in a container is slower than building on the local machine. So, when you build in the Debug configuration, Visual Studio actually builds your projects on the local machine, and then shares the output folder to the container using volume mounting. A build with this optimization enabled is called a Fast mode build.
This performance optimization normally only occurs when you build in the Debug configuration. In the Release configuration, the build occurs in the container as specified in the Dockerfile. You can enable this behavior for the Release configuration by setting ContainerDevelopmentMode to Fast in the project file:
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<ContainerDevelopmentMode>Fast</ContainerDevelopmentMode>
</PropertyGroup>
If you want to disable the performance optimization for all configurations, and build as the Dockerfile specifies, then set the ContainerDevelopmentMode property to Regular in the project file as follows:
<PropertyGroup>
<ContainerDevelopmentMode>Regular</ContainerDevelopmentMode>
</PropertyGroup>
To restore the performance optimization, remove the property from the project file.
When you start debugging (F5), a previously started container is reused, if possible. If you don't want to reuse the previous container, you can use Rebuild or Clean commands in Visual Studio to force Visual Studio to use a fresh container.
The process of running the debugger depends on the type of project and container operating system:
For information on vsdbg.exe, see Offroad debugging of .NET Core on Linux and OS X from Visual Studio.
Modify container image for debugging and production
Modify container image only for debugging
You can customize your containers in certain ways to help in debugging, such as installing something for diagnostic purposes, without affecting production builds.
Note
The instructions here apply to the single-container case. You can also do the same thing for multiple containers with Docker Compose, but the techniques required for Docker Compose are slightly different. For example, the stage is controlled by a setting in the dockercompose.debug.yml file.
In the following example, we install the package procps-ng, but only in debug mode. This package supplies the command pidof, which Visual Studio requires (when targeting .NET 5 and earlier) but isn't in the Mariner image used here. The stage we use for fast mode debugging is debug, a custom stage defined here. The fast mode stage doesn't need to inherit from the build or publish stage, it can inherit directly from the base stage, because Visual Studio mounts a volume that contains everything needed to run the app, as described earlier in this article.
In the project file, add this setting to tell Visual Studio to use your custom stage debug when debugging.