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

Martin Han 21 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.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,508 questions
{count} votes