Visual studio element template $ safeitemname $ not working as expected

I am creating a Visual Studio element template to create multiple files that depend on a container file.

The last file <ProjectItem SubType="Code" TargetFileName="$fileinputname$\I$fileinputname$ View.cs" ReplaceParameters="true">Container View.cs</ProjectItem> creates a view interface that expects a specific type of model. However, the $safeitemname$ parameter did not work as I expected.

Output File Container View.cs :

 public interface IIMy_Triplet_View : IView<IMy_Triplet_View_Model> { } 

Expected:

 public interface IMy_Triplet_View : IView<My_Triplet_Model> { } 

This is the source of the Container View.cs template:

 using System; using System.Collections.Generic; using System.Linq; using System.Web; using WebFormsMvp; namespace $rootnamespace$ { public interface $safeitemname$_View : IView<$safeitemname$_Model> { } } 

And the .vstemplate file

  <VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item"> <TemplateData> <DefaultName>Model-View-Presenter</DefaultName> <Name>Model-View-Presenter</Name> <Description>Creates a model-view-presenter triplet</Description> <ProjectType>CSharp</ProjectType> <SortOrder>10</SortOrder> <Icon>__TemplateIcon.png</Icon> <PreviewImage>__PreviewImage.png</PreviewImage> </TemplateData> <TemplateContent> <References> <Reference> <Assembly>WebFormsMvp</Assembly> </Reference> </References> <ProjectItem SubType="Code" TargetFileName="$fileinputname$" ReplaceParameters="false">Container</ProjectItem> <ProjectItem SubType="Code" TargetFileName="$fileinputname$\$fileinputname$ Model.cs" ReplaceParameters="true">Container Model.cs</ProjectItem> <ProjectItem SubType="Code" TargetFileName="$fileinputname$\$fileinputname$ Presenter.cs" ReplaceParameters="true">Container Presenter.cs</ProjectItem> <ProjectItem SubType="Code" TargetFileName="$fileinputname$\I$fileinputname$ View.cs" ReplaceParameters="true">Container View.cs</ProjectItem> </TemplateContent> </VSTemplate> 
+8
c # parameters visual-studio visual-studio-templates
source share
1 answer

The solution is found here: http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/8516524a-22d3-4ed2-b2da-aaafe855fb92/

Add a custom parameter (the last element in the TemplateContent section):

 <VSTemplate Version="3.0.0" ... Type="Item"> <TemplateData> ... </TemplateData> <TemplateContent> ... <CustomParameters> <CustomParameter Name="$basename$" Value="$fileinputname$"/> </CustomParameters> </TemplateContent> </VSTemplate> 

And use $ basename $ in files instead of $ fileinputname $.

+14
source share

All Articles