Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > ProjectItem TargetFileName in App_Code folder
 

ProjectItem TargetFileName in App_Code folder

I'm working in a VSTemplate to new item. It should create s 3 files. The usual file.aspx and it code behind file.aspx.cs. This is working fine.

But I need to add in the same time a class file _file.cs opn App_Code folder.

<TemplateContent>

<ProjectItem ReplaceParameters="true" TargetFileName="$page$.aspx">$.Taspx</ProjectItem>

<ProjectItem ReplaceParameters="true" TargetFileName="$page$.aspx.cs">$.aspx.Tcs</ProjectItem>

<ProjectItem ReplaceParameters="true" TargetFileName="..\\App_Code\\_$page$.cs">_$.Tcs</ProjectItem>

</TemplateContent>

Any way, all 3 files goes tosame folder and none goes to App_Code.

There some way to do this only using the template or I need to use some other way?

Julio L. Botelho  Sunday, June 24, 2007 4:31 AM

Hi Julio,

Here I give you an example of how you can achieve that..

in the vstemplate you should use something like this:

<TemplateContent>
<Project TargetFileName="WebSite.webproj" File="WebSite.webproj" ReplaceParameters="true">
<Folder Name="App_Code">
<ProjectItem ReplaceParameters="true" TargetFileName="$MyPageName$.cs">foo.cs</ProjectItem>
</Folder>
<Folder Name="App_Data"></Folder>
<Folder Name="Other"/>
<ProjectItem ReplaceParameters="true" TargetFileName="$MyPageName$.aspx">foo.aspx</ProjectItem>
<ProjectItem>Web.config</ProjectItem>
</Project>
</TemplateContent>

and in your templates folder you should have the following structure:

/FooWebSite

| -/App_Code/

||----foo.cs

|----foo.aspx

remember to set the Copy to Output property as always or if it's newer.

hth.

Jose Escrich  Thursday, June 28, 2007 3:00 PM

Hi Julio

you have to add a Folder element like this:

<TemplateContent>

<ProjectItem ReplaceParameters="true" TargetFileName="$page$.aspx">$.Taspx</ProjectItem>

<ProjectItem ReplaceParameters="true" TargetFileName="$page$.aspx.cs">$.aspx.Tcs</ProjectItem>

<Folder Name="App_Code">

<ProjectItem ReplaceParameters="true" TargetFileName="..\\App_Code\\_$page$.cs">_$.Tcs</ProjectItem>

</Folder>

</TemplateContent>

hth.

jose.

Jose Escrich  Monday, June 25, 2007 5:29 PM

Thanks,

I tried before and I got an error - I reproduce now again to remember the message:

"A target file name within VSTemplate file is invalid, it contains a fully qualified file name"

And creates a folder App_Code under the folder where I'm saving the aspx and aspx.cs files.

To get my project working I'm writing this file using filesystem functions, but this work only on local machine and do not work if the target is a remote site accessed using ftp or other way.

Julio Botelho

Julio L. Botelho  Monday, June 25, 2007 9:12 PM

Hi Julio,

Here I give you an example of how you can achieve that..

in the vstemplate you should use something like this:

<TemplateContent>
<Project TargetFileName="WebSite.webproj" File="WebSite.webproj" ReplaceParameters="true">
<Folder Name="App_Code">
<ProjectItem ReplaceParameters="true" TargetFileName="$MyPageName$.cs">foo.cs</ProjectItem>
</Folder>
<Folder Name="App_Data"></Folder>
<Folder Name="Other"/>
<ProjectItem ReplaceParameters="true" TargetFileName="$MyPageName$.aspx">foo.aspx</ProjectItem>
<ProjectItem>Web.config</ProjectItem>
</Project>
</TemplateContent>

and in your templates folder you should have the following structure:

/FooWebSite

| -/App_Code/

||----foo.cs

|----foo.aspx

remember to set the Copy to Output property as always or if it's newer.

hth.

Jose Escrich  Thursday, June 28, 2007 3:00 PM

You can use google to search for other answers

Custom Search

More Threads

• Delete Extra Lines from Code using TextTemplateAction
• Issue with DSL Tool
• Code Snippets not uninstalling
• Sharing gpState in TFS Source Control
• Cant' install "Guidance Automation Extensions" ...
• Problem in migrating VS 2005 guidance package to VS 2008
• Always publish release build
• Combining GAT and CAB
• Guidance don´t unload the AppDomain
• How to add template menu item to custom solution