Create multi-project dotnet templates with shared projects outside template folder

42 Views Asked by At

I'm trying to create some dotnet templates for dotnet cli using template.json. This template would contain multiple projects and some of them would be shared with other templates. So those shared projects would be outside the template folder.

Here is an example of the structure:

/Templates
  /Template1
    Template1.sln
    /.template.config
      template.json
    /Src
      /Project1
  /Template2
    Template2.sln
    /.template.config
      template.json
    /Src
      /Project1
  /SharedProject1
  /SharedProject2

I would like to include SharedProjects 1 & 2 inside both of my templates without to duplicate them directly in the template's folder

Here is my template1 template.json file

{
  "$schema": "http://json.schemastore.org/template",
  "author": "Papapinguy",
  "classifications": [ "Web", "MVC", "ASP.NET"],
  "identity": "Template.Poc",
  "name": "POC Template",
  "shortName": "pocTemplate",
  "tags": {
    "language": "C#",
    "type": "project"
  },
  "sourceName": "Template",
  "preferNameDirectory": true,
  "sources": [
    {
      "source": "../SharedProject1/",
      "target": "./Src/SharedProject1/"
    },
    {
      "source": "../SharedProject2/",
      "target": "./Src/SharedProject2/"
    }
  ],
  "primaryOutputs": [
    {
      "path": "./Src/Project1.csproj"
    },
    {
      "path": "./Src/SharedProject1.csproj"
    },
    {
      "path": "./Src/SharedProject2.csproj"
    }
  ],
  "exclude": ["**/[Bb]in/**", "**/[Oo]bj/**", ".template.config/**/*", "**/*.lock.json"]
}

When I try to install this package using

\Templates>dotnet new install Template1\ --force

I have the following exception saying that /SharedProject1 and /SharedProject2 are outside the root folder of Template1 what I can understand.

 [Error][MV012] L’emplacement source « ../Template.Domain » est en dehors de l’emplacement source d’installation spécifié.

I asked several GPTs friends and all said that it's still possible using the source/target copy or primaryOutputs tips but none worked.

So finally, is it possible ? Or do I have to change my folders structure and if so, how should I structure my templates folder to be consistent.

Thanks a lot in advance.

0

There are 0 best solutions below