6

I'm successfully creating and installing a custom project template using the pretty good instructions here. The template is installed successfully, however, when I create a new project based on this template the resulting folder contains three additional things I actually don't want to have there:

  • _rels/.rels
  • [Content_Types].xml
  • The original nuspec file

The project template was created locally as a local NuGet package. See the flow of things in the screenshots Generating and installing project template and enter image description here

Can anyone tell me how I can prevent these additional files to be part of the project that is generated from my template?

baumgarb
  • 1,955
  • 3
  • 19
  • 30

2 Answers2

3

I have faced with the same problem. Found the solution with nuspec file.

the nuspec file was like

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
  <metadata>
    <id>XYZ.Template</id>
    <version>1.0.7</version>
    <description>
      Creates the XYZ API Template
    </description>
    <authors>XYZ</authors>
    <packageTypes>
      <packageType name="Template" />
    </packageTypes>
  </metadata>
  <files>
     <file src="**"  exclude="**\bin\**\*;**\obj\**\*;**\*.user;"/>
  </files>
</package>

The problem was file src expression. The ** expression will be include those files. Move your nuspec file to one folder above. Then change the following line.

     <file src="api/**"  exclude="**\bin\**\*;**\obj\**\*;**\*.user;"/>
alim
  • 677
  • 5
  • 19
  • I moved the .nuspec file a folder above and it did not work. Also updated the nuspec file with the file src to use the new path without luck. I'm wondering if you have found any other workaround. – vhugo Jun 06 '22 at 15:59
2

You can exclude files. In your template.json:

    "sources": [
    {
      "modifiers": [
        {
          "exclude": [ "[Content_Types].xml" ,"_rels/**", "Baumgarb.Demo.DemoWebApi.nuspec"]
        }
      ]
    }
  ]

But I would put all files that are not related to your template outside the template folder.

CarlesD
  • 116
  • 6