MSBuild Switch for Building Docker Image

VENKATESH 21 Reputation points
2021-06-18T14:44:11.617+00:00

Is it possible to build docker image (docker build command) implicitly / directly from msbuild (say, thru a flag or switch). Searched a lot, but couldn't find anything.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,160 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 47,461 Reputation points
    2021-06-18T15:06:58.487+00:00

    MSBuild is for building a project, not containers. In general you will have a build script that runs that would handle this. In a build server environment the script generally pulls down the code, sets up any build infrastructure, builds the solution(s), runs unit tests and then publishes the build and/or builds containers. MSBuild is only responsible for one of these steps.

    If for some reason you really, really want to do this as part of the build then the workaround would be to create a post-build event in your project. However post build events run after a project builds, not the solution. Therefore you'd have to ensure it was the last project to build. Then you can run any command line tools you need to. But, again, this is not recommended. Furthermore post build events run in VS as well so you probably don't want to waste the time building a container while debugging.

    Finally note that VS has built in support for containers. While I haven't used it myself I suspect VS can help generate the scripts you need.


0 additional answers

Sort by: Most helpful