Working in a new demo project called “CMCDSample”, with Visual Studio 2017, I have found a small limitation in “Docker” projects (“docker-compose”) in VS2017, and below I document both the limitation and its solution.
Limitation of original “docker-compose” projects in VS217
When VS2017 builds (or runs with F5) an original “docker-compose” project of VS2017, it checks if the selected configuration is “Debug”, in which case it searches for a file, inside the project, called “docker-compose.vs.debug.yml” to use it in the build process. If the actual configuration it is not called literally “Debug”, then VS2017 assumes that it is a “Release” and tries to use (if exists), the file “docker-compose.vs.release.yml”.
The project “CMCDSample” shows how to manage two Sitecore servers with different roles (“Content Delivery” and “Content Manager”) inside a development environment. This solution of Visual Studio needs a configuration for each role server of Sitecore. At the same time, each one of those roles needs a “Debug” and “Release” version. In conclusion, we need the following configurations:
The behaviour of VS2017 previously described conflicts with the needed of having several configurations of “Debug” for the different roles of the Sitecore server. The logic applied to the build process, makes the configurations “DebugCD” and “DebugCM” build like if they were “Release”, disabling all the functionality needed in a development environment to debug the code.
Fortunately, there is an easy fix that allow us to indicate for each custom configuration, if the build logic “Debug” or “Release” must be applied.
The steps detailed below describe how to fix it:
- Open the VS2017 solution that contains the project “docker-compose” with custom configurations.
- In the “Solution Explorer” panel, right-click on the project “docker-compose” and select “Unload Project”. The project will show up in the “Solution Explorer” panel as “docker-compose (unavailable)”
- Again, in the “Solution Explorer” panel, right-click on the project “docker-compose (unavailable)” and select “Edit docker-compose.dcproj”. The file “docker-compose.dcproj” will open in VS2017.
- Inside the file “docker-compose.dcproj” search the element <PropertyGroup Label=”Globals”> and then from its last label (</PropertyGroup>) add the following element “PropertyGroup”:
<DockerDevelopmentMode Condition=” ‘$(Configuration)’ == ‘DebugCD‘
<DockerDevelopmentMode Condition=” ‘$(Configuration)’ == ‘DebugCM‘
<DockerDevelopmentMode Condition=” ‘$(Configuration)’ == ‘ReleaseCD‘
<DockerDevelopmentMode Condition=” ‘$(Configuration)’ == ‘ReleaseCM‘
- Note that there is a sub-element “DockerDevelopmentMode” for each configuration of the solution. The names used in the attribute “Condition” must match each configuration. There must be an element “DockerDevelopmentMode” for each configuration of the solution.
- The values of the nodes “DockerDevelopmentMode” indicate how each configuration must be treated:
- Fast: Debug
- Once modified, the file “docker-compose.dcproj” must be saved and closed in VS2017.
- Finally, in the “Solution Explorer” panel, right-click on the project “docker-compose (unavailable) and select “Reload Project”.
Hope this can help someone else. If yes, please let me know by leaving a comment. Thanks!