Thursday, November 11, 2010

"Unable to copy the file..." error when dynamically changing item names in a Visual Studio project template

I created a Visual Studio project template including creating a wizard using the instructions here: http://msdn.microsoft.com/en-us/library/ms185301.aspx. As part of the template I wanted to parameterise the name of items within the template - which I found the instructions to do so here: http://msdn.microsoft.com/en-us/magazine/cc188697.aspx#S6 (well not instructions, but what manual updates are required to the .vstemplate file - specifically Class1.cs).

After making this update (where $fileinputname$ is now the parameter which determines the file name, the following error was thrown..."Unable to copy the file Class1.cs from the project template to the project. Can't find the file \Class1.cs".

After some quick Googling, I found the solution in the following thread: http://forums.asp.net/t/941773.aspx. What would have been benefical to me is if I had found this article first http://msdn.microsoft.com/en-us/library/ys81cc94.aspx (as mentioned in the forum) - where it now contains the steps required to update rename files with parameters (i.e update the compile include to have the parameter name, rather than the original file name before it is renamed). The MSDN article fails to mention this.