2009-09-03 1 views
1

У меня есть шаблон, который добавляет новую запись в контекстное меню «Добавить-> Новый элемент» в проекте в проводнике решений в Visual Studio.Создание шаблона элемента для Visual Studio 2008 с файловыми зависимостями, возможно ли это?

Я уже создал шаблон, поместив его в свой каталог ItemTemplates под папкой моих документов, и он работает в том смысле, что я могу добавлять новые элементы в проект через шаблон.

Однако шаблон состоит из 3 файлов:

<filename>.controller 
<filename>.Designer.cs 
<filename>.cs 

Они добавляются к проекту на тот же уровень, но я хотел бы иметь такую ​​же иерархию вы получаете, когда вы добавляете форму к проекту, где файл .Designer.cs помещается как под-узел под файлом .cs.

В принципе, это то, что проект выглядит следующим образом:

TestProject 
    +- Properties 
    +- References 
    +- App.config 
    +- Program.cs 
    +- MyTestController.controller 
    +- MyTestController.Designer.cs 
    +- MyTestController.cs 

в то время как я хочу, чтобы выглядеть следующим образом:

TestProject 
    +- Properties 
    +- References 
    +- App.config 
    +- Program.cs 
    +- MyTestController.controller 
    +- MyTestController.Designer.cs 
    +- MyTestController.cs 

это возможно? Если да, то что я могу изменить в моем файле .vstemplate, чтобы получить это поведение?

Вот .vstemplate файл я добавил в шаблон почтового файла:

<VSTemplate Version="2.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005"> 
    <TemplateData> 
     <Name>LVK.NET New Controller</Name> 
     <Description>Adds an business logic controller class to the project.</Description> 
     <Icon Package="{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}" ID="4522" /> 
     <ProjectType>CSharp</ProjectType> 
     <SortOrder>10</SortOrder> 
     <DefaultName>Controller.controller</DefaultName> 
    </TemplateData> 
    <TemplateContent> 
     <References> 
      <Reference> 
       <Assembly>System</Assembly> 
      </Reference> 
      <Reference> 
       <Assembly>System.Data</Assembly> 
      </Reference> 
      <Reference> 
       <Assembly>System.Xml</Assembly>:\ 
      </Reference> 
      <Reference> 
       <Assembly>LVK.Core</Assembly> 
      </Reference> 
      <Reference> 
       <Assembly>LVK.BusinessLogic</Assembly> 
      </Reference> 
     </References> 
     <ProjectItem ReplaceParameters="true">Controller.controller</ProjectItem> 
     <ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.Designer.cs">Controller.Designer.cs</ProjectItem> 
     <ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.cs">Controller.cs</ProjectItem> 
    </TemplateContent> 
</VSTemplate> 

ответ

1

Укажите "иерархию" в projectfile (например .csproj):

<ItemGroup> 
    <Compile Include="Controller.controller" /> 
    <Compile Include="Controller.cs"> 
    <DependentUpon>Controller.controller</DependentUpon> 
    </Compile> 
    <Compile Include="Controller.Designer.cs"> 
    <DependentUpon>Controller.controller</DependentUpon> 
    </Compile> 
</ItemGroup> 

и добавить файл проекта к вашему .vstemplate

<TemplateContent> 
    <Project TargetFileName="Project1.csproj" File="Project1.csproj" ReplaceParameters="true"> 
     <ProjectItem ReplaceParameters="false" TargetFileName="Controller.controller">Controller.controller</ProjectItem> 
     <ProjectItem ReplaceParameters="true" TargetFileName="Controller.cs">Controller.cs</ProjectItem> 
     <ProjectItem ReplaceParameters="true" TargetFileName="Controller.Designer.cs">Controller.Designer.cs</ProjectItem> 
    </Project> 
    </TemplateContent> 

Done ;-)