Custom Templates
-
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 -
I'm not sure what language template or what file the above belongs in, but should you not be using
$safeprojectname$
rather thantest
in the text portions of the above statements?Use the best guess
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 -
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 -
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, 1997Maybe it's choking on the fact that they're named "test". Is it finding all of the other files ok?
-
Maybe it's choking on the fact that they're named "test". Is it finding all of the other files ok?
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 -
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, 1997Based 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>
-
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>
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).
-
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, 1997When 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. -
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, 1997I 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.vstemplateThe 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">
< -
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.vstemplateThe 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">
<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