Home > database >  How to stop dotnet solution template from nesting the output
How to stop dotnet solution template from nesting the output

Time:11-02

I have a Visual Studio solution in which I have a .template.config directory with a template.json file in it.

{
  "$schema": "http://json.schemastore.org/template",
  "author": "Me",
  "classifications": [ "Library" ],
  "identity": "Our.Microservice.Template",
  "name": "Our Microservice Solution Pattern",
  "shortName": "our-microservice",
  "tags": {
    "type": "solution",
    "language": "C#"
  },
  "sourceName": "Our.Microservice.Template",
  "defaultName": "Our.Services.SERVICE-NAME-HERE",
  "preferNameDirectory": false,
  "guids": [
    "dd357121-d106-45e8-99b7-324ea4b1babb",
    "5cb69290-d0c5-4edc-ba1d-0b4b4f619157",
    "cb79b212-29fc-44c6-a9a7-bb96b2327fd9"
  ]
}

I also have a SolutionTemplate.nuspec in the root directory of the solution.

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
  <metadata>
    <id>Our.Microservice.Template</id>
    <version>1.0.0</version>
    <description>
      Blah blah blah.
    </description>
    <authors>Me</authors>
    <license type="expression">Apache-2.0</license>
    <packageTypes>
      <packageType name="Template" />
    </packageTypes>
  </metadata>
  <files>
    <file src="**\*.*"             exclude="**\bin\**\*.*;**\obj\**\*.*;**\*.nuspec;**\*.nupkg;**\*.suo;docs\**;.git\**;**\.gitignore;.vs\**;.vscode\**;" 
             />
  </files>  
</package>

I've been packing the the template up with:

nuget.exe pack "<path-to-dir>\SolutionTemplate.nuspec"

And then installing with:

dotnet new --install "<path-to-dir>\Our.Microservice.Template.1.0.0.nupkg"

This works, but when I create a new solution from the template, the output gets nested in an extra directory e.g.

If in the creation dialogs in VS I chose the location as c:\development\existing-git-repo then the eventual output would be

c:
    \development
        \existing-git-repo
            \PROJECT-NAME
                \dir-1
                \dir-2
                \file-1
                \file-2

Is there a way to stop it from nesting the output in the extra directory (based on the project name)?

So the result would be:

c:
    \development
        \existing-git-repo
            \dir-1
            \dir-2
            \file-1
            \file-2

CodePudding user response:

In the end, the best (and only) way I found to stop the extra nesting was to make sure I create new solutions using the command line rather than via Visual Studio.

If we use dotnet new, we can use the output option:

dotnet new --help
...
-o, --output                   Location to place the generated output.

If we set this to ./ then this stops the extra nesting e.g.:

dotnet new mvc -n MyMvcApp -o ./
  • Related