locked
Customizing a project item template RRS feed

  • Question

  • Hello,

    I'd like to set the custom tool and the build action of a project item through a project item template. I saw on a post titled "Is it possible to associate a custom tool with a file extension" posted on 4. July, but could not make it work (with both VS 2005 Beta 2 and RC1)
    After exporting a template through VS2005 and modifying it according to the mentioned post, I get:

    <VSTemplate Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
      <TemplateData>
        <DefaultName>SqlBuilder.dbm</DefaultName>
        <Name>SqlBuilder</Name>
        <Description>Meta-data information for the SQL Builder Generator</Description>
        <ProjectType>CSharp</ProjectType>
        <SortOrder>10</SortOrder>
        <Icon>__TemplateIcon.ico</Icon>
      </TemplateData>
      <TemplateContent>
        <References />
        <ProjectItem SubType="" TargetFileName="$fileinputname$.dbm" ReplaceParameters="true">XMLFile1.dbm</ProjectItem>
        <CustomParameters>
           <CustomParameter Name="$CustomTool$" Value="SqlBuilderGenerator" />
        </CustomParameters>
      </TemplateContent>
    </VSTemplate>

    The CustomParameters section is supposed to set the custom tool, but it has no effect. What am I doing wrong and how can I set the build action ?
    ---
    Jean-Marie Pirelli

    Thursday, September 29, 2005 8:20 AM

Answers

  • There seems to be some confusion over what the CustomParameters and CustomParameter tags do. When you use the CustomParameter tag, this creates a replacement variable with the name Name, and will replace that value with the value SqlBuilderGenerator. Meaning that you will be able to open a text file, put the string $CustomTool$ in that file, and when the wizard runs it will find that token and replace it with SqlBuilderGenerator. It will not modify properties of the project file.

    Craig
    Monday, October 31, 2005 9:11 PM

All replies

  • There seems to be some confusion over what the CustomParameters and CustomParameter tags do. When you use the CustomParameter tag, this creates a replacement variable with the name Name, and will replace that value with the value SqlBuilderGenerator. Meaning that you will be able to open a text file, put the string $CustomTool$ in that file, and when the wizard runs it will find that token and replace it with SqlBuilderGenerator. It will not modify properties of the project file.

    Craig
    Monday, October 31, 2005 9:11 PM
  • Hello,

    I needed the same thing for resource files targeting the FX1.1. This works for me, I hope it will help you :

    <TemplateContent>

        <ProjectItem>Resource.resx</ProjectItem>

        <CustomParameters>

            <CustomParameter Name="$itemproperties$" Value="CustomTool" />

            <CustomParameter Name="$CustomTool$" Value="ResXFilePublicCodeGenerator" />

        </CustomParameters>

    </TemplateContent>

    Note the CustomParameter which specifies the CustomTool as an item property.

    Monday, April 3, 2006 11:14 AM
  • I can't seem to get this to work with my template.
    The file is generated reflecting the template with the parameters replaces correctly, but the CustomTool association is never made, it's just blank...
    Wednesday, May 16, 2007 3:08 PM
  • I have the same problem. Did anybody find the resolution?

    Friday, May 18, 2007 9:49 AM
  • Well it seems that there is a type reference required for the wizard engine, so that the custom parameters are picked up to begin with.

     

    Add this to your template file (inside the VSTemplate element):

     

    Code Snippet

    <WizardExtension>

    <Assembly>Microsoft.VSDesigner, Version=8.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>

    <FullClassName>Microsoft.VSDesigner.ProjectWizard.ItemPropertyWizard</FullClassName>

    </WizardExtension>

     

    • Proposed as answer by hsaelens Tuesday, May 18, 2010 12:10 PM
    Thursday, March 6, 2008 4:05 PM
  • How would you do the same thing in order to set the BuildAction? I've tried various things and I haven't been able to get it working. In my case I have a custom .xml file with extension .YYY and I want for it to be marked as an Embedded Resource when it it is added via it's Item Template.
    Monday, June 22, 2009 5:29 PM
  • <ProjectItem SubType="Content" TargetFileName="$fileinputname$.Spark" ReplaceParameters="true">Spark.Spark</ProjectItem> The SubType controls the BuildAction. It must match the MSBuild element name you wish to emit.
    Wednesday, January 5, 2011 8:29 AM
  • This seems to have worked up to VS 2015, but no longer works with VS 2017 RC. Has anything changed?
    Thursday, January 5, 2017 10:14 PM
  • This seems to have worked up to VS 2015, but no longer works with VS 2017 RC. Has anything changed?
    Thursday, January 5, 2017 10:14 PM