none
How to set the Build Action for an item created by a Visual Studio item template?

    Question

  • I'm wondering how to create an item template for Visual Studio that is able to set the Build Action. In my case the item that I'm adding is an XML file with a .YYY extension and I wish to set the CustomTool to a custom tool and the Build Action to "Embedded Resource". I've been able to get the CustomTool to set by using the CustomProperties as shown below but I can't get BuildAction working no matter what I try. I also haven't been able to find any documentation that states the standard properties that we can reach by the $itemproperties$ property.

        <CustomParameters>
          <CustomParameter Name="$itemproperties$" Value="CustomTool" />
          <CustomParameter Name="$CustomTool$" Value="ARWrapperGenerator" />
        </CustomParameters>
    Monday, June 22, 2009 5:50 PM

Answers

  • Hello,

    We could substitute project item's properities in the node "ProjectItem" by setting the "ReplaceParameters" to "true".  A little special, to specify the BuildAction,  we should use the property "ItemType", i.e.:

    <ProjectItem SubType="" TargetFileName="$fileinputname$.YYY" 
    
    ReplaceParameters="true" ItemType="Embedded Resource" 
    
    CustomTool="ARWrapperGenerator">MyFile.YYY</ProjectItem>

    If I misunderstood you, please feel free to let me know.

    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.
    • Proposed as answer by Paul Reisert Friday, June 26, 2009 5:59 AM
    • Marked as answer by Wesley Yao Monday, June 29, 2009 9:59 AM
    Wednesday, June 24, 2009 10:47 AM

All replies

  • Hello,

    We could substitute project item's properities in the node "ProjectItem" by setting the "ReplaceParameters" to "true".  A little special, to specify the BuildAction,  we should use the property "ItemType", i.e.:

    <ProjectItem SubType="" TargetFileName="$fileinputname$.YYY" 
    
    ReplaceParameters="true" ItemType="Embedded Resource" 
    
    CustomTool="ARWrapperGenerator">MyFile.YYY</ProjectItem>

    If I misunderstood you, please feel free to let me know.

    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.
    • Proposed as answer by Paul Reisert Friday, June 26, 2009 5:59 AM
    • Marked as answer by Wesley Yao Monday, June 29, 2009 9:59 AM
    Wednesday, June 24, 2009 10:47 AM
  • Wow, that's the way I was envisioning it working originally, just couldn't find the documentation. I'll try to test out this methodology soon and report back my results.
    Wednesday, June 24, 2009 3:01 PM
  • I tested Wesley's method and it works out perfectly.  This is a great way if you want to specify the custom Build Action in the template initially.

    If, however, you want to change the BuildAction using a ProjectItem object, or change it depending on decisions in your code, a suitable way is outlined here: http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/bd74f1bc-2c60-4f9c-b29f-e50bf16aadfc

    Alternatively, I guess you could also unload the project and change the itemtype anyways, but that's no fun. :p

    Best,
    Paul Reisert
    • Edited by Paul Reisert Friday, June 26, 2009 6:47 PM Typo!
    Friday, June 26, 2009 6:33 AM
  • Adding ItemType doesn't do anything for me. I did the following in the .vstemplate file

    <

     

    TemplateContent>

    <

     

    ProjectItem TargetFileName="$fileinputname$.xyz" ReplaceParameters="true" ItemType="Compile">myfile.xyz</ProjectItem>

    </

     

    TemplateContent>

    The BuildAction still defaults to be "Content". And ItemType gets a warning saying "The ItemType attribute is not declared." Did I do something wrong?

    Thursday, July 23, 2009 10:21 PM
  • It didn't work for me either:

    <ProjectItem SubType="Designer" TargetFileName="$fileinputname$View.xaml\$fileinputname$View.Styles.xaml" ReplaceParameters="true" ItemType="Content">View.Styles.xaml</ProjectItem>

     

    Does the CustomTool attribute need to be set ?

    Sunday, October 17, 2010 8:39 AM