Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > Parameterising ProjectType in VS2005 templates
 

Parameterising ProjectType in VS2005 templates

Is it possible to parameterise the ProjectType node in studio 2005 template files?

The problem I have is like this, our development team write in both C# and VB and I want to write a guidance package to help speed up development in both code camps.

The classes withinmy package are generated using code (CodeDomProvider, etc) so I can squirt out class code in either language Ok. But Ihave hita problemwhen it comes tosolution & project files as they are templated and have the language set in the ProjectType element.

Do I need to write 2 packages with the majority of stuffexactly the samebut different solution & project templates or am I missing a trick here?

Can I either:

  • parameterise the ProjectType element in the solution & the project templates
  • create the solution & project files using code
  • create the solution & projects without a ProjectType element and infer the language insome other way

Hopefully someone can offer some assistance here as I don't really want to have to duplicate the solution & project files if I don't have to :)

Thanks,
Sara

Sara_H  Tuesday, October 03, 2006 10:29 AM

Hi Sara,

You definitely not need to write two almost identical packages for this.

Although you can use GAX to parameterise the .vstemplate and specify the ProjectType (by getting its value from a recipe argument for instance) I believe a better approach would be to have a different templates for each language (inside the same package), one for VB & and another one for C#; this means duplicate .proj and vstemplates files which may seem odd at first but is really an advantage once you start customizing the projects, as you will need to customize other settings besides ProjectType, like which msbuild targets to import for each project file, etc.

Does this help?

-Victor.

vga  Tuesday, October 03, 2006 10:44 PM

Hi Sara,

You definitely not need to write two almost identical packages for this.

Although you can use GAX to parameterise the .vstemplate and specify the ProjectType (by getting its value from a recipe argument for instance) I believe a better approach would be to have a different templates for each language (inside the same package), one for VB & and another one for C#; this means duplicate .proj and vstemplates files which may seem odd at first but is really an advantage once you start customizing the projects, as you will need to customize other settings besides ProjectType, like which msbuild targets to import for each project file, etc.

Does this help?

-Victor.

vga  Tuesday, October 03, 2006 10:44 PM

Thanks for that idea Victor, I'm giving this a go right now on our main guidance package.

Sara

Sara_H  Wednesday, October 04, 2006 1:11 PM

Great, let us know if you find any issues regarding this.

thanks,
-Victor.

vga  Thursday, October 05, 2006 12:05 AM

Hi Victor,

I've managed to set the guidance package to use different projects Ok by creating the relevant solutions files and sharing my code generating functionality. So I can now generate projects and code in C# or VB depending on which package was used (hurray!).

BUT ... my glee was short lived as I've hit a bit of an issue with taking this approach

The code generation files I'm using create a CodeCompileUnit using a CodeNamespace object as the base to build on. This works fine until your combine this with the fact that VBautomatically appends any namespace defined in code files to any default namespace defined in the project! (And we have default namespaces defined) If I remove the namespace object I cannot create a CodeCompileUnit as it requires a CodeNamespace object in order to work properly.

Is there a way I can either tell the code DOM tonot generate the namespace declaration codefor VB or can I use parameterised T4 templates to achieve the code generation instead?

If I should be using T4 templates, can you explain how I can parameterise the template names?I appreciate that I will need different templates for C# and VBbut I don't want to have duplicate all my receipes where the template names are hard coded. I ask as I havealready looked at the TextTemplateAction object and it only accepts a template name as a string rather than an expression to evaluate - and I cannot inherit from this object and extend it as it is sealed.

Further help gratefully received
Sara

Sara_H  Tuesday, October 10, 2006 12:11 PM

You can use google to search for other answers

Custom Search

More Threads

• Unable to uninstall or reinstall SCSF
• $ProjectName$ passed into a template creator is not expanded
• Flailing with Guidance Automation Extensions and Web Service Software Factory and subsequent uninstall
• Add View context menu not displayed for some projects
• Add View(..) context menu does not show
• no help for asmx web service factory
• A Bug in DteHelper?
• Cannot Load smart client guidance in VS2008
• How can i show something like a table in VB.NET 2005 form ?
• Need the June GAX MSI