dotnet / dotnet-template-samples

Samples showing how to create templates using the Template Engine for dotnet new and Visual Studio

Home Page:https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-new

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom Assembly Name

chelseafarley opened this issue · comments

I want to prefix my namespace with some custom namespaces e.g. Template.MyProject (where Template is automatically replaced with the project name) when created with the name Test and with parameter "namespacePrefix" being CompanyName, the project would be Test.MyProject but the namespace would be CompanyName.Test.MyProject

I have done this by having NAMESPACE_PREFIX on the front of my namespaces and default namespace. Then I replace this with a required parameter "NamespacePrefix" that my template.json accepts. e.g.

{
  "$schema": "http://json.schemastore.org/template",
  "author": "Chelsea Farley",
  "classifications": [ ".Net Core", "Web API", "Microservice" ], 
  "name": "Microservice",
  "identity": "Template.Microservice",         
  "shortName": "microservice",
  "tags": {
    "language": "C#",
    "type":"project"
  },
  "sourceName": "Template",
  "preferNameDirectory": true,
  "symbols":{
    "NamespacePrefix": {
      "type": "parameter",
      "replaces":"NAMESPACE_PREFIX",
      "isRequired": true
    }
  },
  "source":{
    "exclude": ["**/[Bb]in/**", "**/[Oo]bj/**"]
  }
}

@chelseafarley It sounds like you were able to get this figured out. Do you need any additional info?

No additional information required, thanks for your samples. They have been really helpful!

I am having one issue, but it isn't a major... When I try to exclude my .git folder it always seems to get generated anyway e.g.

"source": { "exclude": ["**/[Bb]in/**", "**/[Oo]bj/**", ".git/**"] }

@chelseafarley you shouldn't have to exclude .git. That should happen automatically. Can you file an issue at https://github.com/dotnet/templating for this? I'll close this issue down.