NET core Project Definition Item Template

Source: Internet
Author: User

NET core Project Definition Item Template

As the most powerful ide,visual studio on the planet, not only does it provide a lot of native features, but more importantly it is a customizable ide, such as custom project template and item template, which is a very useful extension point. Here we focus on item Template, where we can add our custom item (as Shown) in the "add new item" dialog box. If you do not know the article Template,scott gu.

We have previously customized some of the item Template and have recently tried to use them in. NET core projects, but have Failed. It was a tough day for this, but it was finally solved-although the solution was simply to add a single line of Code.

If you do not understand the schema of the item template definition file, The simplest way to define the item template is to create a corresponding project directly with vs. Since we are the item Template provided for The. Net core project, we have created A. Net Core class library Project. As a demonstration, we added the following Foobar.cs file to the project as the item template for the item that was added for the target Project.

As a rule, we only need to select the menu File->export template to open the Export Wizard for the following Template. We select the Item Template option and proceed to the next Step.

As long as we use the item template to add Foobar.cs to the target, we just need to select this File.

Select the default option to know the completion wizard, as A. Zip file will appear in the directory "%userprofile%documents\visual Studio 2015\my exported Templates" directory.

As a rule, we just need to copy this zip file to the%userprofile%documents\visual Studio 2015\templates\itemtemplates\.net Core catalog. however, when you add item to A. NET core project, You do not see it.

To do this, we unzip the file and look at its "mytemplate.vstemplate" file, as shown below, which is the contents of the File. The main focus is on the <ProjectType> element that represents the project type, and we see its value as DNX. One might think that dnx is the wrong type of project, although DNX is already a historic place, but vs is still using it to Represent. NET Core.

   1: <vstemplate version= "3.0.0" xmlns= "http://schemas.microsoft.com/developer/vstemplate/2005" type= "Item" >
   2:   <TemplateData>
   3:     <DefaultName>MyItem.cs</DefaultName>
   4:     <Name>MyItem</Name>
   5:     <Description>&lt; No Description available&gt;</description>
   6:     <ProjectType>DNX</ProjectType>
   7:     <SortOrder>10</SortOrder>
   8:     <Icon>__TemplateIcon.ico</Icon>
   9:   </TemplateData>
  Ten:   <TemplateContent>
  One:     <references/>
  :     <projectitem subtype= "" targetfilename= "$fileinputname $.cs" replaceparameters= "true" >Foobar.cs< /projectitem>
  :   </TemplateContent>
  : </VSTemplate>

In fact, In addition to the need to develop <ProjectType>, we also need to specify templategroupid, and set the value to "shareddotnetanddotnetweb" (representing the Normal. NET Core class library projects and Web projects Apply)

   1: <vstemplate version= "3.0.0" xmlns= "http://schemas.microsoft.com/developer/vstemplate/2005" type= "Item" >
   2:   <TemplateData>
   3:     <DefaultName>MyItem.cs</DefaultName>
   4:     <Name>MyItem</Name>
   5:     <Description>&lt; No Description available&gt;</description>
   6:     <ProjectType>DNX</ProjectType>
   7:     <TemplateGroupID>SharedDotNetAndDotNetWeb</TemplateGroupID>
   8:     <SortOrder>10</SortOrder>
   9:     <Icon>__TemplateIcon.ico</Icon>
  Ten:   </TemplateData>
  One:   <TemplateContent>
  :     <references/>
  :     <projectitem subtype= "" targetfilename= "$fileinputname $.cs" replaceparameters= "true" >Foobar.cs< /projectitem>
  :   </TemplateContent>
  : </VSTemplate>
Then we re-compress the package and deploy it,

NET core Project Definition Item Template

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.