Share via


Build a container project from the command line

Relative paths in the Dockerfile are relative to the build context, so if you change the context, be sure to update the relative paths accordingly.

Use MSBuild

To build an image for single Docker container project, you can use MSBuild with the /t:ContainerBuild command option. This command tells MSBuild to build the target ContainerBuild rather than the default target Build. For example:

MSBuild MyProject.csproj /t:ContainerBuild /p:Configuration=Release

You see output similar to what you see in the Output window when you build your solution from the Visual Studio IDE. Always use /p:Configuration=Release, since in cases where Visual Studio uses the multistage build optimization, results when building the Debug configuration might not be as expected. See Customize container images for debugging.

If you're using a Docker Compose project, use this command to build images:

msbuild /p:SolutionPath=<solution-name>.sln /p:Configuration=Release docker-compose.dcproj

To view the MSBuild logs, see Obtaining build logs with MSBuild.

Build from the command line

Visual Studio uses the dev tag to designate images that it has specially prepared to optimize the startup time during debugging. However, these images shouldn't be used outside of the context of Visual Studio. This tag is an indication the images have nonstandard modifications and customizations, for example, to support Fast Mode debugging. See Customize Docker containers in Visual Studio.