How to get the project name when creating an item template in Visual Studio?
03:02 14 Jun 2024

I want to create a project template in Visual Studio. The $rootnamespace$ and $safeitemname$ parameters work fine, but I also want to access the project name. I do it as follows, but instead of writing the project name, it remains as $projectname$ in the output.

UserControl.xaml


    
        
    
    
            
    

UserControl.xaml.cs

namespace $rootnamespace$
{
    public partial class $safeitemname$ : UserControl
    {
        public $safeitemname$()
        {
            InitializeComponent();
        }
    }
}

UserControl.vstemplate



  
    SUserControl
    
    
    Microsoft.CSharp.WPF.UserControl
    CSharp
    CSharp + (WPF | (!CPS + WindowsForms))
    false
    98
    3.0
    1
    SUserControl.xaml
    blend
  
  
    
      
        System
      
      
        System.Xaml
      
      
        WindowsBase
      
      
        PresentationCore
      
      
        PresentationFramework
      
    
    SUserControl1.xaml
    SUserControl1.xaml.cs
  

visual-studio itemtemplate