0

I am trying to create a Visual Studio 2022 Project Template. I am using a custom Windows form, where I accept multiple user inputs and have a class that implements IWizard, where I add it to the replacementsDictionary so that file contents are updated to replace the place holder template variables.

public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
{
    replacementsDictionary.Add("$MyTemplateInput1$", UserInputForm.SomeField.Text);
}

However, I am not able to use the user input value to specify a target file name.

Within MyTemplate.vstemplate file, I have tried the below options.

  <TemplateContent>
    <Project TargetFileName="$projectname$.csproj" File="MyCustom.Templates.csproj" ReplaceParameters="true">
      <Folder Name="Properties" TargetFolderName="Properties">
        <ProjectItem ReplaceParameters="true" TargetFileName="launchSettings.json">launchSettings.json</ProjectItem>
      </Folder>
      <Folder Name="manifests" TargetFolderName="manifests">
        <ProjectItem ReplaceParameters="true" TargetFileName="$manifestFilePrefix$-trace-off.yaml">app-mytemplate-trace-off.yaml</ProjectItem>
        <ProjectItem ReplaceParameters="true" TargetFileName="app-$MyTemplateInput1$-trace-on.yaml">app-mytemplate-trace-on.yaml</ProjectItem>
      </Folder>
      <ProjectItem ReplaceParameters="true" TargetFileName="$projectname$_Local.csproj">MyCustom.Templates_Local.csproj</ProjectItem>
      <ProjectItem ReplaceParameters="true" TargetFileName="Program.cs">Program.cs</ProjectItem>
      <ProjectItem ReplaceParameters="true" TargetFileName="Startup.cs">Startup.cs</ProjectItem>
      <ProjectItem ReplaceParameters="true" TargetFileName="web.config">web.config</ProjectItem>
      <CustomParameters>
        <CustomParameter Name="$manifestFilePrefix$" Value="app-$MyTemplateInput1$"/>
      </CustomParameters>
    </Project>
  </TemplateContent>

While $projectname$ gets replaced in target file name properly, neither the use of custom parameter approach works nor the direct use of replacement variable. In both cases, I am getting the file name as manifestFilePrefix$-trace-off.yaml and app-$MyTemplateInput1$-trace-on.yaml.

Any idea on how to get the file name populated dynamically based on user input.

Thanks!

askids
  • 1,406
  • 1
  • 15
  • 32

0 Answers0