Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Studio
  4. Custom Templates

Custom Templates

Scheduled Pinned Locked Moved Visual Studio
csharpvisual-studiowpfxmlhelp
11 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • realJSOPR Online
    realJSOPR Online
    realJSOP
    wrote on last edited by
    #1

    I'm trying to create a custom temple, and I have some files in the solution that need to have the project name as their name. I have the following:

    <ProjectItem ... TargetFileName="$safeprojectname$.dll.config">test.dll.config</ProjectItem>
    <ProjectItem ... TargetFileName="$safeprojectname$.xml">test.xml</ProjectItem>

    But when I create a new project with the template, I get a Visual Studio error saying it can't copy the file because it can't find it. Anybody got any clues for me? EDIT ======================== BTW, I also tried using $projectname$ instead of $safeprojectname$, and it doesn't matter where I put either one - I still get the error. Lastly, I tried using "xyz" instead of $projectname$, and that gave me the same error. This is STUPID.

    ".45 ACP - because shooting twice is just silly" - JSOP, 2010
    -----
    You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
    -----
    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

    L J A A 5 Replies Last reply
    0
    • realJSOPR realJSOP

      I'm trying to create a custom temple, and I have some files in the solution that need to have the project name as their name. I have the following:

      <ProjectItem ... TargetFileName="$safeprojectname$.dll.config">test.dll.config</ProjectItem>
      <ProjectItem ... TargetFileName="$safeprojectname$.xml">test.xml</ProjectItem>

      But when I create a new project with the template, I get a Visual Studio error saying it can't copy the file because it can't find it. Anybody got any clues for me? EDIT ======================== BTW, I also tried using $projectname$ instead of $safeprojectname$, and it doesn't matter where I put either one - I still get the error. Lastly, I tried using "xyz" instead of $projectname$, and that gave me the same error. This is STUPID.

      ".45 ACP - because shooting twice is just silly" - JSOP, 2010
      -----
      You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
      -----
      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I'm not sure what language template or what file the above belongs in, but should you not be using $safeprojectname$ rather than test in the text portions of the above statements?

      Use the best guess

      realJSOPR 1 Reply Last reply
      0
      • L Lost User

        I'm not sure what language template or what file the above belongs in, but should you not be using $safeprojectname$ rather than test in the text portions of the above statements?

        Use the best guess

        realJSOPR Online
        realJSOPR Online
        realJSOP
        wrote on last edited by
        #3

        I tried that too, but according tot he MSDN site, I'm supposed to use the TargetFileName attribute.

        ".45 ACP - because shooting twice is just silly" - JSOP, 2010
        -----
        You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
        -----
        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

        L 1 Reply Last reply
        0
        • realJSOPR realJSOP

          I tried that too, but according tot he MSDN site, I'm supposed to use the TargetFileName attribute.

          ".45 ACP - because shooting twice is just silly" - JSOP, 2010
          -----
          You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
          -----
          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Sorry, I'm stumped then, I've not use this type of template.

          Use the best guess

          1 Reply Last reply
          0
          • realJSOPR realJSOP

            I'm trying to create a custom temple, and I have some files in the solution that need to have the project name as their name. I have the following:

            <ProjectItem ... TargetFileName="$safeprojectname$.dll.config">test.dll.config</ProjectItem>
            <ProjectItem ... TargetFileName="$safeprojectname$.xml">test.xml</ProjectItem>

            But when I create a new project with the template, I get a Visual Studio error saying it can't copy the file because it can't find it. Anybody got any clues for me? EDIT ======================== BTW, I also tried using $projectname$ instead of $safeprojectname$, and it doesn't matter where I put either one - I still get the error. Lastly, I tried using "xyz" instead of $projectname$, and that gave me the same error. This is STUPID.

            ".45 ACP - because shooting twice is just silly" - JSOP, 2010
            -----
            You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
            -----
            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

            J Offline
            J Offline
            Jeremy Rice
            wrote on last edited by
            #5

            Maybe it's choking on the fact that they're named "test". Is it finding all of the other files ok?

            realJSOPR 1 Reply Last reply
            0
            • J Jeremy Rice

              Maybe it's choking on the fact that they're named "test". Is it finding all of the other files ok?

              realJSOPR Online
              realJSOPR Online
              realJSOP
              wrote on last edited by
              #6

              That was a simple replacement because I was too damn lazy to type the actual entire file name.

              ".45 ACP - because shooting twice is just silly" - JSOP, 2010
              -----
              You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
              -----
              "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

              1 Reply Last reply
              0
              • realJSOPR realJSOP

                I'm trying to create a custom temple, and I have some files in the solution that need to have the project name as their name. I have the following:

                <ProjectItem ... TargetFileName="$safeprojectname$.dll.config">test.dll.config</ProjectItem>
                <ProjectItem ... TargetFileName="$safeprojectname$.xml">test.xml</ProjectItem>

                But when I create a new project with the template, I get a Visual Studio error saying it can't copy the file because it can't find it. Anybody got any clues for me? EDIT ======================== BTW, I also tried using $projectname$ instead of $safeprojectname$, and it doesn't matter where I put either one - I still get the error. Lastly, I tried using "xyz" instead of $projectname$, and that gave me the same error. This is STUPID.

                ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                -----
                You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                -----
                "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

                A Offline
                A Offline
                AspDotNetDev
                wrote on last edited by
                #7

                Based on this (probably what you are looking at), you also have to set ReplaceParameters to true:

                <ProjectItem ... ReplaceParameters="true" TargetFileName="$safeprojectname$.xml">test.xml</ProjectItem>

                Thou mewling ill-breeding pignut!

                A 1 Reply Last reply
                0
                • A AspDotNetDev

                  Based on this (probably what you are looking at), you also have to set ReplaceParameters to true:

                  <ProjectItem ... ReplaceParameters="true" TargetFileName="$safeprojectname$.xml">test.xml</ProjectItem>

                  Thou mewling ill-breeding pignut!

                  A Offline
                  A Offline
                  AspDotNetDev
                  wrote on last edited by
                  #8

                  Well, nevermind I guess. I just tried this and I get the same error:

                  Microsoft Visual Studio:

                  Unable to copy the file 'Go.cs' from the project template to the project. Cannot find file "C:\Users\AspDotNetDev\Local\Temp\jsdgjlkgjlk.ljksd\Temp\Go.cs".

                  According to this, it may be a Visual Studio bug. However, if it is, it exists in both 2010 and 2012 (I tried both).

                  Thou mewling ill-breeding pignut!

                  1 Reply Last reply
                  0
                  • realJSOPR realJSOP

                    I'm trying to create a custom temple, and I have some files in the solution that need to have the project name as their name. I have the following:

                    <ProjectItem ... TargetFileName="$safeprojectname$.dll.config">test.dll.config</ProjectItem>
                    <ProjectItem ... TargetFileName="$safeprojectname$.xml">test.xml</ProjectItem>

                    But when I create a new project with the template, I get a Visual Studio error saying it can't copy the file because it can't find it. Anybody got any clues for me? EDIT ======================== BTW, I also tried using $projectname$ instead of $safeprojectname$, and it doesn't matter where I put either one - I still get the error. Lastly, I tried using "xyz" instead of $projectname$, and that gave me the same error. This is STUPID.

                    ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                    -----
                    You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                    -----
                    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

                    A Offline
                    A Offline
                    Alan N
                    wrote on last edited by
                    #9

                    When I try this the error message is saying it can't find the original file, e.g. test.cs, in the temporary directory used for template expansion. After monitoring the temp folder with a filesystem watcher I can see the correctly renamed file, not the original file. So far so good as the file was supposed to be renamed. The issue is why after having renamed the file, does VS then stupidly look for the original filename. VS appears to be using the project file to decide which files it needs to copy from the temp directory to the final location. The fix is to use replaceable parameters in the project file for any renamed files. e.g. change <Compile Include="test.cs" /> to <Compile Include="$safeprojectname$.cs" /> I use the word fix rather than solution as now the modified project file is only good after the parameters have been replaced by template expansion. If you try and open it directly, VS will look for a file named $safeprojectname$.cs. Damn tricky things, these templates! Alan.

                    1 Reply Last reply
                    0
                    • realJSOPR realJSOP

                      I'm trying to create a custom temple, and I have some files in the solution that need to have the project name as their name. I have the following:

                      <ProjectItem ... TargetFileName="$safeprojectname$.dll.config">test.dll.config</ProjectItem>
                      <ProjectItem ... TargetFileName="$safeprojectname$.xml">test.xml</ProjectItem>

                      But when I create a new project with the template, I get a Visual Studio error saying it can't copy the file because it can't find it. Anybody got any clues for me? EDIT ======================== BTW, I also tried using $projectname$ instead of $safeprojectname$, and it doesn't matter where I put either one - I still get the error. Lastly, I tried using "xyz" instead of $projectname$, and that gave me the same error. This is STUPID.

                      ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                      -----
                      You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                      -----
                      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

                      A Offline
                      A Offline
                      AspDotNetDev
                      wrote on last edited by
                      #10

                      I got it working! The important missing step was to modify the .csproj file itself to account for the new dynamic filename. In my test, this was the only thing I really needed to change:

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

                      Just so I have a full example posted here, the contents of my ZIP file are:

                      Properties
                      AssemblyInfo.cs
                      Go.cs
                      Testify.csproj
                      Testify.vstemplate

                      The contents of AssemblyInfo.cs (GUID changed for security considerations):

                      using System.Reflection;
                      using System.Runtime.CompilerServices;
                      using System.Runtime.InteropServices;

                      // General Information about an assembly is controlled through the following
                      // set of attributes. Change these attribute values to modify the information
                      // associated with an assembly.
                      [assembly: AssemblyTitle("Testify")]
                      [assembly: AssemblyDescription("")]
                      [assembly: AssemblyConfiguration("")]
                      [assembly: AssemblyCompany("Microsoft")]
                      [assembly: AssemblyProduct("Testify")]
                      [assembly: AssemblyCopyright("Copyright © Microsoft 2013")]
                      [assembly: AssemblyTrademark("")]
                      [assembly: AssemblyCulture("")]

                      // Setting ComVisible to false makes the types in this assembly not visible
                      // to COM components. If you need to access a type in this assembly from
                      // COM, set the ComVisible attribute to true on that type.
                      [assembly: ComVisible(false)]

                      // The following GUID is for the ID of the typelib if this project is exposed to COM
                      [assembly: Guid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")]

                      // Version information for an assembly consists of the following four values:
                      //
                      // Major Version
                      // Minor Version
                      // Build Number
                      // Revision
                      //
                      // You can specify all the values or you can default the Build and Revision Numbers
                      // by using the '*' as shown below:
                      // [assembly: AssemblyVersion("1.0.*")]
                      [assembly: AssemblyVersion("1.0.0.0")]
                      [assembly: AssemblyFileVersion("1.0.0.0")]

                      The contents of Go.cs:

                      using System;
                      using System.Collections.Generic;
                      using System.Linq;
                      using System.Text;

                      namespace Testify
                      {
                      class Go
                      {
                      }
                      }

                      The contents of Testify.csproj:

                      <?xml version="1.0" encoding="utf-8"?>
                      <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
                      <

                      realJSOPR 1 Reply Last reply
                      0
                      • A AspDotNetDev

                        I got it working! The important missing step was to modify the .csproj file itself to account for the new dynamic filename. In my test, this was the only thing I really needed to change:

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

                        Just so I have a full example posted here, the contents of my ZIP file are:

                        Properties
                        AssemblyInfo.cs
                        Go.cs
                        Testify.csproj
                        Testify.vstemplate

                        The contents of AssemblyInfo.cs (GUID changed for security considerations):

                        using System.Reflection;
                        using System.Runtime.CompilerServices;
                        using System.Runtime.InteropServices;

                        // General Information about an assembly is controlled through the following
                        // set of attributes. Change these attribute values to modify the information
                        // associated with an assembly.
                        [assembly: AssemblyTitle("Testify")]
                        [assembly: AssemblyDescription("")]
                        [assembly: AssemblyConfiguration("")]
                        [assembly: AssemblyCompany("Microsoft")]
                        [assembly: AssemblyProduct("Testify")]
                        [assembly: AssemblyCopyright("Copyright © Microsoft 2013")]
                        [assembly: AssemblyTrademark("")]
                        [assembly: AssemblyCulture("")]

                        // Setting ComVisible to false makes the types in this assembly not visible
                        // to COM components. If you need to access a type in this assembly from
                        // COM, set the ComVisible attribute to true on that type.
                        [assembly: ComVisible(false)]

                        // The following GUID is for the ID of the typelib if this project is exposed to COM
                        [assembly: Guid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")]

                        // Version information for an assembly consists of the following four values:
                        //
                        // Major Version
                        // Minor Version
                        // Build Number
                        // Revision
                        //
                        // You can specify all the values or you can default the Build and Revision Numbers
                        // by using the '*' as shown below:
                        // [assembly: AssemblyVersion("1.0.*")]
                        [assembly: AssemblyVersion("1.0.0.0")]
                        [assembly: AssemblyFileVersion("1.0.0.0")]

                        The contents of Go.cs:

                        using System;
                        using System.Collections.Generic;
                        using System.Linq;
                        using System.Text;

                        namespace Testify
                        {
                        class Go
                        {
                        }
                        }

                        The contents of Testify.csproj:

                        <?xml version="1.0" encoding="utf-8"?>
                        <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
                        <

                        realJSOPR Online
                        realJSOPR Online
                        realJSOP
                        wrote on last edited by
                        #11

                        That IS the answer. I tried it this morning, and it worked like a charm. :) Many thanks, oh great and powerful Oz!

                        ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                        -----
                        You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                        -----
                        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups