In item template, how to substitute part of text with project name?

Martin Han 26 Reputation points
2021-09-18T11:47:21.48+00:00

I have an item template,

   <v:View x:TypeArguments="local:$safeitemname$Model" x:Name="view"  
       x:Class="$rootnamespace$.$safeitemname$"  
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
                xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   
                xmlns:d="http://schemas.microsoft.com/expression/blend/2008"   
                xmlns:v ="clr-namespace:$safeprojectname$.Visual"  
                xmlns:local="clr-namespace:$rootnamespace$"  
                mc:Ignorable="d"   
                d:DesignHeight="450" d:DesignWidth="800">  
   </v:View>  

However in practice $safeprojectname$ was not replaced. After research I found its only available for project template.

I tried using the Wizard, however, I don't know how to get the project name with the given paramters of IWizard.RunStarted(Object, Dictionary<String,String>, WizardRunKind, Object[]) Method. It is posible to get it via IWizard.ProjectItemFinishedGenerating(ProjectItem), but this method is called after everything are done.

Anther thing I found perhaps useful is an answer in Stackoverflow, https://stackoverflow.com/a/42138852/12463119. Unfortunately I cannot understand it as I don't where where the 'dte' varible come from.

Please tell me how to let my template be able to capture the project name and automatically write into the generated file.

Developer technologies | C#
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.