自定义 ItemTemplate 未出现在 Visual Studio 2015 的“添加新项目"对话框中 [英] Custom ItemTemplate does not appear in Visual Studio 2015 Add New Item dialog

查看:31
本文介绍了自定义 ItemTemplate 未出现在 Visual Studio 2015 的“添加新项目"对话框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经查看了这个问题 并没有解决我的问题.

I have viewed this question and it did not solve my problem.

我正在尝试在 Visual Studio 2015 中创建一个新的 ItemTemplate.我首先在 Visual Studio 中创建模板,然后使用文件"菜单中的导出模板"选项.

I'm attempting to create a new ItemTemplate in Visual Studio 2015. I started out by creating the template in Visual Studio, then using the Export Template option from the File menu.

我从导出模板向导中选择了项目模板",选择了我的项目,并选择了用作模板的文件.我填写了模板选项,然后单击完成",选中自动将模板导入 Visual Studio"和在输出文件文件夹上显示资源管理器窗口".

I selected "Item template" from the Export Template Wizard, chose my project, and selected the file that would serve as the template. I filled out the template options, and clicked "Finish" with "Automatically import the template into Visual Studio" and "Display an explorer window on the output files folder" checked.

打开的资源管理器窗口显示了我在 zip 存档中的模板.我导航到 %My Documents%\Visual Studio 2015\Templates\ItemTemplates 并发现 zip 存档也在该文件夹中.

The explorer window that opened showed my template in a zip archive. I navigated to %My Documents%\Visual Studio 2015\Templates\ItemTemplates and found the zip archive was also in that folder.

然后我转到添加新项目"对话框,但在任何类别或主要 Visual C# 项目类别中都找不到我的模板.

I then went to Add New Item dialog, but could not find my template listed in any category, or the main Visual C# Items category.

我解压了存档文件,发现其中包含的文件如下:

I unzipped the archived and found the following for the files included within:

MyTemplate.vstemplate

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
  <TemplateData>
    <DefaultName>MyTemplate.cs</DefaultName>
    <Name>MyTemplate</Name>
    <Description>MyTemplate</Description>
    <ProjectType>CSharp</ProjectType>
    <SortOrder>10</SortOrder>
    <Icon>__TemplateIcon.ico</Icon>
  </TemplateData>
  <TemplateContent>
    <References />
    <ProjectItem SubType="" TargetFileName="$fileinputname$.cs" ReplaceParameters="true">Template.cs</ProjectItem>
  </TemplateContent>
</VSTemplate>

Template.cs

using System;
using System.Linq;

namespace $rootnamespace$
{
    public partial class $safeitemname$
    {
        public void $safeitemname$()
        {
            throw new NotImplementedException();
        }
    }
}

我的尝试

我尝试以管理员身份打开 VS2015 的开发人员命令提示符并输入以下命令(不是一个接一个):

What I've Tried

I've tried opening a Developer Command Prompt for VS2015 as an administrator and entering the following commands (not one after the other):

devenv /installvstemplates
devenv /setup
devenv /resetsettings

我多次尝试重新启动我的电脑和 Visual Studio 实例.

I've tried restarting my PC and Visual Studio instance multiple times.

我尝试手动清除缓存文件夹并重建它们(尽管据我所知它们与自定义 ItemTemplates 无关).

I've tried manually clearing the cache folders and rebuilding them (despite the fact that they have nothing to do with custom ItemTemplates as far as I can tell).

正如我在此处此处此处,它应该简单地从 %My Documents%\Visual Studio 2015\Templates\ItemTemplates 甚至不需要关闭 Visual Studio.

As I've read here, here, and here, it should simply read from the %My Documents%\Visual Studio 2015\Templates\ItemTemplates automatically without even needing to close Visual Studio.

我已经检查了我的 工具 >选项 >用户项目模板位置的项目和解决方案路径,它是正确的.我什至将它粘贴到资源管理器窗口地址栏中以确保.

I've checked my Tools > Options > Projects and Solutions paths for User item templates locations and it is correct. I even pasted it into the explorer window address bar to be sure.

我尝试将 .zip 存档放在 ItemTemplates 文件夹的各个子级别.

I've tried placing the .zip archive at various sub levels of the ItemTemplates folder.

我尝试将 .zip 存档放在旧版本的 VS ItemTemplates 文件夹中.

I've tried placing the .zip archive in older versions of VS ItemTemplates folders.

我已经用尽了我能找到的所有 MSDN 文章和博客.它们似乎都表明我尝试过的步骤应该已经奏效了.

I have exhausted every MSDN article and blog I could find. They all seem to indicate that the steps I have tried should've already worked.

我还能做什么?有没有其他人遇到并解决过这个问题?

What else can I do? Has anyone else encountered and solved this problem?

如果有任何其他信息可以帮助解决此问题,请告诉我

我的 Visual Studio 版本是 14.0.23107.0

推荐答案

我想分享我做错了什么,以防其他人阅读了所有教程和文档,但仍然没有弄清楚.

I wanted to share what I was doing wrong just in case someone else gets through all of the tutorials and documentation out there and still hasn't figured it out.

我正在压缩在提取由 Export Template 过程生成的压缩档案时创建的文件夹.这会导致压缩存档的结构类似于:

I was zipping the folder that was created when extracting the compressed archive generated by the Export Template process. This causes the structure of the compressed archived to look something like:

MyTemplate.zip
|-MyTemplate
  |-MyTemplate.vstemplate
  |-MyCodeFile.cs
  |-MyIcon.ico

这一额外的目录层会导致 Visual Studio 无法读取模板.

This extra layer of directories causes Visual Studio not to be able to read the template.

你想要的是这样的结构:

What you want is a structure like:

MyTemplate.zip
|-MyTemplate.vstemplate
|-MyCodeFile.cs
|-MyIcon.ico

如果您使用的是 Windows 内置压缩 Send to >压缩(zipped)文件夹,然后确保选择文件本身,而不是解压缩由导出模板过程创建的存档时创建的目录.

If you are using Windows built-in compression Send to > Compressed (zipped) folder, then be sure to select the files themselves, and not the directory that is created when you decompress the archive that was created by the Export Template process.

这篇关于自定义 ItemTemplate 未出现在 Visual Studio 2015 的“添加新项目"对话框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆