You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/tutorials/cli-templates-create-template-package.md
+25-10Lines changed: 25 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,27 +35,28 @@ In this part of the series you'll learn how to:
35
35
36
36
A template package is one or more templates packed into a NuGet package. When you install or uninstall a template package, all templates contained in the package are added or removed, respectively.
37
37
38
-
Template packages are represented by a NuGet package (_.nupkg_) file. And, like any NuGet package, you can upload the template package to a NuGet feed. The `dotnet new install` command supports installing template packages from a NuGet package feed. Additionally, you can install a template package from a _.nupkg_ file directly.
38
+
Template packages are represented by a NuGet package (_.nupkg_) file. And, like any NuGet package, you can upload the template package to a NuGet feed. The `dotnet new install`[command](../tools/dotnet-new-install.md) supports installing template packages from a NuGet package feed. Additionally, you can install a template package from a _.nupkg_ file directly.
39
39
40
40
Normally you use a C# project file to compile code and produce a binary. However, the project can also be used to generate a template package. By changing the settings of the _.csproj_, you can prevent it from compiling any code and instead include all the assets of your templates as resources. When this project is built, it produces a template package NuGet package.
41
41
42
42
The package you are going to generate will include the [item template](cli-templates-create-item-template.md) and [package template](cli-templates-create-project-template.md) previously created.
43
43
44
+
In order to create the template package, we will use the template for the template package provided by [Microsoft.TemplateEngine.Authoring.Templates](https://www.nuget.org/packages/Microsoft.TemplateEngine.Authoring.Templates).
44
45
In your terminal, run the command:
45
46
46
47
```dotnetcli
47
48
dotnet new install Microsoft.TemplateEngine.Authoring.Templates
48
49
```
49
50
50
-
This [template package](https://github.com/dotnet/templating/tree/main/template_feed/Microsoft.TemplateEngine.Authoring.Templates) contains templates useful for template authoring.
51
+
This [template package](https://www.nuget.org/packages/Microsoft.TemplateEngine.Authoring.Templates) contains templates useful for template authoring. Note: nuget.org should be available as NuGet feed inside the working directory to install this template package.
51
52
52
53
Navigate to the _working_ folder and run:
53
54
54
55
```dotnetcli
55
-
dotnet new templatepack --name "templatepack"
56
+
dotnet new templatepack --name "AdatumCorporation.Utility.Templates"
56
57
```
57
58
58
-
The `--name` parameter sets the _.csproj_ filename to _templatepack.csproj_. You should see a result similar to the following output.
59
+
The `--name` parameter sets the _.csproj_ filename to AdatumCorporation.Utility.Templates.csproj_. You should see a result similar to the following output.
59
60
60
61
```console
61
62
The template "Template Package" was created successfully.
Manual instructions: Open *.csproj in the editor and complete the package metadata configuration. Copy the templates to 'content' folder. Fill in README.md.
66
67
```
67
68
68
-
Next, open the _templatepack.csproj_ file in a code editor and populate it according to the hints in the template:
69
+
Next, open the _AdatumCorporation.Utility.Templates.csproj_ file in a code editor and populate it according to the hints in the template:
69
70
70
71
```xml
71
72
<PropertyGroup>
@@ -81,15 +82,29 @@ Next, open the _templatepack.csproj_ file in a code editor and populate it accor
81
82
</PropertyGroup>
82
83
```
83
84
84
-
For getting more information about content of _templatepack.csproj_ file, navigate to [Pack a template into a NuGet package (nupkg file)](https://learn.microsoft.com/dotnet/core/tools/custom-templates#pack-a-template-into-a-nuget-package-nupkg-file).
85
+
For getting more information about NuGet package metadata available in _AdatumCorporation.Utility.Templates.csproj_ file, navigate to [Pack a template into a NuGet package (nupkg file)](https://learn.microsoft.com/dotnet/core/tools/custom-templates#pack-a-template-into-a-nuget-package-nupkg-file).
86
+
87
+
By default, the created project file includes [template authoring MSBuild tasks](https://aka.ms/templating-authoring-tools).
Those MSBuild tasks provide template validation and [localization of the templates](https://aka.ms/templating-localization) capabilities. The localization is disabled by default, to enable creation of localization files, set `LocalizeTemplates` to `true`.
85
100
86
101
## Build and install
87
102
88
-
Save changes in _templatepack.csproj_ file. Before building the template package, verify that your folder structure is correct. Any custom template should be placed in the _content_ folder, in its own folder. The hierarchy should look similar to:
103
+
Save changes in _AdatumCorporation.Utility.Templates.csproj_ file. Before building the template package, verify that your folder structure is correct. Any custom template should be placed in the _content_ folder, in its own folder. The hierarchy should look similar to:
89
104
90
105
```console
91
106
working
92
-
│ templatepack.csproj
107
+
│ AdatumCorporation.Utility.Templates.csproj
93
108
└───content
94
109
├───extensions
95
110
│ └───.template.config
@@ -109,9 +124,9 @@ C:\working> dotnet pack
109
124
Microsoft (R) Build Engine version 16.8.0+126527ff1 for .NET
110
125
Copyright (C) Microsoft Corporation. All rights reserved.
111
126
112
-
Restore completed in 123.86 ms for C:\working\templatepack.csproj.
127
+
Restore completed in 123.86 ms for C:\working\AdatumCorporation.Utility.Templates.csproj.
0 commit comments