Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use TargetFileName to place a file up a directory within a Visual Studio Template?

I have a .cs file with a base class that I want to use from within many projects. I've first placed this cs file above the project folder (along side the .sln). Then, within the project, I've changed the

<Compile Include="BaseClass.cs">
to
<Compile Include="..\BaseClass.cs">

This works, and the file icon then has a little shortcut arrow.


The problem comes when I want to export the project as a project template. The BaseClass does not get included in the template because it is outside the project folder. I've tried adding the BaseClass.cs to the template zip and adding
<ProjectItem ReplaceParameters="true" TargetFileName="..\BaseClass.cs">BaseClass.cs</ProjectItem>
to the MyTemplate.vstemplate, but I get the error:
A target file name within the VSTemplate file is invalid, it contains a fully qualified path
If I remove the ..\, it includes the file directly. If I leave the <ProjectItem> out of the .vstemplate file, and just put <Compile Include="..\BaseClass.cs"> in the .csproj file in the template, it looks for the file in Users/me/AppData/Local....

How can I get the template to reference a file outside the project directory?

like image 841
Marty Neal Avatar asked Jul 18 '12 18:07

Marty Neal


People also ask

What is TargetFileName?

TargetFileName. Optional attribute. Specifies the name and path of the project item when a project is created from the template. This attribute is useful for creating a directory structure different from the directory structure in the template . zip file, or for using parameter replacement to create an item name.

How do I import a project template into Visual Studio?

Project -> Export Template… Select Project Template. Select source Project. In the Template Options I choose to Automatically Import the template to Visual Studio.


1 Answers

This is a known issue which has not been solved by Microsoft : https://connect.microsoft.com/VisualStudio/feedback/details/565068/project-template-relative-file-path-does-not-work

like image 142
Rom Eh Avatar answered Sep 19 '22 23:09

Rom Eh