visual studio – C# project created in CLI with custom template returns empty folder


I’ve set up a template for a microservice that we will have to create plenty of in an upcoming project. After following all the steps, I was able to create a nupkg package. I’ve installed the template but it only generates an empty folder. All the output returns successfully, so I’m fresh out of ideas.

Here’s my template.json file:

    {
      "$schema": "http://json.schemastore.org/template",
      "author": "ME",
      "classifications": ["WebAPI", "Microservice"],
      "identity": "MicroService.Template",
      "name": "MicroserviceTemplate",
      "shortName": "microservice",
      "sourceName": "MicroserviceTemplate",
      "preferNameDirectory": true,
      "tags": {
        "language": "C#",
        "type": "project"
      },
  "symbols": {
    "PROJECT_NAME": {
      "type": "parameter",
      "defaultValue": "MyMicroService",
      "replaces": "MyMicroService"
    }
  },
      "primaryOutputs": [
      { "path": "MicroServiceTemplate.sln" },
      { "path": "MyMicroService.API/MyMicroService.API.csproj" },
      { "path": "MyMicroService.Events/MyMicroService.Events.csproj" },
      { "path": "MyMicroService.Domain/MyMicroService.Domain.csproj" },
      { "path": "MyMicroService.DataAccess/MyMicroService.DataAccess.csproj" },
      { "path": "MyMicroService.Contracts/MyMicroService.Contracts.csproj" },
      { "path": "MyMicroService.API.Tests/MyMicroService.API.Tests.csproj" },
      { "path": "MyMicroService.Events.Tests/MyMicroService.Events.Tests.csproj" },
      { "path": "MyMicroService.Domain.Tests/MyMicroService.Domain.Tests.csproj" },
      { "path": "MyMicroService.DataAccess.Tests/MyMicroService.DataAccess.Tests.csproj" }
        ]
    }

The MicroService.Template.csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <LangVersion>10.0</LangVersion>
    <PackageId>MicroService.Template</PackageId>
    <Version>1.0.0</Version>
    <Authors>Me</Authors>
    <Description>A template for microservices</Description>
    <PackageTags>template;microservice</PackageTags>
    <OutputPath>./nupkg</OutputPath>
    <IncludeSymbols>true</IncludeSymbols>
    <SymbolPackageFormat>snupkg</SymbolPackageFormat>
    <IncludeSource>true</IncludeSource>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>   
    <OutputType>Exe</OutputType>
  </PropertyGroup>

  <ItemGroup>
    <Content Include=".template.config/**" Pack="true" PackagePath="content/.template.config/" />
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
    <!-- Include other necessary files -->
  </ItemGroup>

</Project>

And an example of one of the csproj files from one project in the solution:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <OutputType>Exe</OutputType>
    <LangVersion>10.0</LangVersion>
    <RootNamespace>{{PROJECT_NAME}}.API</RootNamespace>
    <AssemblyName>{{PROJECT_NAME}}.API</AssemblyName>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>    
  </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="MediatR" Version="12.4.0" />
        <PackageReference Include="Microsoft.OpenApi" Version="1.6.17" />
        <PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.1" />
    </ItemGroup>

    <ItemGroup>
      <ProjectReference Include="..\MyMicroService.Contracts\MyMicroService.Contracts.csproj" />
      <ProjectReference Include="..\MyMicroService.Domain\MyMicroService.Domain.csproj" />
    </ItemGroup>

    <ItemGroup>
      <Folder Include="Controllers\" />
    </ItemGroup>

</Project>

Might it have something to do with the {{placeholders}} I’ve put in the project names in the csproj files? But then I would think atleast the sln file should be created.

Leave a Reply

Your email address will not be published. Required fields are marked *