Search code examples
c#visual-studiotemplatesvisual-studio-templates

Visual Studio C# Project Template: $safeprojectname$ parameter


Visual Studio C# Project Template: $safeprojectname$ parameter

i'm trying to create a project template and i want to replace some file names to safeprojectname.

It works for source file however it did not work project file (.csproj) itsef.

  <TemplateContent>    
    <Project TargetFileName="$safeprojectname$.csproj" File="$safeprojectname$.csproj" ReplaceParameters="true">      
      <Folder Name="Definition File" TargetFolderName="Definition File">
        <ProjectItem ReplaceParameters="true" TargetFileName="$safeprojectname$.txt">$safeprojectname$.txt</ProjectItem>
      </Folder> 
    <TemplateContent>

Is it possible to use $safeprojectname$ in project file naming?

MSDN says:

safeprojectname: The name provided by the user in the New Project dialog box, with all unsafe characters and spaces removed.

If it is not possible to use $safeprojectname$ in projet name itself i need know the what are the unsafe characters that will removed.


Solution

  • i need know the what are the unsafe characters that will removed

    Same as what Path.GetInvalidFileNameChars() returns. So in practice any character in :\/*?"<>|. Note how these characters do special things when used at the command line and when composing a full path name. Having them appear in a project file name would cause lots of trouble.