Project Templates Error RRS feed

  • Question

  • User-411071024 posted

    I am implementing my own custom project templates (as I am upgrading one of my .NET aplications to 2.0). I followed the steps required to make a custom project template using the "Export Template" wizard. These steps are mentioned here:


    A static template was created successfully. But I need to the files' names to be changed dynamically according to the project name. So I tweeked the "MyTemplate.vstemplate" in the template ZIP file; the change is similar to this:

    <ProjectItem TargetFileName="$safeprojectname$.cs">Class1.cs</ProjectItem>

    as mentioned in:

    Now, when I try to use the template I get a popup error message saying "Unable to copy the file Class1.cs from the project template to the project. Can't find the file <path to temp folder>\Class1.cs"

    I am not sure what the problem is. A [B] on me for anyone who can help.

    Thanks in Advance...

    Wednesday, November 30, 2005 6:23 AM

All replies

  • User-1634877164 posted
    Hi InSorrows,

    Here is a blog post I made about how to create a template for ASP.NET pages in VS 2005: http://weblogs.asp.net/scottgu/archive/2005/09/09/424780.aspx

    Does this help?


    Thursday, December 1, 2005 3:04 AM
  • User-411071024 posted
    Hi Scott,

    Thanks for taking the time to reply.

    Unfortunately, my problem starts at the point where the example you mentioned in your blog ends.

    In your example, suppose you want to change not only the class name but also the name of the aspx page (i.e something other than default.aspx). You would extract the MyTemplate.vstemplate file and tweak it as such:

    <ProjectItem TargetFileName="$safeprojectname$.aspx">Default.aspx</ProjectItem>

    And then add it to the zip archive containing the template files....

    And thats's when troubles begin for me once I try to create the template as mentioned in the original post.

    I'd appreciate your feedback on this.

    Thursday, December 1, 2005 8:15 AM
  • User-1791038673 posted

    From your description this looks like a bug.  I'll try to reproduce here and let you know what I find.

    Thursday, December 1, 2005 5:23 PM
  • User-411071024 posted

    Sorry to re-iterate the request, but has anybody tried to reproduce this scenario yet? I hope to get some feedback on this.

    Many thanks to those who replied and to those who will...-hopefully-[*-)]


    Saturday, December 3, 2005 11:01 AM
  • User-1791038673 posted

    I can repro the message you see with an item template.  When I try a project template I'm getting errors modifying contents of the ZIP file, saying it's corrupted.  The severity of this potential bug will be to determine if it fails or succeeds with client projects.

    How are you modifying contents of the ZIP archive?  Are you un-zipping the contents, and then creating a new archive, or are you dropping and replacing the template file directly onto the ZIP archive as you would a folder?

    Tuesday, December 6, 2005 7:24 PM
  • User-411071024 posted

      First, thanks a bunch for the reply...

      If this proves to be a persistent bug, then this is a dreadful news...

      As for the unzipping mechanism. I simply unzip the archive, tweak the template files and then use Windows's "send to compressed folder" to re-create the archive. I, however, noticed something unusual...When Visual Studio generates the Archive (.zip) file, its size as an example would be 11KB. When I unzip and rezip again - even without changing any file - the resulting .zip file will have a size of 8KB !!

      Maybe this bug is related to how VS2005 creates the .zip file in the first place.....what do you think the appropriate course of action should be...???

    Tuesday, December 6, 2005 11:36 PM
  • User-1791038673 posted

    There is a known bug in the way we compress files, and the error I was seeing about adding and removing files directly from the ZIP archive was Postponed.

    I'm still investigating the original error you are seeing with the team that owns Templates, and I'll try to reply some time tomorrow.  Thanks for your patience.

    Thursday, December 8, 2005 8:14 PM
  • User-1791038673 posted

    I tested this for another hour tonight, and I'm seeing the original bug you report for a Windows client project, but not for a web forms project. 

    In my Windows client project I created a new default VB Windows application, exported, modified the name of form1 with the project safe name, and I can't create a new client project based on that template.  Next I exported a default web forms project, modified the vstemplate file and renamed default.aspx with $safeprojectname$ as you describe, and now I can create a new web site where the default name is the name I give the project in New Web Site.

    There's obviously a bug here, and I'd like to narrow it down.  Can you try to create a new web site with the "ASP.NET Web Site" template, both VB and C#, and see if either of them allow you successfuly create a new web site after you modify the ZIP template file?  And can you try to do the same by exporting the default Windows Application and changing "form1" to "$safeprojectname$"?  And let me know if you can create a new Windows app with the modified template. 

    Thanks for your feedback

    Monday, December 12, 2005 12:03 AM
  • User-411071024 posted

    Hi Dan,

    I applied the test on a number of different project types. Of course the test is whether or not I can change at least one file name dynamically using the $safeprojectname$ token following the afore-mentioned procedures. Here is the resulting test matrix:

    Project Type              Language        PASS
    ------------              --------           ----
    ASP.NET website          VB                  Y
    ASP.NET website          C#                  Y
    Windows Application      VB                  N
    Windows Application      C#                  N
    Class Library                 VB                  N
    Class Library                 C#                  N
    Empty Project               VB                  N
    Empty Project               C#                  N
    Console Application        VB                  N
    Console Application        C#                  N

    (Y=Yes, N=No)

    Unfortunately my work relies on being able to customize the Empty Project Template.


    I hope this helped.

    Thanks for following up on this issue.

    Monday, December 12, 2005 11:48 AM
  • User-1791038673 posted

    I contacted the Templates team and it appears this is not a product bug.  The MSDN article left out an important step.  You must also modify the project file name.  Can you try these steps and let me know if it works for you?

    1)       Rename the file inside the template zip file as $safeprojectname$.cs<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

    2)       In the .vstemplate file simply put the following  <ProjectItem ReplaceParameters="true">$safeprojectname$.cs</ProjectItem> (Notice for this <TargetFileName> is not used )


    Monday, December 12, 2005 2:48 PM
  • User-411071024 posted

     Hi Dan,

     Firstly, happy holidays for everybody...

     I applied the steps you mentioned but unfortunately, I got the same error. Please tell me if it worked when you tried it.

     Thanks in advance for the reply...

     P.S. what about the known bug in the zipping mechanism you refered to previously in this thread? Could the two issues be related?

    Tuesday, December 27, 2005 7:33 PM
  • User-1791038673 posted
    The team that owns the template code told me it worked.  I'll try it myself this week and reply back to the post.
    Tuesday, January 17, 2006 9:31 PM
  • User-1791038673 posted

    I was able to get the replacement working for a C# Windows Application, where the default Form1 is named the same as the Project.  First, I created a new C# Windows Application. I didn't change any file content or file names.  Here's what I changed after unzipping the exported template file:

    In MyTemplate.vstemplate I changed

          <ProjectItem ReplaceParameters="true" TargetFileName="Form1.cs">Form1.cs</ProjectItem>
          <ProjectItem ReplaceParameters="true" TargetFileName="Form1.Designer.cs">Form1.Designer.cs</ProjectItem>


          <ProjectItem ReplaceParameters="true" TargetFileName="$safeprojectname$.cs">Form1.cs</ProjectItem>
          <ProjectItem ReplaceParameters="true" TargetFileName="$safeprojectname$.Designer.cs">Form1.Designer.cs</ProjectItem>

    In the project file WinApp1.csproj I changed

        <Compile Include="Form1.cs">
        <Compile Include="Form1.Designer.cs">


        <Compile Include="$safeprojectname$.cs">
        <Compile Include="$safeprojectname$.Designer.cs">

    Monday, January 30, 2006 11:15 PM
  • User-411071024 posted

    Hi Dan,

    Actually, tweaking the .csproj solves the issue. Thanks for the insight. It seems though that we always have to start with either a Console or Windows application project - since they have a .csproj file - and then customize it to our requirements.

    I hope that these issues will be reflected soon in the MSDN documentation.


    Wednesday, February 1, 2006 12:31 AM
  • User1381837036 posted
    This thread is very helpful and seemingly got me over the hump until I hit this the following issue.  I apologize for tagging it on here...but this thread provides the context for the problem.

    Having successfully renamed the files in the project, I tried to rename the assembly name in the csproj file.  I created a custom parameter with the name $safeasemblyname$ and assigned a value.  I then plugged this into the assemblyname tag in the file.  It failed.

    For giggles, I plugged the variable onto the end of the tag just above the assembly name (the namespace tag) and it appends just fine.

    Is there some reason that the assemblyname tag is protected or cannot be changed on the fly?

    Wednesday, February 8, 2006 1:54 PM