How to add .dcproj into solution via dotnet sdk

9.5k views Asked by At

I have a solution named: MyProject.sln and project related to docker called - docker-compose.dcproj.

I want to create dotnet new template which will contain support for docker-compose through project docker-compose.dcproj.

I tried this command:

dotnet sln MyProject.sln add docker-compose.dcproj

I got this error message:

Project 'C:\MyProject\docker-compose.dcproj' has an unknown project type and cannot be added to the solution file. Contact your SDK provider for support.

I am using .net core sdk version 3.1.100.

How to add docker-compose.dcproj into solution via command above?

2

There are 2 answers

0
Ziaullah Khan On

I was able to get it to working at least two ways.

1. Visual Studio

I created a .net framework project. Right clicked on Project. Add > Docker Support. I moved

  1. docker-compose.dcproj
  2. docker-compose.override.yml
  3. docker-compose.yml

to a .NET Core project folder.

Select Added new project and picked up this dcproj file. With a few edits to the compose file. I was able to get it to working.

2. When you don't have visual studio.

I see the mentioned error too. Not able to add the project through cli

$ dotnet sln ConsoleApp2.sln add "docker-compose.dcproj"
Project 'C:\Code\ConsoleApp2\docker-compose.dcproj' has an unknown project type and cannot be added to the solution file. Contact your SDK provider for support.

I modified the sln file text as below.

$ type docker-compose.dcproj

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
  <PropertyGroup Label="Globals">
    <ProjectVersion>2.1</ProjectVersion>
    <DockerTargetOS>Windows</DockerTargetOS>
    <ProjectGuid>9c31f76d-0249-4004-9b65-d5fa07cf95f8</ProjectGuid>
  </PropertyGroup>
  <ItemGroup>
    <None Include="docker-compose.override.yml">
      <DependentUpon>docker-compose.yml</DependentUpon>
    </None>
    <None Include="docker-compose.yml" />
  </ItemGroup>
</Project>

Add below two lines above Global in the solution file.

Project("{Any GUID}") = "docker-compose", "docker-compose.dcproj", "{<ProjectGuid> from above output}"
EndProject

Please do not mess up the file format. Be very careful. Save a copy of solution file before you attempt any of this. Good luck.

0
yala_cat On

You can overcome this issue using VS, Refer the image below. This will generate the docker-compose.yml file in the root of the solution.

enter image description here