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
title: Create item templates with Export Template Wizard
3
-
description: Use the Export Template Wizard to create an item template in Visual Studio, and enable the template to be used in a Universal Windows App project.
4
-
ms.date: 05/20/2024
2
+
title: Create item templates
3
+
description: Learn how to create, edit, and use item templates in Visual Studio projects.
4
+
ms.date: 04/11/2025
5
5
ms.topic: how-to
6
6
helpviewer_keywords:
7
7
- item templates [Visual Studio], creating
8
8
author: ghogen
9
9
ms.author: ghogen
10
10
manager: mijacobs
11
11
ms.subservice: general-ide
12
+
13
+
#customer intent: As a developer, I want to create and use item templates in Visual Studio, so I can easily reuse project items in other projects.
12
14
---
13
15
# Create item templates
14
16
15
-
This article shows you how to create an item template by using the **Export Template Wizard**. If your template will consist of multiple files, see [How to: Create multi-file item templates](../ide/how-to-create-multi-file-item-templates.md).
17
+
This article shows you how to create an item template by using the **Export Template Wizard** or manually, and how to edit and use item templates. If your template consists of multiple files, also see [How to: Create multi-file item templates](how-to-create-multi-file-item-templates.md).
16
18
17
-
## Add an item template to the Add New Item dialog box
19
+
## Add an item template
18
20
19
21
1. Create or open a project in Visual Studio.
22
+
1. Select **Project** > **Add New Item** or press **Ctrl**+**Shift**+**A**.
23
+
1. In the **Add New Item** dialog box, select an item and then select **Add** to add it to the project.
24
+
1. Modify the item as desired, and indicate where in the item, if anywhere, parameter replacement should take place. For more information, see [How to: Substitute parameters in a template](how-to-substitute-parameters-in-a-template.md).
1. On the **Choose Template Type** page, choose **Item Template**, select the project that contains the item, and then select **Next**.
28
+
1. On the **Select Item To Export** page, choose the item you want to create a template for, and then select **Next**.
29
+
1. On the **Select Item References** page, select any assembly references to include in the template, and then select **Next**.
30
+
1. On the **Select Template Options** page:
20
31
21
-
1. Add an item to the project, and modify it if you want to.
22
-
23
-
1. Modify the code file to indicate where parameter replacement should take place. For more information, see [How to: Substitute parameters in a template](../ide/how-to-substitute-parameters-in-a-template.md).
24
-
25
-
1. On the **Project** menu, choose **Export Template**.
32
+
- Enter the template name and optional description, icon image, and preview image.
26
33
27
-
1. On the **Choose Template Type** page, choose **Item Template**, select the project that contains the item, and then choose **Next**.
34
+
Icon files for items are *.ico* files, as described in [Images and icons for Visual Studio](../extensibility/ux-guidelines/images-and-icons-for-visual-studio.md#file-types). The preview image is a 200 x 200 image that appears in the **Add New Item** dialog box. You can download the [Visual Studio image library](https://www.microsoft.com/download/details.aspx?id=35825) to get icons consistent with Visual Studio style.
28
35
29
-
1. On the **Select Item To Export** page, choose the item you want to create a template for, and then choose **Next**.
36
+
-Select whether to **Automatically import the template into Visual Studio** and **Display an explorer window in the output files folder**.
30
37
31
-
1.On the **Select Item References** page, select the assembly references to include in the template, and then choose **Next**.
38
+
1. Select **Finish**.
32
39
33
-
1. On the **Select Template Options** page, enter the template name and optional description, icon image and preview image, and then choose **Finish**. Icon files for items are `.ico` files, as described in [Images and icons for Visual Studio - file types](../extensibility/ux-guidelines/images-and-icons-for-visual-studio.md#file-types). The preview image is a 200 x 200 image that will appear in the **Add New Item** dialog box.
40
+
The template files are compressed into a *.zip* file and copied to the directory shown in the wizard under **Output location**. The default location is *%USERPROFILE%\Documents\Visual Studio \<version\>\My Exported Templates*.
34
41
35
-
You can look in the [Visual Studio image library](../designers/the-visual-studio-image-library.md) for icons consistent with the Visual Studio style.
42
+
If you selected **Automatically import the template into Visual Studio**, the *.zip* file is also added to the user *ItemTemplates* directory. The default location is *%USERPROFILE%\Documents\Visual Studio \<version\>\Templates\ItemTemplates*.
36
43
37
-
The files for the template are added to a *.zip* file and copied to the directory you specified in the wizard. The default location is *%USERPROFILE%\Documents\Visual Studio \<version\>\My Exported Templates*.
44
+
You can now use the item template in your projects.
38
45
39
-
1. If you did not select the option **Automatically import the template into Visual Studio** in the **Export Template Wizard**, locate the exported template. Then, copy it to the user item template directory. The default location is *%USERPROFILE%\Documents\Visual Studio \<version\>\Templates\ItemTemplates*.
46
+
## Use the item template
40
47
48
+
1. If you didn't select **Automatically import the template into Visual Studio** when you created the template, copy the *.zip* file to your *ItemTemplates* directory. The default location is *%USERPROFILE%\Documents\Visual Studio \<version\>\Templates\ItemTemplates*.
41
49
1. Close Visual Studio and then reopen it.
50
+
1. Create a new project, or open an existing project, and select **Project** > **Add New Item**
51
+
1. Select the item template from the **Add New Item** dialog box. If you added a description in the **Export Template Wizard**, the description appears on the right side of the dialog box.
52
+
1. Select **Add** to add the template item to your project.
42
53
43
-
1. Create a new project, or open an existing project, and then choose **Project** > **Add New Item** or press **Ctrl**+**Shift**+**A**.
44
-
45
-
The item template appears in the **Add New Item** dialog box. If you added a description in the **Export Template Wizard**, the description appears on the right side of the dialog box.
46
-
47
-
## Enable the item template to be used in a Universal Windows App project
48
-
49
-
The wizard does much of the work to create a basic template, but in many cases you need to manually modify the *.vstemplate* file after you have exported the template. For example, if you want the item to appear in the **Add New Item** dialog for a Universal Windows App project, you have to perform a few extra steps.
50
-
51
-
1. Follow the steps in the previous section to export an item template.
52
-
53
-
1. Extract the *.zip* file that was created, and open the *.vstemplate* file in Visual Studio.
54
-
55
-
1. For a C# Universal Windows project, add the following XML inside the `<TemplateData>` element:
56
-
57
-
```xml
58
-
<TemplateID>Microsoft.CSharp.Class</TemplateID>
59
-
```
60
-
61
-
1. In Visual Studio, save the *.vstemplate* file and close it.
62
-
63
-
1. Copy and paste the *.vstemplate* file back to the *.zip* file.
54
+
## Edit the .vstemplate file
64
55
65
-
If the **Copy File** dialog box appears, choose the **Copy and Replace**option.
56
+
The wizard creates a basic template, but in some cases you need to manually modify the *.vstemplate* file after you export the template. For example, if you want the item to appear in the **Add New Item**dialog for a Universal Windows App project, you must edit the *.vstemplate* file.
66
57
67
-
You can now add an item based on this template to a Universal Windows project from the **Add New Item** dialog box.
58
+
1. Extract the exported item template *.zip* file, and open the *.vstemplate* file in Visual Studio.
59
+
1. Edit the file as needed. For a C# Universal Windows project, add `<TemplateID>Microsoft.CSharp.Class</TemplateID>` inside the `<TemplateData>` element.
60
+
1. Save and close the *.vstemplate* file, and replace it in the *.zip* file.
68
61
69
-
## Enable templates for specific project subtypes
62
+
###Enable templates for specific project subtypes
70
63
71
-
You can specify that your template should only appear for only certain project subtypes, such as Windows, Office, Database, or Web.
64
+
You can edit the *.vstemplate* file to specify that your item template appears only for certain project subtypes, such as Windows, Office, Database, or Web.
72
65
73
-
1. Locate the `ProjectType` element in the *.vstemplate* file for the item template.
66
+
1. Open the *.vstemplate* file for editing.
67
+
1. Add a [ProjectSubType](../extensibility/projectsubtype-element-visual-studio-templates.md) element immediately after the `ProjectType` element, with value `Windows`, `Office`, `Database`, or `Web`. For example: `<ProjectSubType>Database</ProjectSubType>`.
74
68
75
-
1. Add a [ProjectSubType](../extensibility/projectsubtype-element-visual-studio-templates.md) element immediately after the `ProjectType` element.
76
-
77
-
1. Set the text value of the element to one of the following values:
78
-
79
-
- Windows
80
-
- Office
81
-
- Database
82
-
- Web
83
-
84
-
For example: `<ProjectSubType>Database</ProjectSubType>`.
85
-
86
-
The following example shows an item template for **Office** projects.
69
+
The following example shows a *.vstemplate* file for `Office` projects.
@@ -103,26 +86,19 @@ The following example shows an item template for **Office** projects.
103
86
104
87
## Manually create an item template
105
88
106
-
In some cases you may want to create an item template manually, from scratch.
107
-
108
-
1. Create a project and project item.
109
-
110
-
2. Modify the project item until it is ready to be saved as a template.
111
-
112
-
3. Modify the code file to indicate where parameter replacement should occur, if anywhere. For more information about parameter replacement, see [How to: Substitute parameters in a template.](../ide/how-to-substitute-parameters-in-a-template.md)
113
-
114
-
4. Create an XML file and save it with a *.vstemplate* file extension in the same directory as your project item file.
115
-
116
-
5. Edit the *.vstemplate* XML file to provide item template metadata. For more information, see [Template schema reference (extensibility)](../extensibility/visual-studio-template-schema-reference.md) and the example in the previous section.
117
-
118
-
6. Save the *.vstemplate* file and close it.
119
-
120
-
7. In **Windows Explorer**, select the files you want to include in your template. Right-click the selection, and choose **Send to** > **Compressed (zipped) folder**. The files that you selected are compressed into a *.zip* file.
89
+
Instead of using the wizard, you can create an item template manually from scratch.
121
90
122
-
8. Copy the *.zip* file and paste it in the user item template location. The default directory is *%USERPROFILE%\Documents\Visual Studio 2022\Templates\ItemTemplates*. For more information, see [How to: Locate and organize project and item templates](../ide/how-to-locate-and-organize-project-and-item-templates.md).
91
+
1. Create a project and add an item.
92
+
1. Modify the item as desired, such as adding where any parameter replacement should take place, and save the item.
93
+
1. Create an XML file and save it with a *.vstemplate* file extension in the same directory as your project item file.
94
+
1. Add item template metadata to the *.vstemplate* XML file, as shown in the preceding example. For more information, see [Template schema reference (extensibility)](../extensibility/visual-studio-template-schema-reference.md).
95
+
1. Save and close the *.vstemplate* file.
96
+
1. In Windows Explorer, select the files you want to include in your template, including the *.vstemplate* file. Right-click the selection and select **Compress to** > **ZIP File**.
97
+
1. Copy the resulting *.zip* file and paste it in the Visual Studio user item template location. The default directory is *%USERPROFILE%\Documents\Visual Studio \<version>\Templates\ItemTemplates*.
123
98
124
99
## Related content
125
100
126
-
-[Create project and item templates](../ide/creating-project-and-item-templates.md)
127
-
-[How to: Create multi-file item templates](../ide/how-to-create-multi-file-item-templates.md)
101
+
-[Locate and organize project and item templates](how-to-locate-and-organize-project-and-item-templates.md)
102
+
-[Create project and item templates](creating-project-and-item-templates.md)
Copy file name to clipboardExpand all lines: docs/msbuild/errors/msb3021.md
+18-8Lines changed: 18 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
-
title: "MSB3021: Unable to copy file 'source' to 'destination'."
3
-
description: "This error occurs when an error occurred when trying to copy a file."
4
-
ms.date: "08/15/2022"
2
+
title: MSB3021 diagnostic code
3
+
description: Learn about the possible causes of the MSB3021 build error and get troubleshooting tips.
4
+
ms.date: 04/14/2025
5
5
ms.topic: "error-reference"
6
6
f1_keywords:
7
7
- MSB3021
@@ -18,12 +18,22 @@ ms.subservice: msbuild
18
18
---
19
19
# MSB3021
20
20
21
+
This article describes the MSB3021 error code.
22
+
23
+
## Message text
24
+
25
+
`Unable to copy file 'source' to 'destination'.`
26
+
27
+
## Description
28
+
21
29
This diagnostic code is emitted when an error occurs when trying to copy a file. The error text from the operating system is displayed, which usually provides specific information about the failure.
22
30
23
-
The message resembles the following, but this text is followed by additional information from the operating system:
31
+
## Resolution
32
+
33
+
The standard output message text is followed by additional information from the operating system. Look to the additional information provided to determine the cause of the problem.
34
+
35
+
Common causes include the file is locked by another process, insufficient permissions to write to the destination folder, insufficient space on the drive, and so on. Make sure the file is not in use, that MSBuild has write permissions on the destination folder, and that there is sufficient space on the disk.
24
36
25
-
```output
26
-
MSB3021: Unable to copy file 'source' to 'destination'.
27
-
```
37
+
## Applies to
28
38
29
-
Look to the additional information provided by the operating system to determine the cause of the problem. Common causes include the file is locked by another process, insufficient permissions to write to the destination folder, insufficient space on the drive, and so on. Make sure the file is not in use, that MSBuild has write permissions on the destination folder, and that there is sufficient space on the disk.
Copy file name to clipboardExpand all lines: docs/msbuild/errors/msb3026.md
+16-8Lines changed: 16 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
-
title: "MSB3026: Could not copy 'source' to 'destination'. Beginning retry 'count' in 'milliseconds'."
3
-
description: "This diagnostic code is emitted when MSBuild tries multiple times to copy a file."
4
-
ms.date: "08/15/2022"
2
+
title: MSB3026 diagnostic code
3
+
description: Learn about the possible causes of the MSB3026 build error and get troubleshooting tips.
4
+
ms.date: 04/14/2025
5
5
ms.topic: "error-reference"
6
6
f1_keywords:
7
7
- MSB3026
@@ -18,12 +18,20 @@ ms.subservice: msbuild
18
18
---
19
19
# MSB3026
20
20
21
+
This article describes the MSB3026 error code.
22
+
23
+
## Message text
24
+
25
+
`Could not copy 'source' to 'destination'. Beginning retry 'count' in 'milliseconds'.`
26
+
27
+
## Description
28
+
21
29
This diagnostic code is emitted when MSBuild tries multiple times to copy a file.
22
30
23
-
The message resembles the following, but this text is followed by additional information from the operating system:
31
+
## Resolution
32
+
33
+
The standard output message text is followed by additional information from the operating system. Look to the additional information provided to determine the cause of the problem.
24
34
25
-
```output
26
-
MSB3026: Could not copy 'source' to 'destination'. Beginning retry 'count' in 'milliseconds'.
27
-
```
35
+
## Applies to
28
36
29
-
Look to the additional information provided by the operating system to determine the cause of the problem.
Copy file name to clipboardExpand all lines: docs/msbuild/errors/msb3027.md
+21-5Lines changed: 21 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
-
title: "MSB3027: Could not copy 'source' to 'destination'. Exceeded retry count of 'number'. Failed."
3
-
description: "This error occurs when MSBuild tries to copy a file repeatedly and fails when the limit of the number of retries is reached."
4
-
ms.date: "07/07/2021"
2
+
title: MSB3027 diagnostic code
3
+
description: Learn about the possible causes of the MSB3027 build error and get troubleshooting tips.
4
+
ms.date: 04/14/2025
5
5
ms.topic: "error-reference"
6
6
f1_keywords:
7
7
- MSB3027
@@ -16,8 +16,24 @@ ms.author: ghogen
16
16
manager: mijacobs
17
17
ms.subservice: msbuild
18
18
---
19
-
# MSB3027: Could not copy 'source' to 'dest'. Exceeded retry count of 'number'. Failed
19
+
# MSB3027
20
20
21
-
This error occurs when MSBuild tries to copy a file repeatedly and fails when the limit of the number of retries is reached. Look to the additional error text for any error from the operating system that indicates what the problem might be.
21
+
This article describes the MSB3027 error code.
22
+
23
+
## Message text
24
+
25
+
`Could not copy 'source' to 'dest'. Exceeded retry count of 'number'. Failed`
26
+
27
+
## Description
28
+
29
+
This error occurs when MSBuild tries to copy a file repeatedly and fails when the limit of the number of retries is reached.
30
+
31
+
## Resolution
32
+
33
+
The standard output message text is followed by additional information from the operating system. Look to the additional information provided to determine the cause of the problem.
22
34
23
35
Typical causes include the destination file is in use by another program, the permissions to not allow writing to the destination file, not enough space on the drive, or the network drive is not available due to a network or permissions error.
Copy file name to clipboardExpand all lines: docs/msbuild/errors/msb3041.md
+15-8Lines changed: 15 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
-
title: "MSB3041: Unable to create a manifest resource name for 'resource'."
3
-
description: "This error occurs when MSBuild is unable to create a manifest resource name for the specified resource."
4
-
ms.date: "08/15/2022"
2
+
title: MSB3041 diagnostic code
3
+
description: Learn about the possible causes of the MSB3041 build error and get troubleshooting tips.
4
+
ms.date: 04/14/2025
5
5
ms.topic: "error-reference"
6
6
f1_keywords:
7
7
- MSB3041
@@ -18,13 +18,20 @@ ms.subservice: msbuild
18
18
---
19
19
# MSB3041
20
20
21
+
This article describes the MSB3041 error code.
22
+
23
+
## Message text
24
+
25
+
`Unable to create a manifest resource name for 'resource'.`
26
+
27
+
## Description
28
+
21
29
This error occurs when a manifest resource name could not be created for the specified resource.
22
30
23
-
The message resembles the following, but this text is followed by additional information from the operating system:
31
+
## Resolution
24
32
25
-
```output
26
-
MSB3041: Unable to create a manifest resource name for 'resource'.
27
-
```
33
+
The standard output message text is followed by additional information from the operating system. Look to the additional information provided to determine the cause of the problem.
28
34
29
-
Look to the additional information for the cause of the failure.
0 commit comments