Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
West Wind WebSurge - Rest Client and Http Load Testing for Windows

Project and Item Templates in VS.NET 2005 are easy!


:P
On this page:

Finally! It’s actually reasonably easy to create project templates in VS.NET 2005. Microsoft has made the process of creating custom project and page templates relatively easy by providing an export Wizard that lets you basically build your project as you want it and have VS create a project template from it. The Wizard sits on the File Menu under Export Template and lets you select to create a project or Item Template.  Project Templates grab the current project as is and package it, while the Item Template Wizard asks you to select the files you want to include in your template. In both cases you can embed a few custom string expansion macros that give you the name of the project and file and a few other things.

 

The Wizard zips up your files into a ZIP along with a template configuration file that describes the template to VS.NET.

 

All that’s left to do is stick the Zip file into the VS.NET templates directory and voila your project templates are visible and reusable. The file needs to be copied into:

 

D:\Documents and Settings\ricks\My Documents\Visual Studio 2005\Templates\ItemTemplates

 

or ProjectTemplates. The Zip file apparently can go anywhere in this hierarchy to become visible.

 

I just did this for Web Connection. Web Connection is actually not a .NET application, but it uses VS.NET for editing of script page, taking advantage of the visual designer and the control editors. Even so there’s tremendous advantage there in that I can now copy all the required support files in one fell swoop from within Visual Studio (instead of Web Connection’s own Project Wizard which does the same). But the real benefit for Web Connection comes from the Page Template which allows removing some of the default XHTML gunk, default code block that isn’t used, allows adding of a Web Control reference and adding a default custom WebPage control reference into the page right from the start. This saves several steps that take a bit of explaining usually, so it’s much nicer to have this done in a single step!

 

 

One thing that I couldn’t figure though is how to add a WebControl library to the Toolbox, but I suspect that’s probably not as easy <g>… another day for that.

 

This is a big step forward and provides oodles of benefits for any vendor shipping source code related tools as you can now much more easily provide custom items that automatically include necessary references to projects or namespaces in classes etc.

 

But it’s also great for personal day to day use – I immediately went in and modified my default class and ASP.NET page definitions to match my needs because it’s so easy to do now.

 

And to make things even more surprising this stuff is actually – gasp - documented reasonably well (not the process, just the reference):

 

http://msdn2.microsoft.com/en-us/library/6db0hwky

 

Scott Guthrie also posted about ASP.NET project templates a few weeks back which got me started on this earlier.

 

Kudos for this cool feature.


The Voices of Reason


 

Havagan
October 06, 2005

# re: Project and Item Templates in VS.NET 2005 are easy!

Amen to that! (That's geek fervor and not religious fervor.) This is a big plus for me since I tend to create quite a few custom templates in VS.NET 2003.

Now the only problem is finding the patience to wait while the government bureaucracy grinds out the go ahead to upgrade!

Gavin
December 06, 2005

# re: Project and Item Templates in VS.NET 2005 are easy!

Hi,

The export template menu item is not visible for me in the menu bar (under "File")?

I am using Visual Studio 2005 Team Suite edition. This is the Visual Studio 2005 August Community Technology Preview beta edition. I’m also coding in C#....

Seems strange to me that something that is in the Professional edition is not in the Team Suite....

Any ideas? Going around in circles here trying to do something that from your article looks easy :(

Thanks!
G

Rick Strahl
December 06, 2005

# re: Project and Item Templates in VS.NET 2005 are easy!

I'm also running Team Suite and the Export Template option is definitely there. Make sure you have a page or project open.



Gavin
December 07, 2005

# re: Project and Item Templates in VS.NET 2005 are easy!

Hi,

Seems I needed to customize my IDE.... The post here solved the issue:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=160020&SiteID=1&mode=1

Thanks!
G

Erik
December 27, 2005

# re: Project and Item Templates in VS.NET 2005 are easy!

I am trying to get a template to use an IWizard Extension, but when I get everything in the correct folders and try to start a new project (or even item) based on my templates VS 2005 just shows the following message:

"Error: this template sttempted to load an untrusted component 'myIwizard, Version 1.2.0.0, Culture=neutral, PublicKeyToken=3eb1b29301739d55'."

This happens even if I don't strongly name the assembly. I get this even trying to use the template provided as an example in the IWizardStarterKit.

I was just curious if anyone else had experienced this - or knows of a way to resolve it?

Thanks.
Erik.

ZW
January 19, 2006

# re: Project and Item Templates in VS.NET 2005 are easy!

Have you tried to modify the exported template file? What I did was unzip the file and rezip it with a different name. After I put the new one in the template folder, the VS2005 could not see it. Any suggestions?

Also, how to create a template solution with multiple projects? The only way seems to create the zip file myself. But the new zip file can be seen by VS2005, what to do?

Thank you.

ZW

Red
June 08, 2006

# re: Project and Item Templates in VS.NET 2005 are easy!

I have the same problem ... I tried to create a template with two files - something like .aspx and .aspx.cs files bu VS does not allow to select more than one file for the template ... so i checked the template file for aspx and according to it create my own template ... but it didn't work ... so I tried to just unzip the template file and zip it again and it disappeared ... does anybody have a solution ?

Steve
June 29, 2006

# re: Project and Item Templates in VS.NET 2005 are easy!

I've created a Web Application template that I intended to distribute to our departments developers. I've tested it by giving the .zip template file to a couple of developers but it isn't working properly. The template shows up just fine, but when they select "HTTP" in the location dropdown the location textbox, "Browse" button and "OK" buttons are grayed out and disabled. It works fine on my machine, but not on anyone elses machine.

What could be the problem??

Steve
June 29, 2006

# re: Project and Item Templates in VS.NET 2005 are easy!

BTW here is the contents of the .vstemplate file. It shows the EnableLocationBrowseButton setting is set to "True", but it's shows as disabled.

<VSTemplate Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
<TemplateData>
<Name>ESDWebApplication</Name>
<Description>ESD Web Application Template</Description>
<ProjectType>Web</ProjectType>
<ProjectSubType>VisualBasic</ProjectSubType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
<DefaultName>ESDWebApplication</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
<Icon>__TemplateIcon.ico</Icon>
</TemplateData>
<TemplateContent>
<Project TargetFileName="ProjectName.webproj" File="ProjectName.webproj" ReplaceParameters="true">
<Folder Name="App_Code" TargetFolderName="App_Code">
<ProjectItem ReplaceParameters="true" TargetFileName="ApplicationDML.vb">ApplicationDML.vb</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="clsWebDML.vb">clsWebDML.vb</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="clsWebDMLJHAToday.vb">clsWebDMLJHAToday.vb</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="modADORoutines.vb">modADORoutines.vb</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="modASP.NETRoutines.vb">modASP.NETRoutines.vb</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="modGlobal.vb">modGlobal.vb</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="modWebErrorHandling.vb">modWebErrorHandling.vb</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="modWebGlobalFunctions.vb">modWebGlobalFunctions.vb</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="mWebDataGrid.vb">mWebDataGrid.vb</ProjectItem>
</Folder>
<Folder Name="App_Data" TargetFolderName="App_Data" />
<ProjectItem ReplaceParameters="true" TargetFileName="AssemblyInfo.vb">AssemblyInfo.vb</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="Default.aspx">Default.aspx</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="Default.aspx.vb">Default.aspx.vb</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="Error.htm">Error.htm</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="Global.asax.vb">Global.asax.vb</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="NoRights.htm">NoRights.htm</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="web.config">web.config</ProjectItem>
</Project>
</TemplateContent>
</VSTemplate>

GB
July 12, 2006

# re: Project and Item Templates in VS.NET 2005 are easy!

Has anybody tried to create MultiProject Templates and if so could they post a walkthrough?
Thanks a lot

Mike
September 16, 2006

# re: Project and Item Templates in VS.NET 2005 are easy!

Any hint on getting the "Export Template" menu item to be visible?
I'm using VS2005 Professional.

Rick Strahl
September 16, 2006

# re: Project and Item Templates in VS.NET 2005 are easy!

It may have to do with your developer profile. Some of the profiles don't show all the options.

I'm using the C# profile and it's there and I suspect the Web Profile and VB profiles also have it enabled

Brad
September 26, 2006

# re: Project and Item Templates in VS.NET 2005 are easy!

Multi-project template example: http://dotnetjunkies.com/VSContent/95B0E1C3-66F2-48FC-835C-098EE632DD85.dcik

How about doing a multi-template example that includes 2 projects: an web project and a web setup project? For an encore, you could add a third project: a web deployment project (http://msdn.microsoft.com/asp.net/reference/infrastructure/wdp/).

I've yet to figure out how to get either of these combinations to work.

Richard Purchas
October 11, 2006

# re: Project and Item Templates in VS.NET 2005 are easy!

If you can't see the Export Templates option in the File menu then do this:
- export/backup your VS.Net settings (via Tools ==> Import and Export Settings)
- import your C# / VB settings from the default list of settings (this will be shown to you on the 2nd or 2rd wizard step)

Tony Taylor
October 19, 2006

# re: Project and Item Templates in VS.NET 2005 are easy!

If Export Template is missing from your File menu, open Tools -> Customize... and then the Commands tab. Choose the File menu on the left-hand list and drag the Export Template... command onto your File menu.

My problem is that Export Template... is disabled in my File menu. Any ideas?

# DotNetSlackers: Project and Item Templates in VS.NET 2005 are easy!


anon
May 12, 2009

# re: Project and Item Templates in VS.NET 2005 are easy!

MS's templating system is next to f**ing useless. I have been wroking with VS since its inception. and i have to say that most of what they produce is bells and whistles.

you get a new feature added, and you think great ... but once you scrattch under the seruface you find that beyond doing the most mickey mouse operations it is pretty bl00dy useless. this is just another example.

trying passing perameters around in a multi project template.

unnnnbelievable

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024