How to add conditions in Visual Studio Template Schema and generate projects based on conditions

痴心易碎 提交于 2020-04-07 09:19:51

问题


I have a requirement to generate a custom project template using vsix and IWizard. Wizard will show three check boxes. for example (Bot, Tab , Chat). The output solution must have projects only for checkboxes selected in the wizard i.e if both Bot and Tab are selected then Bot.csproj and Tab.csproj projects will be generated in the solution. If all three of them are selected then all projects must be generated. Right now it generates all the projects irrespective of the selection because there is no way to add conditions in the top most .vsTemplate file. Below is the vsTemplate I have in the code, Is there any way with which I can achieve it?

In short,When we create a asp.net mvc project , if we selected "Tests" checkbox then it will generate a unit test project too. If we doesn't selected it doesn't generate. I have a similar requirement.

<?xml version="1.0" encoding="utf-8"?>
<VSTemplate Version="3.0.0" Type="ProjectGroup" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" xmlns:sdk="http://schemas.microsoft.com/developer/vstemplate-sdkextension/2010">
  <TemplateData>
    <Name>My App (C#)</Name>
    <Description>A project for creating a chat application using C#</Description>
    <Icon>Chat.ico</Icon>
    <ProjectType>CSharp</ProjectType>
    <LanguageTag>csharp</LanguageTag>
    <PlatformTag>C#</PlatformTag>
    <RequiredFrameworkVersion>2.0</RequiredFrameworkVersion>
    <SortOrder>1000</SortOrder>
  </TemplateData>
  <TemplateContent>
    <ProjectCollection>
      <ProjectTemplateLink ProjectName="Tab">
        TabProject\Tab.vstemplate
      </ProjectTemplateLink>
      <ProjectTemplateLink ProjectName="Bot">
        BotProject\Bot.vstemplate
      </ProjectTemplateLink>
      <ProjectTemplateLink ProjectName="Chat">
        ChatProject\Chat.vstemplate
      </ProjectTemplateLink>
    </ProjectCollection>
  </TemplateContent>
</VSTemplate>

来源:https://stackoverflow.com/questions/60220136/how-to-add-conditions-in-visual-studio-template-schema-and-generate-projects-bas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!