locked
Visual Studio 2010: ProjectItem parameters SubType and ItemType in VSTemplate file have no effect RRS feed

  • Question

  • Hi,

    I successfully created a custom project template for Visual Studio 2010. 

    I then added two item templates for my custom file types.  Using the following XML code in a vstemplate file, the FileNode being created (when doing Add->New Item... and selecting my template) is set to ItemName="Content", Item.ItemType="Content" and SubType="Content".  So it seems to be completely ignoring the values in my vstemplate file.  Am I doing something wrong?

    <VSTemplate Version="2.0.0" Type="Item"
        xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
      <TemplateData>
        <Name>MyCode Header</Name>
        <Description>MyCode header file.</Description>
        <Icon>MyCodeHeader.ico</Icon>
        <ProjectType>MyCode</ProjectType>
        <DefaultName>Header.mch</DefaultName>
      </TemplateData>
      <TemplateContent>
        <ProjectItem TargetFileName="$fileinputname$.sch" ReplaceParameters="true" SubType="" ItemType="Compile">MyCodeHeader.mch</ProjectItem>
      </TemplateContent>
    </VSTemplate>
    


    Thanks.

    Wednesday, September 21, 2011 5:02 PM

All replies

  • Hi cage1976,

    Based on my knowledge, the <ProjectItem> only has the following attributes:

    1.       OpenInEditor;

    2.       OpenInHelpBrowser;

    3.       OpenInWebBrowser;

    4.       OpenOrder;

    5.       ReplaceParameters;

    6.       TargertFileName;

    It doesn’t have SubType attribute

    You can refer to the following articles:

    How to: Manually Create Project Templates:

    http://msdn.microsoft.com/en-us/library/ms185291.aspx .

    How to: Create Project Templates:

    http://msdn.microsoft.com/en-us/library/xkh1wxd8.aspx

     

    Best regards,

    Lucy


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, September 23, 2011 9:08 AM
  • Hi Lucy,

    Thanks for the reply.  However, those articles are for Project Templates (which I have working) and I was asking about Project Item templates.  See this link:

     

    http://msdn.microsoft.com/en-us/library/ms171408.aspx

     

    Thanks


    • Edited by cage1976 Friday, September 23, 2011 10:03 AM
    Friday, September 23, 2011 10:02 AM
  • Hi cage,

    Thank you for your reminding.

    What type of your application?

    If it is a web application, I found there is a member submitted the following issue to the Microsoft connect.

    ProjectItem "SubType" property is no longer available for web applications

    http://connect.microsoft.com/VisualStudio/feedback/details/114479/projectitem-subtype-property-is-no-longer-available-for-web-applications

    >> <ProjectType>MyCode</ProjectType>

    The projecttype should be CSharp,VisualBasic,Jsharp or Web

    Please refer to http://msdn.microsoft.com/en-us/library/ms171408.aspx

     

    Best regards,

    Lucy


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, September 26, 2011 10:18 AM
  • Hi Lucy,

    This is for a custom project type for my own programming language, which is why I use MyCode in place of CSharp, VisualBasic, etc for the ProjectType.  Is this not allowed?

    I started this using the Ook! sample.  I managed to fix this in code by overriding AddFileToMsBuild in my ProjectNode derived class.  See code below for this function.  Still not sure why the xml isn't working, unless somehow my template project has been set to a web project?  Is there some way to make sure project templates act like C++ projects?  I can't get files to be added as links either when I use the project templates so this is possible I guess?

    Thanks,

            protected override ProjectElement AddFileToMsBuild(string file)
            {
                ProjectElement newItem;
                //  Make filename relative
                string itemPath = BaseURI.MakeRelative(new Url(file));
    
                //  Code files set to Compile, everything else set to None
                if (IsCodeFile(itemPath))
                {
                    newItem = this.CreateMsBuildFileItem(itemPath, ProjectFileConstants.Compile);
                    newItem.SetMetadata(ProjectFileConstants.SubType, null);
                }
                else
                {
                    newItem = this.CreateMsBuildFileItem(itemPath, ProjectFileConstants.None);
                    newItem.SetMetadata(ProjectFileConstants.SubType, null);
                }
    
                return newItem;
            }
    
    


    Monday, September 26, 2011 10:55 AM
  • Hi cage,

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Thank you for your understanding and support.

     

    Best regards,

     


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, September 27, 2011 8:15 AM
  • Hi,

    Got these refereces, hope they could make some help,

    http://msdn.microsoft.com/en-us/library/ms247069(v=VS.100).aspx
    http://msdn.microsoft.com/en-us/magazine/cc188697.aspx

    Also you could get a more in-depth level of support from http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone to better meet your needs if necessary.

    Regards

    Friday, January 6, 2012 5:48 AM
  • Hi all,

    Lucy, please take care that there are TWO types of "ProjectItem":

    http://msdn.microsoft.com/en-us/library/ys81cc94(v=vs.110).aspx (Parent = Project)

    http://msdn.microsoft.com/en-us/library/ms171408(v=vs.110).aspx (Parent = TemplateContent)

    I think cage1976 is talking about the second one.

    Friday, January 4, 2013 12:51 PM