locked
Create Multi-file Item Template with Custom Tool RRS feed

  • Question

  • Well,

    I'm basing most of my template creation off of existing templates because most often I am simply expanding upon what is already there.  For this case, I am working with the "dataset" item template.  So, for starters, I went to the %VisualStudio%\Common7\Ide\ItemTemplates\VisualBasic\Data\1033 folder and opened up the dataset.zip file, extracting both the xsd and the vstemplate files.

    I proceeded to update them slightly, as I wanted to include my own "options" file as part of the Dataset, and re-define the Custom Tool.

      <ProjectItem ReplaceParameters="true" SubType="Designer">DataSet.xsd</ProjectItem>
      <CustomParameters>
       <CustomParameter Name="$itemproperties$" Value="CustomTool" />
       <CustomParameter Name="$CustomTool$" Value="MSDataSetGenerator" />
       <CustomParameter Name="$QueryServiceGuid$" Value="AD028B85-FA21-41b1-AB4A-08672F633506" />
       <CustomParameter Name="$XmlConvert_itemname$" Value="" />
      </CustomParameters>
    
    

    Those lines are a direct copy/paste from the default dataset template included in VS 2008 pro.  pretty simple.  Well, I also looked at the Form.zip template, and say that it contained two <ProjectItem> tags, where only the Form.vb has the subtype "designer" and the Form.designer.vb was just included normally. 

    I also took my current application that has a fully realized dataset done in this fashion, and exported the template so as to see how it exported.  My end result was:

    		<ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.xso" SubType="">QWDataSet.xso</ProjectItem>
    		<ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.xsd" SubType="Designer">QWDataSet.xsd</ProjectItem>
    		<CustomParameters>
    			<CustomParameter Name="$itemproperties$" Value="CustomTool" />
    			<CustomParameter Name="$CustomTool$" Value="QWCodeFileGenerator" />
    			<CustomParameter Name="$QueryServiceGuid$" Value="AD028B85-FA21-41b1-AB4A-08672F633506" />
    			<CustomParameter Name="$XmlConvert_itemname$" Value="" />
    		</CustomParameters>
    
    

    Now for the problems:

    First the .XSO file (which is simply an xml file with included Schema) was not added as a "DependentUpon" entry in the Solution Explorer.  If you examing a .vbproj file in a text/xml editor, you see, this:

      <None Include="DataSet1.xsd">
       <SubType>Designer</SubType>
       <Generator>QWCodeFileGenerator</Generator>
       <LastGenOutput>DataSet1.Designer.vb</LastGenOutput>
      </None>
      <None Include="DataSet1.xso">
       <DependentUpon>DataSet1.xsd</DependentUpon>
      </None>
      <None Include="DataSet1.xsc">
       <DependentUpon>DataSet1.xsd</DependentUpon>
      </None>
      <None Include="DataSet1.xss">
       <DependentUpon>DataSet1.xsd</DependentUpon>
      </None>
    
    

    Of course the line containing the ".xso" file is my manual addition.  WHen I create the item off of my above template design I get this:

      <None Include="QWDataSet1.xsc">
       <DependentUpon>QWDataSet1.xsd</DependentUpon>
      </None>
      <None Include="QWDataSet1.xsd">
       <SubType>Designer</SubType>
       <Generator>QWCodeFileGenerator</Generator>
      </None>
      <None Include="QWDataSet1.xss">
       <DependentUpon>QWDataSet1.xsd</DependentUpon>
      </None>
      <None Include="QWDataSet1.xso">
       <Generator>QWCodeFileGenerator</Generator>
      </None>
    
    

    As you can see, my template for some reason has decided to create the .xso file as a "Generator" file and not as a "DependentUpon" file. 

    How Do I rectify this in the .vstemplate file in order to tell Visual studio:

    A) The ProjectItem .xso is a "Dependent File" for the .xsd

    B) The CustomTool Generator ONLY applies to the .XSD file not the .XSO file

    Thanks

    Jaeden "Sifo Dyas" al'Raec Ruiner


    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.
    Monday, March 14, 2011 4:56 PM

Answers

  • Hi JaedenRuiner,

    Welcome to the MSDN forum! Im glad to see your active participation and discussion in MSDN forum. My name is Andrew Xiao and I will do my best to resolve your problem as soon as possible.

    According to your description (I have noticed that you are not familiar with Custom Wizard Extension Development). If I have misunderstood anything, please feel free to let me know.

    I have some actions might help resolve your problem. Please take the following step:

    1.       Create Class Libarary project to implement IWizard interface.

    Example:   

    public void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem)

    {

        ProjectItemTypes type = GetProjectItemType(projectItem);

        switch (type)

        {

            case ProjectItemTypes.Parent:

                this.parentProjectItem = projectItem;

                break;

            case ProjectItemTypes.Child:

                this.childrenProjectItems.Add(projectItem);

                break;

    }

    Then when the template is finished, it adds the nested items to its parent like this:

    public void RunFinished()

    {

        foreach (EnvDTE.ProjectItem item in this.childrenProjectItems)

        {

        string filename = item.get_FileNames(0);

        this.parentProjectItem.ProjectItems.AddFromFile(filename);

        }

    }

    2.    Build my Class Libarary project and sign my assembly with a strong name, and then register this assembly in the GAC(Global Assembly Cache).

    3.       Add the following code in the Template.

           <WizardExtension>

        <Assembly>CustemTempalteWizard, Version=1.0.0.0, Culture=neutral, PublicKeyToken=839837e0656accff, processorArchitecture=MSIL</Assembly>

        <FullClassName>CustemTempalteWizard.Class1</FullClassName>

    </WizardExtension>

     

    I hope this will help resolve your problem. If anything is not clear, please feel free to let us know.

    Thank you for your understanding and support.

     

    Best Regards,

    Andrew

     

    Thursday, March 17, 2011 2:39 AM

All replies

  • Hi JaedenRuiner,

    From your description (The ProjectItem .xso is a "Dependent File" for the .xsd). I did some research, this can't be done in .vstemplate file. We'd better to use Iwizard to create an item which have nested items.

     

     

     

     

    I hope this will help resolve your problem.

     

    Andrew

    used Iwizard to programatically add the files as child files - http://www.codeproject.com/KB/dotnet/NestedItemTemplate.aspx
    • Edited by Andrew Xiao Wednesday, March 16, 2011 6:49 AM
    Tuesday, March 15, 2011 9:02 AM
  • Ah,

    Well a few things here.  First off, where do I find this "IWizard" to create the nested template.  Is it a 3rd party app, or something built into VS, and if the latter where do I find it in VS?

    Secondly, that link seems to cause a complaint about an invalid security certificate, so not sure if that was intential, but something maybe to look into.

    Thanks

    Jaeden "Sifo Dyas" al'Raec Ruiner


    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.
    Tuesday, March 15, 2011 7:08 PM
  • Hi JaedenRuiner,

    Welcome to the MSDN forum! Im glad to see your active participation and discussion in MSDN forum. My name is Andrew Xiao and I will do my best to resolve your problem as soon as possible.

    According to your description (I have noticed that you are not familiar with Custom Wizard Extension Development). If I have misunderstood anything, please feel free to let me know.

    I have some actions might help resolve your problem. Please take the following step:

    1.       Create Class Libarary project to implement IWizard interface.

    Example:   

    public void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem)

    {

        ProjectItemTypes type = GetProjectItemType(projectItem);

        switch (type)

        {

            case ProjectItemTypes.Parent:

                this.parentProjectItem = projectItem;

                break;

            case ProjectItemTypes.Child:

                this.childrenProjectItems.Add(projectItem);

                break;

    }

    Then when the template is finished, it adds the nested items to its parent like this:

    public void RunFinished()

    {

        foreach (EnvDTE.ProjectItem item in this.childrenProjectItems)

        {

        string filename = item.get_FileNames(0);

        this.parentProjectItem.ProjectItems.AddFromFile(filename);

        }

    }

    2.    Build my Class Libarary project and sign my assembly with a strong name, and then register this assembly in the GAC(Global Assembly Cache).

    3.       Add the following code in the Template.

           <WizardExtension>

        <Assembly>CustemTempalteWizard, Version=1.0.0.0, Culture=neutral, PublicKeyToken=839837e0656accff, processorArchitecture=MSIL</Assembly>

        <FullClassName>CustemTempalteWizard.Class1</FullClassName>

    </WizardExtension>

     

    I hope this will help resolve your problem. If anything is not clear, please feel free to let us know.

    Thank you for your understanding and support.

     

    Best Regards,

    Andrew

     

    Thursday, March 17, 2011 2:39 AM
  • Sorry that I haven't come back to this thread in a while, but I am finally at a point where I actually am taking the time to create Wizard extensions. 

    So, first off, it was going to be pointed to that IWizard interface which allows for so much customization of the code templates, however I do still have some remaining questions regarding your answer to adding a tree of "Dependent" items to a project.

    ProjectItemTypes is not a actual type and neither is the method which gets this information.  I have searched for the string and it apparently has something to do with SharePoint which A) I have no knowledge of and B) is unessential to our system here. 

    So, is this facet even necessary as long as I am either doing a Project Template or Item Template, so this would only be a factor for Item Templates, and thus can check the WizardRunKind parameter of the RunStarted() method to provide me the necessary checks, and then is it simply retaining the list of sub child items?  How do i know which project item is the "Parent" item and which is the "child items" or do i need to code that with "custom" parameters in the vstemplate files?

    Thanks

    Jaeden "Sifo Dyas" al'Raec Ruiner

     


    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.
    Monday, October 3, 2011 9:11 PM