*.vstemplate for and *.csproj/*.vbproj must be kept in sync.

I just spent half the day trying to figure out why I couldn't add files (ProjectItems) to the project template I was making. It all started out good. I created a new Xxx.cs.vstemplate, Xxx.csproj and Properties\AssemblyInfo.cs files. Rebuilt my GAT package started an new instance of VS and created the project. At this point I was very happy with myself!

I then added a Constants.cs file to the Xxx.cs.vstemplate file rebuilt everything and tried to create the new project with the new file in it. Woops, it created the same exact project without the Constants.cs file. I scratched my head and worked for the next couple hours trying to figure out what I had screwed up.

There are a couple of things that go into making this problem. First, the actual project files are created in a temp directory and then copied to the actual directory when the wizard has finished. The Constants.cs file was correctly being built (at least I think because I could never get to the temp directory before the whole thing was deleted).

The second thing is that at the end of the wizard it calls the _Solution.AddFromTempate (which is documented in the VSIP documentation). This takes the actual project file (*.csproj or *.vbproj) and copies just the things in it to the project destination directory. This is why the project was being created but the Constants.cs file was never being copied because I hadn't added Constants.cs to the list of items in the *.csproj file.

So the lesson to learn from this is not to be a bad person like me, update your *.csproj/*.vbproj and your *.vstemplate at the same time and life will be good!

[1626 byte] By [JLeBert] at [2008-1-28]

Visual Studio

Site Classified