使用标签构建Visual Studio模板,以进行有效的用户搜索和分组
Visual Studio’s project templates enable you, the developer, to create multiple similar projects more efficiently by defining a common set of starter files. The project templates can be fully customized to meet the needs of a development team, or a group, and can be published to the Visual Studio Marketplace for others to download and use too! Once published, developers can install and access the template through Visual Studio’s New Project Dialog.
Visual Studio的项目模板使开发人员可以通过定义一组通用的启动程序文件来更有效地创建多个类似项目。 可以对项目模板进行完全自定义,以满足开发团队或小组的需求,并且可以将其发布到Visual Studio Marketplace中,供其他人下载和使用! 发布后,开发人员可以通过Visual Studio的“新建项目”对话框安装和访问模板。
The newly designed New Project Dialog for Visual Studio 2019 was built to help developers get to their code faster. Using a search and filter focused experience, we are aiming to provide better discoverability for specific templates to start your application development
新设计的Visual Studio 2019的新项目对话框旨在帮助开发人员更快地获取其代码 。 借助以搜索和过滤器为重点的经验,我们旨在为特定模板提供更好的可发现性,以开始您的应用程序开发
In this walkthrough, you will learn to
在本演练中,您将学习
- Create a project template 创建一个项目模板
- Add tags or filters to the project template 将标签或过滤器添加到项目模板
- Deploy the template as an extension using the VSIX project template 使用VSIX项目模板将模板部署为扩展
Before getting started, please make sure you have installed Visual Studio 2019 with Visual Studio SDK.
在开始之前,请确保已使用Visual Studio SDK安装了Visual Studio 2019。
创建项目模板 (Creating a project template )
There are a few ways you can create a project template, but in this walkthrough, we will create a C# project template using the New Project Dialog.
您可以通过几种方式创建项目模板,但是在本演练中,我们将使用“新建项目”对话框创建C#项目模板。
-
In Visual Studio, launch the New Project Dialog File > New > Project
在Visual Studio中,启动“新建项目”对话框文件 >“ 新建” >“ 项目”
(or use the keyboard shortcut, CTRL + SHIFT + N).
(或使用键盘快捷键CTRL + SHIFT + N)。
-
Filter the list by Project type > Extensions and select C# Project Template.
按项目类型 > 扩展过滤列表,然后选择C#项目模板 。
-
Click Next then modify the Project name field and click Create.
单击下一步,然后修改项目名称字段,然后单击创建 。
将标签/过滤器添加到项目模板 (Adding tags / filters to your project template )
Once you’ve created a project template, you can add tags or filters to it in the template’s .vstemplate XML file. 1. Add Visual Studio’s built-in tags as well as any custom tags to your project template using LanguageTag, PlatformTag, ProjectTypeTag elements under TemplateData and save the file. For example, as highlighted below:
创建项目模板后,您可以在模板的中向其添加标签或过滤器。 vstemplate XML文件。 1.使用TemplateData下的LanguageTag , PlatformTag , ProjectTypeTag元素将Visual Studio的内置标签以及所有自定义标签添加到项目模板中,然后保存文件。 例如,如下所示:
2. Save and close the vstemplate the XML file.
2.保存并关闭vstemplate XML文件。
使用VSIX项目模板将模板作为扩展部署 (Deploying the template as an extension using the VSIX project template )
Wrap your project template in a VSIX project template to deploy your template as an extension.
将项目模板包装在VSIX项目模板中,以将模板部署为扩展。
1. Create an Empty VSIX Project in the Solution created for the C# project template above.
1.在为上述C#项目模板创建的解决方案中创建一个空VSIX项目。
- In the Solution Explorer, right click on the Solution and select Add > New Project. 在解决方案资源管理器中,右键单击解决方案,然后选择添加>新建项目。
- Type “vsix” in the search box and select Empty VSIX Project for C# (or VSIX Project if you are using earlier versions of Visual Studio). 在搜索框中键入“ vsix”,然后为C#选择“空VSIX项目”(如果使用的是Visual Studio的早期版本,则选择“ VSIX项目”)。
- Click Next then modify the Project name field and click Create. 单击下一步,然后修改项目名称字段,然后单击创建。
2. Set the VSIX Project as a startup project.
2.将VSIX项目设置为启动项目。
In the Solution Explorer, right click on the VSIX project and select Set as StartUp Project. Your Solution Explorer should now look something like this (with your VSIX project bolded):
在解决方案资源管理器中,右键单击VSIX项目,然后选择“设为启动项目”。 您的解决方案资源管理器现在应该看起来像这样(VSIX项目以粗体显示):
3. Add your project template as an asset to the VSIX project.
3.将项目模板作为资产添加到VSIX项目。
-
Click on the Assets tab and select the New button.
单击资产选项卡,然后选择新建按钮。
-
Set the Type field as Microsoft.VisualStudio.ProjectTemplate.
将类型字段设置为Microsoft.VisualStudio.ProjectTemplate 。
-
Set the Source field as A project in current solution.
在当前解决方案中将“ 源”字段设置为A项目 。
-
Set the Project field as your project template.
将项目字段设置为您的项目模板。
-
Click OK, then save and close the source.extension.vsixmanifest file.
单击确定 ,然后保存并关闭source.extension .vsixmanifest文件。
4. Run your code without invoking the debugger (
4.在不调用调试器的情况下运行代码( CTRL + CTRL + F5) F5 )
That’s it! Your new project template will appear in the New Project dialog with the tags under your template’s description and filters enabled by those tags. You can also take it a step further and easily publish your project template to the Visual Studio Marketplace (and while you’re at it, also try out the little great things about Visual Studio 2019 and please let us know what you think)! Here is an example of one in an existing extension, Textmate Grammar Template.
而已! 您的新项目模板将显示在“ 新建项目”对话框中,其中模板说明下的标签以及由这些标签启用的过滤器。 您还可以更进一步,轻松地将项目模板发布到Visual Studio Marketplace(在您使用它的同时,还可以尝试一下有关Visual Studio 2019的小知识 ,请告诉我们您的想法)! 这是现有扩展中的一个示例Textmate语法模板 。
有建议吗? (Have suggestions? )
We are continuing to work on our tools and to do that, we could use your help! Please share your feedback/comments below, or through the Visual Studio Developer Community, or tweet at our team @VisualStudio.
我们将继续致力于我们的工具,为此,我们可以使用您的帮助! 请在下面或通过Visual Studio 开发人员社区或在我们的@VisualStudio团队中分享您的反馈/意见。
崔秀珍 (Soojin Choi)
Program Manager, Visual Studio Platform
Visual Studio平台程序经理