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
+1-90Lines changed: 1 addition & 90 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,6 @@ title: Create a template package for dotnet new
3
3
description: Learn how to create a csproj file that builds a template package for the dotnet new command.
4
4
author: adegeo
5
5
ms.date: 09/11/2023
6
-
zone_pivot_groups: dotnet-version
7
6
ms.topic: tutorial
8
7
ms.author: adegeo
9
8
---
@@ -16,27 +15,12 @@ You can view the completed template in the [.NET Samples GitHub repository](http
16
15
17
16
In this part of the series you'll learn how to:
18
17
19
-
::: zone pivot="dotnet-9-0,dotnet-8-0"
20
-
21
18
> [!div class="checklist"]
22
19
>
23
20
> * Create a template package by using the [Microsoft.TemplateEngine.Authoring.Templates](https://www.nuget.org/packages/Microsoft.TemplateEngine.Authoring.Templates) NuGet package.
24
21
> * Install a template package from a NuGet package file.
25
22
> * Uninstall a template package by package ID.
26
23
27
-
::: zone-end
28
-
29
-
::: zone pivot="dotnet-7-0,dotnet-6-0"
30
-
31
-
> [!div class="checklist"]
32
-
>
33
-
> * Create a \*.csproj project to build a template package.
34
-
> * Configure the project file for packing.
35
-
> * Install a template package from a NuGet package file.
36
-
> * Uninstall a template package by package ID.
37
-
38
-
::: zone-end
39
-
40
24
## Prerequisites
41
25
42
26
* Complete [part 1](cli-templates-create-item-template.md) and [part 2](cli-templates-create-project-template.md) of this tutorial series.
@@ -45,21 +29,11 @@ In this part of the series you'll learn how to:
45
29
46
30
* Open a terminal and navigate to the _working_ folder.
47
31
48
-
::: zone pivot="dotnet-8-0"
49
-
50
-
* Install .NET 8.
32
+
* Install .NET 8 or .NET 9.
51
33
* Install the `Microsoft.TemplateEngine.Authoring.Templates` template from the NuGet package feed.
52
34
53
35
* Run the `dotnet new install Microsoft.TemplateEngine.Authoring.Templates` command from your terminal.
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.
@@ -70,8 +44,6 @@ Normally you use a C# project file to compile code and produce a binary. However
70
44
71
45
The package you're going to generate will include the [item](cli-templates-create-item-template.md) and [project](cli-templates-create-project-template.md) templates previously created.
72
46
73
-
::: zone pivot="dotnet-8-0"
74
-
75
47
The [Microsoft.TemplateEngine.Authoring.Templates](https://www.nuget.org/packages/Microsoft.TemplateEngine.Authoring.Templates) package contains templates useful for template authoring. To install this package, nuget.org should be available as NuGet feed in the working directory.
76
48
77
49
01. In the _working_ folder, run the following command to create the template package:
@@ -116,63 +88,6 @@ The [Microsoft.TemplateEngine.Authoring.Templates](https://www.nuget.org/package
116
88
... cut for brevity ...
117
89
```
118
90
119
-
::: zone-end
120
-
121
-
::: zone pivot="dotnet-7-0,dotnet-6-0"
122
-
123
-
01. In the _working_ folder, run the following command to create the template package:
124
-
125
-
```dotnetcli
126
-
dotnet new console -n AdatumCorporation.Utility.Templates
127
-
```
128
-
129
-
The `-n` parameter sets the project file name to _AdatumCorporation.Utility.Templates.csproj_. You should see a result similar to the following output.
130
-
131
-
```output
132
-
The template "Console Application" was created successfully.
133
-
134
-
Processing post-creation actions...
135
-
Running 'dotnet restore' on .\AdatumCorporation.Utility.Templates.csproj...
136
-
Restore completed in 52.38 ms for C:\code\working\AdatumCorporation.Utility.Templates.csproj.
137
-
138
-
Restore succeeded.
139
-
```
140
-
141
-
01. Delete the _Program.cs_ file. The new project template generates this file but it's not used by the templates engine.
142
-
143
-
01. Next, open the _AdatumCorporation.Utility.Templates.csproj_ file in your favorite editor and replace the content with the following XML:
The settings under `<PropertyGroup>` in the XML snippet are broken into two groups.
@@ -193,8 +108,6 @@ In the second group, the `<TargetFramework>` setting ensures that MSBuild runs p
193
108
> [!TIP]
194
109
> For more information about NuGet metadata settings, see [Pack a template into a NuGet package (nupkg file)](../tools/custom-templates.md#pack-a-template-into-a-nuget-package-nupkg-file).
195
110
196
-
::: zone pivot="dotnet-8-0"
197
-
198
111
The created project file includes [template authoring MSBuild tasks](https://aka.ms/templating-authoring-tools) and localization settings.
199
112
200
113
```xml
@@ -212,8 +125,6 @@ The created project file includes [template authoring MSBuild tasks](https://aka
212
125
213
126
These MSBuild tasks provide template validation and [localization of the templates](https://aka.ms/templating-localization) capabilities. Localization is disabled by default. To enable creation of localization files, set `LocalizeTemplates` to `true`.
214
127
215
-
::: zone-end
216
-
217
128
## Pack and install
218
129
219
130
Save the project file. Before building the template package, verify that your folder structure is correct. Any template you want to pack should be placed in the _templates_ folder, in its own folder. The folder structure should look similar to the following hierarchy:
0 commit comments