.netvisual-studiotemplatesdocker-composedotnet-new

Can i use Docker Compose in dotnet template?


I am trying to create a dotnet template using dotnet new (for Visual Studio). It mostly works fine, apart from docker compose. I tried to include a docker compose project (.dcproj) just as everything else.

When using the dotnet new command, everything works fine, the solution file is generated correctly. But if i use the template within Visual Studio, the soltuion file gets changed - and the dcproj is just removed. I could not figure out any way to preserve the dcproj when working with visual studio - I also couldn't find any other templates that are using docker compose in that way. Is this possible? Why is Visual Studio doing that?

My template.json:

{
    "$schema": "http://json.schemastore.org/template",
    "author": "Me",
    "classifications": [ "Blazor" ],
    "identity": "BlazorApplication",
    "name": "Blazor Application",
    "description": "A pre-configured blazor project.",
    "shortName": "blazor",
    "sourceName":"BlazorApplication",
    "tags": {
      "language": "C#",
      "type": "project"
    }
  }

Solution

  • Found the problem: The tag "type" must be solution, otherwise Visual Studio creates a second sln file where it auto-discovers the csproj files, but not the dcproj ones.

    {
        "$schema": "http://json.schemastore.org/template",
        "author": "Me",
        "classifications": [ "Blazor" ],
        "identity": "BlazorApplication",
        "name": "Blazor Application",
        "description": "A pre-configured blazor project.",
        "shortName": "blazor",
        "sourceName":"BlazorApplication",
        "tags": {
          "language": "C#",
          "type": "solution"
        }
      }