locked
Passing CustomParameters to ProjectItems.AddFromTemplate in VS2008 RRS feed

  • Question

  • Hi, 

    I am sure that I have seen that this is possible in VS2008 (but undocumented) by appending "|$custparamname1$=mysusbstition1|$custparamname2$=mysusbstition2" to file name.

    e.g. 
     item.ProjectItems.AddFromTemplate( templateFilename + "|$custparamname1$=mysusbstition1|$custparamname2$=mysusbstition2", "NewFile");

    However, when I try to do this in my VS2008 Addin, I get an exception 'Cannot find file "C:\Documents and ...\MyTemplateItem.zip\MyTemplate.vstemplate|$custparamname1$=mysusbstition1|$custparamname2$=mysusbstition2". Of course, it works fine without the extra string even setting values for customparameters from the ".vstemplate".

    Any ideas or pointers to documentation?

    Thanks,
    Ian. 
    Friday, January 29, 2010 1:02 PM

Answers

  • Hi Ian,

    In the quick response from our product team:

    In existing C#/VB projects, this custom parameter mechanism is supported only in the Solution.AddFromTemplate() automation model method. Unfortunately, it is not supported on the ProjectItems.AddFromTemplate() method.
    e.g. When trying to add a new project into the solution with Solution.AddFromTemplate() method, we could specify the target framework version by appending it to the template name:

    …\Common7\IDE\ProjectTemplatesCache\CSharp\Web\1033\WebApplicationProject20.zip\WebApplicationProject20.vstemplate|$targetframeworkversion$=3.5

    However, In a custom project type, when adding items into the project, ProjectItems.AddFromTemplate() method could also support this custom parameter mechanism.  So I think that article you saw before should be introducing this mechanism in a custom project.  Could you please ensure of it?

    By the way, I learned something new today, thank this thread. :)

    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 Wesley Yao Wednesday, February 3, 2010 3:10 AM
    • Marked as answer by Ian Mardlec Wednesday, February 3, 2010 10:48 AM
    Wednesday, February 3, 2010 3:09 AM

All replies

  • Hi Ian,

    Thanks for your post.
    I never know that ProjectItems.AddFromTemplate() can specify the custom parameters in .vstemplate, where did you get this idea?

    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.
    Monday, February 1, 2010 9:13 AM
  • Hi Wesley

    I am certain that I saw it as a note in the middle of a article (on a slightly different topic), that I cannot for the life of me find again (Carlos maybe??). Even stranger, I am 95% sure that I even had it working a few months ago...

    Regards,
    Ian.
    Monday, February 1, 2010 4:13 PM
  • Hi Ian,

    Thanks for your feedback.
    So it should be something internal that I don't know, hope Carlos(or other guys?) would quickly take a note of this thread and introduce this 'egg' to us.  Because we can't see the back handling in this function(native COM code), I'm going to ask our product team to see if it's possible.

    Regards,
    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.
    Tuesday, February 2, 2010 3:07 AM
  • Hi Ian,

    In the quick response from our product team:

    In existing C#/VB projects, this custom parameter mechanism is supported only in the Solution.AddFromTemplate() automation model method. Unfortunately, it is not supported on the ProjectItems.AddFromTemplate() method.
    e.g. When trying to add a new project into the solution with Solution.AddFromTemplate() method, we could specify the target framework version by appending it to the template name:

    …\Common7\IDE\ProjectTemplatesCache\CSharp\Web\1033\WebApplicationProject20.zip\WebApplicationProject20.vstemplate|$targetframeworkversion$=3.5

    However, In a custom project type, when adding items into the project, ProjectItems.AddFromTemplate() method could also support this custom parameter mechanism.  So I think that article you saw before should be introducing this mechanism in a custom project.  Could you please ensure of it?

    By the way, I learned something new today, thank this thread. :)

    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 Wesley Yao Wednesday, February 3, 2010 3:10 AM
    • Marked as answer by Ian Mardlec Wednesday, February 3, 2010 10:48 AM
    Wednesday, February 3, 2010 3:09 AM
  • Hi Wesley

    Great response & quick. This explains exactly why my code is broken now! 

    I was modifying my AddIn, and previously it had also created a custom project, then created projectitems off that. Sooo glad that I wasn't just imagining things! :-D

    Sounds like I'll have to move to IWizard to add items with customparameter replacements then...

    Thanks a lot,
    Ian.
    Wednesday, February 3, 2010 10:48 AM