MSDN > Home page del forum > Visual Studio Extensibility > how to send different item templates in VSX project to different target folders
Formula una domandaFormula una domanda
 

Con rispostahow to send different item templates in VSX project to different target folders

  • lunedì 29 giugno 2009 15.55GA30 Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Contiene codice
    Hello All,

    I am working on a VSX package. This package exposes a custom editor. This custom editor operates on a custom file type. This custom file type should be accessible from any C#/VB project via the "Add New Item" dialog. Right now I am just working on getting the custom file type to be accessible from any C# project type via the "Add New Item" dialog. I have 2 ItemTemplates in place within my VSX project, one which should go in the C# Silverlight item templates folder ("C:\Documents and Settings\[my user name]\Application Data\Microsoft\VisualStudio\9.0Exp\ItemTemplates\CSharp\Silverlight\1033") and another one which should go in the C# .NET "Reporting" item templates folder ("C:\Documents and Settings\[my user name]\Application Data\Microsoft\VisualStudio\9.0Exp\ItemTemplates\CSharp\Reporting\1033"). In order to accomplish this I have edited my VSX project file to include the following (which I believe are MSBuild instructions. I'm not familiar with MS Build. I copied this from the IronPython example):

      <ItemGroup>
        <ZipItem Include="Templates\ProjectItems\CSharp\Reporting\MyFileType\MyFileType.mft">
          <OutputSubPath>CSharp\Reporting\1033</OutputSubPath>
        </ZipItem>
        <ZipItem Include="Templates\ProjectItems\CSharp\Reporting\MyFileType\MyFileType.mft.cs">
          <OutputSubPath>CSharp\Reporting\1033</OutputSubPath>
        </ZipItem>
        <ZipItem Include="Templates\ProjectItems\CSharp\Reporting\MyFileType\MyFileType.vstemplate">
          <OutputSubPath>CSharp\Reporting\1033</OutputSubPath>
        </ZipItem>
      </ItemGroup>
      <ItemGroup>
        <ZipItem Include="Templates\ProjectItems\CSharp\Silverlight\MyFileType\MyFileType.mft">
          <OutputSubPath>CSharp\Silverlight\1033</OutputSubPath>
        </ZipItem>
        <ZipItem Include="Templates\ProjectItems\CSharp\Silverlight\MyFileType\MyFileType.mft.cs">
          <OutputSubPath>CSharp\Silverlight\1033</OutputSubPath>
        </ZipItem>
        <ZipItem Include="Templates\ProjectItems\CSharp\Silverlight\MyFileType\MyFileType.vstemplate">
          <OutputSubPath>CSharp\Silverlight\1033</OutputSubPath>
        </ZipItem>
      </ItemGroup>  
      <PropertyGroup>
        <TargetRegistryRoot Condition=" '$(TargetRegistryRoot)' == '' ">Software\Microsoft\VisualStudio\9.0Exp</TargetRegistryRoot>
        <RegisterOutputPackage Condition="'$(RegisterOutputPackage)' == ''">true</RegisterOutputPackage>
        <RegisterWithCodebase>true</RegisterWithCodebase>
        <!--<VsTemplateLanguage>CSharp</VsTemplateLanguage>-->
      </PropertyGroup>
      <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
      <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\VSSDK\Microsoft.VsSDK.targets" />
    
    The problem I am having is that somehow the LAST ItemGroup processed is the one that's ending up in both folder. In others, the second ItemGroup listed above which is located in my VSX project at "Templates\ProjectItems\CSharp\Silverlight\MyFileType\" is the one that ends up in both target directories, both "C:\Documents and Settings\[my user name]\Application Data\Microsoft\VisualStudio\9.0Exp\ItemTemplates\CSharp\Silverlight\1033" AND "C:\Documents and Settings\[my user name]\Application Data\Microsoft\VisualStudio\9.0Exp\ItemTemplates\CSharp\Reporting\1033". However, what I am expecting to happen is for the first ItemGroup listed above to end up at "C:\Documents and Settings\[my user name]\Application Data\Microsoft\VisualStudio\9.0Exp\ItemTemplates\CSharp\Reporting\1033" and the second one at "C:\Documents and Settings\[my user name]\Application Data\Microsoft\VisualStudio\9.0Exp\ItemTemplates\CSharp\Silverlight\1033". But this is not happening rather the second ItemTemplate is ending up in both locations and that's basically my problem. I have not been able to figure out how to fix this and am hoping someone could give me some help. The ItemTemplate for the first ItemGroup listed above is located in my VSX project at "Templates\ProjectItems\CSharp\Reporting\MyFileType\MyFileType.vstemplate", and I want it to end up at "C:\Documents and Settings\[my user name]\Application Data\Microsoft\VisualStudio\9.0Exp\ItemTemplates\CSharp\Reporting\1033", and this is what the vstemplate files looks like:
    <VSTemplate Version="3.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
      <TemplateData>
        <Name Package="{7DBE78A6-143B-4644-8DEB-D2D2D386D371}" ID="200"/>
        <Description Package="{7DBE78A6-143B-4644-8DEB-D2D2D386D371}" ID="202"/>
        <Icon Package="{7DBE78A6-143B-4644-8DEB-D2D2D386D371}" ID="401"/>
        <TemplateGroupID>Reporting</TemplateGroupID>
        <ProjectType>CSharp</ProjectType>
        <ShowByDefault>false</ShowByDefault>
        <SortOrder>10</SortOrder>
        <RequiredFrameworkVersion>3.5</RequiredFrameworkVersion>
        <DefaultName>MyFileType.mft</DefaultName>
        <NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
      </TemplateData>
      <TemplateContent>
        <ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.mft">MyFileType.mft</ProjectItem>
        <ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.mft.cs">MyFileType.mft.cs</ProjectItem>
      </TemplateContent>
      <WizardExtension>
        <Assembly>MyFileType.Design.Wizard, Version=1.0.0.0, Culture=neutral, PublicKeyToken=905c288b1b03a431</Assembly>
        <FullClassName>MyFileType.Design.MyFileTypeProjectItemWizard</FullClassName>
      </WizardExtension>
    </VSTemplate>
    
    The ItemTemplate for the second ItemGroup listed above is located in my VSX project at "Templates\ProjectItems\CSharp\Silverlight\MyFileType\MyFileType.vstemplate", and I want it to end up at "C:\Documents and Settings\[my user name]\Application Data\Microsoft\VisualStudio\9.0Exp\ItemTemplates\CSharp\Silverlight\1033", and this is what this vstemplate files looks like:

    <VSTemplate Version="3.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
      <TemplateData>
        <Name Package="{7DBE78A6-143B-4644-8DEB-D2D2D386D371}" ID="200"/>
        <Description Package="{7DBE78A6-143B-4644-8DEB-D2D2D386D371}" ID="202"/>
        <Icon Package="{7DBE78A6-143B-4644-8DEB-D2D2D386D371}" ID="401"/>
        <TemplateGroupID>Silverlight</TemplateGroupID>
        <ProjectType>CSharp</ProjectType>
        <ShowByDefault>false</ShowByDefault>
        <SortOrder>10</SortOrder>
        <RequiredFrameworkVersion>3.5</RequiredFrameworkVersion>
        <DefaultName>MyFileType.mft</DefaultName>
        <NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
      </TemplateData>
      <TemplateContent>
        <ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.mft">MyFileType.mft</ProjectItem>
        <ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.mft.cs">MyFileType.mft.cs</ProjectItem>
      </TemplateContent>
      <WizardExtension>
        <Assembly>MyFileType.Design.Wizard, Version=1.0.0.0, Culture=neutral, PublicKeyToken=905c288b1b03a431</Assembly>
        <FullClassName>MyFileType.Design.MyFileTypeProjectItemWizard</FullClassName>
      </WizardExtension>
    </VSTemplate>
    

    If you notice both vstemplate files are virtually identical except that the first has a TemplateGroupId value of "Reporting" and the second has a TemplateGroupId value of "Silverlight". Again, I am not sure why the second ends up in both target directories. And I'm pretty sure it's the document order of the ItemGroup elements that's driving which one is the one that ends up in both places. I say this because if I flip the order and have the "Silverlight" ItemGroup appear first and the "Reporting" ItemGroup appear second, the it's the "Reporting" ItemGroup that will appear in both target directories. One other note, initially I was just working with one ItemTemplate, the one for "Silverlight". And when I only had this one everything worked great, meaning that when I ran the VSX project and created a SL project in the experimental hive and invoked the "Add New Item" dialog everything worked great. Now I just need to be able to do the same from a non SL C# project and have my item listed in the "Reporting" sub folder of the "Add New Item" dialog. Can anyone please help me? Thank you VERY much!

Risposte

  • giovedì 2 luglio 2009 10.41Wesley YaoMSFT, ModeratoreMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con risposta
    Hello,

    Actually, this job(sending template to the target folder) is done by the "Copy" task in your package project file, please check the "Copy" task existed in the "AfterBuild" target, investigate it, you will find the reason.
    It should looks like: <Copy SourceFiles="xxx" DestinationFolder="xxx" />, from your description, I think the DestinationFolder is correct but the SourceFiles sounds not very well.

    You could also ignore what it is, just add another "Copy" task to send your fist ItemGroup.

    Sincerely,
    Wesley
    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Contrassegnato come rispostaGA30 venerdì 3 luglio 2009 5.30
    •  

Tutte le risposte

  • giovedì 2 luglio 2009 10.41Wesley YaoMSFT, ModeratoreMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con risposta
    Hello,

    Actually, this job(sending template to the target folder) is done by the "Copy" task in your package project file, please check the "Copy" task existed in the "AfterBuild" target, investigate it, you will find the reason.
    It should looks like: <Copy SourceFiles="xxx" DestinationFolder="xxx" />, from your description, I think the DestinationFolder is correct but the SourceFiles sounds not very well.

    You could also ignore what it is, just add another "Copy" task to send your fist ItemGroup.

    Sincerely,
    Wesley
    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Contrassegnato come rispostaGA30 venerdì 3 luglio 2009 5.30
    •  
  • venerdì 3 luglio 2009 5.30GA30 Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Hello Wesley,

    First and foremost, thanks very much for the response.

    Your words lead me to a solution. It turns out the problem was that both of my vstemplate files were in folders of the same name. I gave each folder a distinct name and now each item template is going to its correct location. So this issue appears resolved. Now the problem I am having is that my file type is not appearing in the "Add New Item" Dialog of the non SL projects. I am expecting it to since I have placed my item template in the "Reporting" folder. But anyway, I don't want to side track the issue here. I will post this problem in another thread. Thanks your for your help!