VS2010 MPF:填充“添加->新项目...”自定义项目的列表
我创建了一个自定义语言包,它扩展了 ProjectPackage。我可以正确创建新项目。我希望能够使用“添加”->“新项目...”(Ctrl+Shift+A) 菜单项向项目添加新的源文件。但是,当我此时单击此按钮时,可用模板列表为空。我想将我自己的自定义模板添加到该项目类型的可用模板菜单中。有一些文档可以实现这一点吗?我见过的唯一提到的是注册表黑客攻击,但我认为必须有一种方法可以以编程方式执行此操作。
是否有我可以覆盖的特定方法来填充列表?我真的需要制作一个模板吗?或者我可以只显示“模板名称”、“图标”并提供正确的文件扩展名(创建时文件应该为空,所以我认为模板很大程度上浪费在我想要的内容上做)。
这是我迄今为止所走过的道路。我想我可以在自定义 .vproj 文件中设置项目类型和 GUID(.vproj 是我的自定义项目注册的文件扩展名)。我认为我可以快速创建一个项目模板,其项目类型与我的 .vproj 文件相同。
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
<TemplateData>
<Icon>VerilogSource.ico</Icon>
<DefaultName>module.v</DefaultName>
<Name>Basic Verilog Module</Name>
<Description>
A basic Verilog module for quickly adding new files to the project.
</Description>
<ProjectType>VerilogProject</ProjectType>
</TemplateData>
<TemplateContent>
<ProjectItem TargetFileName="$fileinputname$.v"
ReplaceParameters="true">module.v</ProjectItem>
</TemplateContent>
</VSTemplate>
唉,这个模板根本不显示,即使我已将其包含在 VSIX 中并将其复制到输出目录中。如果我将此模板放在与 .vproj 相同的文件夹中,它将显示为用于创建新项目的模板(错误!),并且仍然不会出现在我的新项目列表中。这可能是因为我没有使用 VSTemplate 来创建项目。相反,我使用 [ProvideProjectFactoryAttribute] 让 VS2010 知道我的 vproj 文件在哪里,并且它将使用 vproj 文件(我猜你可以将其称为模板,但它不是 VSTemplate,它是一个项目)来基于新的项目关闭。
这就是我目前所处的位置,我将继续尝试新事物。我希望有人能找到我正在寻找的答案。谢谢,
吉瓦
I've created a custom language package, which extends ProjectPackage. I can create the new project correctly. I would like to be able to add new source files to the project by using the Add->New Item... (Ctrl+Shift+A) menu item. However, when I click this at the moment the list of available templates is empty. I would like to add my own custom template to the menu of available templates for this project type. Is there some documentation for accomplishing this? The only mentions I have seen have been registry hacks, but there has to be a way to do the programmatically I would think.
Is there a particular method I can override to populate the list? Do I really need to make a template, or can I just show the 'template name', 'icon' and provide the correct file extension (the files should be empty when created, so I think a template is largely wasted on what I want to do).
Here's the path I've been traveling down thus far. I figured I could set my project type and GUID in my custom .vproj file (.vproj is the file extension that my custom project is registered under). I thought I could quickly create a item template with the same ProjectType as my .vproj file.
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
<TemplateData>
<Icon>VerilogSource.ico</Icon>
<DefaultName>module.v</DefaultName>
<Name>Basic Verilog Module</Name>
<Description>
A basic Verilog module for quickly adding new files to the project.
</Description>
<ProjectType>VerilogProject</ProjectType>
</TemplateData>
<TemplateContent>
<ProjectItem TargetFileName="$fileinputname$.v"
ReplaceParameters="true">module.v</ProjectItem>
</TemplateContent>
</VSTemplate>
Alas, this template does not show up at all, even though I've included it in VSIX and copied it to the output directory. If I put this template in the same folder as my .vproj, it will appear as a template for creating a new project (wrong!) and still won't appear in my new items list. This could all derive from the fact that I do not use a VSTemplate for creating my project. Instead I use [ProvideProjectFactoryAttribute] to let VS2010 know where my vproj file is, and it will use the vproj file (which I guess you could call a template, but it isn't a VSTemplate, it is a Project) to base the new project off of.
This is where I am at so far, and I'm continuing to try new things. I'm hoping someone might have the answer I am looking for. Thanks,
Giawa
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过大量阅读和工作后,这是我的答案:
为您的项目和项目使用 vstemplate 文件,并将它们编译为 vstemplate (不要复制到输出,不要包含在 VSIX 中,这与 Microsoft 演练 建议)。编译器会将每个项目和项目模板打包到它们自己的 zip 文件中。现在,您需要告诉 vsixmanifest 这些文件的位置。项目和项的默认目录分别是 ProjectTemplates 和 ItemTemplates。将它们添加到您的 vsixmanifest 中,如下所示:
现在,您还必须向您的 vsix 包内置的 .csproj 文件添加一些属性。这些属性可能可以通过一些复杂的方法添加,但最简单的方法就是直接将它们放入.csproj 文件。
现在,这会将您的 zip 文件包含到您的项目中,如果幸运的话,您现在将拥有正确链接在一起的项目和项目。
幸运的是,有相当多的项目/项目模板文档。我花了一段时间才意识到这是正确的方法。祝你好运,
贾瓦
After a lot of reading and work, here's my answer:
Use vstemplate files for your project and items, and compile them as vstemplate (do not copy to output, do not include with VSIX, contrary to what the Microsoft Walkthrough suggests). The compiler will package each item and project template into their own zip file. Now, you need to tell the vsixmanifest where those files are. The default directories for projects and items are ProjectTemplates and ItemTemplates, respectively. Add them to your vsixmanifest like so:
Now, you must also add some properties to your .csproj file that your vsix package is built in. These properties can probably be added via some convoluted method, but the easiest is just to drop them directly in the .csproj file.
This will now include your zip files into your project, and with any luck, you'll now have projects and items that are linked correctly together.
Luckily, there is quite a bit of documentation out there for item/project templates. It just took me a while to realize that is the correct way to go. Good luck,
Giawa
所有这些步骤都可以在 Visual Studio 中自动完成:
首先在单独的项目中创建一个项目模板(您可以通过
文件 > 导出模板
来完成)。您可以通过编辑.vstemplate
文件来自定义此模板。获得
.zip
文件后,将其拖放到主VSPackage
解决方案中,然后执行以下操作:.vsixmanifest
文件。资产>;新的
。类型
设置为Microsoft.VisualStudio.ItemTemplate
(项目模板)。源
设置为文件系统上的文件
。Path
设置为项目模板.zip
文件。注意:我使用的是 Visual Studio 2013。
All those steps can be done automatically within the Visual Studio:
First Create an item template in a separate project (you can do it by
File > Export template
). You can customize this template by editing the.vstemplate
file.After you got a
.zip
file, drag and drop it to your mainVSPackage
solution and do the following:.vsixmanifest
file.Assets > New
.Type
toMicrosoft.VisualStudio.ItemTemplate
(Item Template).Source
toFile on filesystem
.Path
to your item template.zip
file.Note: I was using Visual Studio 2013.