Visual Studio Notes

1. Using the Project Template Export Wizard

  • The Project Template Export Wizard will export your current project as a template.

  • This is a starting point for creating a template. Once exported, the template will require customization by manually adding Template parameters.

1.1. Create a project that you’d like to be templated.

  • Create a project including all required files and library references.

    Nothing special is required in order to template this project. Customization will occur later…​

1.2. Export the template

  • Official documentation.

    1. Choose the following: Project  Export Template…​

    2. Choose the Project template radio button.

    3. Select the project.

    4. Click Next

    5. Provide values for:

      1. Template Name

        XS-BlazorApp
      2. Template Description]

        A project template for creating a Blazor Server app preconfigured to use the XS Component Library.
      3. Template Icon image

        C:\Users\mattosd\source\repos\GitLab\repo-dot-net-core\Com.XS.Spa.Accounting\Com.XS.Spa.Accounting\wwwroot\android-chrome-192x192.png
    6. Click the Finish button.

1.3. Template Created

  • A template zip file will be created here:

    C:\Users\<username>\Documents\Visual Studio 2022\My Exported Templates

2. Customize the Template

  1. Unzip the previously exported template file.

  2. Delete the zipped file.

  3. Make changes to the _Imports.razor file.

    1. Find these lines

      @using Template_BlazorApp_Net_7._0
      @using Template_BlazorApp_Net_7._0.Shared
    2. And replace the project name with a project name variable as follows:

      @using $safeprojectname$
      @using $safeprojectname$.Shared
  4. Make changes to the MyTemplate.vstemplate file.

    1. Find the line for the _Imports.razor file.

      <ProjectItem ReplaceParameters="false" TargetFileName="_Imports.razor">_Imports.razor</ProjectItem>
    2. Flip the ReplaceParameters value to true.

      ReplaceParameters="true"
  5. After making changes, copy the unzipped folder to the project template cache folder overwritting the existing folder:

    Project Template Cache location
    %appdata%\Microsoft\VisualStudio\17.0_632eabc8\ProjectTemplatesCache
    The actual folder may be slightly different.

3. Use the new Template

  • When creating a new project, look for the XS-BlazorApp template.