views:

122

answers:

1

Here's what I'm trying to achieve. I have a number of projects in C# and VB which I wish to export as template projects as part of my automated build process. Exporting templates is easy to do interactively, but I need to do it as part of my automated build process. Further, the template projects must actually be built prior to exporting them, so that they are guaranteed to compile when the end user uses the template. [I know that template projects don't usually compile, but I have solved that problem, so for the purposes of this question, we can take it as read that the template projects will compile successfully].

I plan to use the MSBuild Community Tasks to zip up my final exported template project. However, I can't place this action in the template project itself, because that action would then be exported as part of the template and that's not what I want to happen.

So my thought is that I could create a new seperate MSBuild project, that examines the other template projects, discovers what files are in them, adds a predefined MyTemplate.vstemplate file, zips up those files and "walla", there's my exported template.

So far so good. The only problem is, I'm a complete MSBuild noob and I'm having trouble getting started. Please, I would value any suggestions on how to accomplish this.

I'm painfully aware that this is almost a "do my job for me" type of question, my defense is that (a) it's not actually my job and (b) I've tried to do my MSBuild homework and the inspiration just isn't flowing.

+1  A: 

Short of "doing it for you" (), how about I show you how it's done elsewhere? I just did the same thing myself over yonder:

http://github.com/AArnott/dotnetopenid/commits

Specifically, the projecttemplates/WebFormsRelyingParty web project is transformed into a project template by the build.proj file's BuildProjectTemplates target.

My strategy is to have an ordinary (compilable) C# web project that I work on. I also have a .vstemplate file in that folder that's not added to the project, but is around so I can make changes. Then during my build, I have MSBuild build the web site, copy the result (excluding most of the products of the build of the web site) to a temporary location. During the copy, I have a custom MSBuild task that replaces my web application name with $safeprojectname$ in all the source files, since this is what the VS project template creator does. It also copies in the icon to use for the template. Finally, it zips it up and puts the .zip file in my output directory.

Andrew Arnott