8

I've successfully created a multi-project solution template. What I would like to do, however, is to rename the beginning of each project with the name of the solution.

So my projects:

  • ProjectOne.A
  • ProjectTwo.B

Would be renamed to

  • SolutionName.A
  • SolutionName.B

where SolutionName is the name by the user when they created the project.

I've read the following articles:

but none seem to answer my specific situation.

Omar
  • 39,496
  • 45
  • 145
  • 213
  • @Adron - can you post the exact link. I don't want to hunt down the right article. – Omar Mar 21 '11 at 22:18
  • I have yet to test what you suggested, but I'll trust that it works based on Myles' comment. – Omar May 20 '11 at 18:06

1 Answers1

11

If your main .vstemplate (the solution's one) is like the example below, you can use variables defined in wizard's dictionary to rename project folders and .csproj to whatever names you want.

<?xml version="1.0" encoding="utf-8"?>
<VSTemplate Version="2.0.0" Type="ProjectGroup"
xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
    <TemplateData>
        <Name>My Web Server Solution with DAL</Name>
        <Description>Creates Projects for Web Server DAL and adds them to a new or existing solution</Description>
        <Icon></Icon>
        <ProjectType>CSharp</ProjectType>
        <ProjectSubType>My</ProjectSubType>
        <DefaultName>WebServer</DefaultName>
        <NumberOfParentCategoriesToRollUp>2</NumberOfParentCategoriesToRollUp>
        <TemplateGroupID>My</TemplateGroupID>
        <TemplateID>My.Dal.Web.Template</TemplateID>
    </TemplateData>
    <TemplateContent>
        <ProjectCollection>
            <ProjectTemplateLink ProjectName="$ModelProjectName$">
                Children\Model\ProjectTemplate.vstemplate
            </ProjectTemplateLink>
            <ProjectTemplateLink ProjectName="$SharedModelContractsProjectName$">
                Children\SharedModelContracts\ProjectTemplate.vstemplate
            </ProjectTemplateLink>
            <ProjectTemplateLink ProjectName="$RepositoryInterfacesProjectName$">
                Children\RepositoryInterfaces\ProjectTemplate.vstemplate
            </ProjectTemplateLink>
            <ProjectTemplateLink ProjectName="$RepositoryImplementationProjectName$">
                Children\RepositoryImplementation\ProjectTemplate.vstemplate
            </ProjectTemplateLink>
            <ProjectTemplateLink ProjectName="$RepositoryExtensionsProjectName$">
                Children\RepositoryExtensions\ProjectTemplate.vstemplate
            </ProjectTemplateLink>
        </ProjectCollection>
    </TemplateContent>
    <WizardExtension>
        <Assembly>My.WebServerDalExtension.Wizard, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c93c79b0feae916</Assembly>
        <FullClassName>My.WebServerDalExtension.Wizard.Controller</FullClassName>
    </WizardExtension>
</VSTemplate>

Use similar changes to addition .vstemplates (the projects' .vstemplates) to rename the .csproj files.

KyleMit
  • 30,350
  • 66
  • 462
  • 664
Danny Varod
  • 17,324
  • 5
  • 69
  • 111
  • Some of these projects reference each other, but the `$safeitemname$` and `$safeprojectname$` placeholders are not being replaced or are replacing with the wrong value. Any idea on how to reference projects together? – Omar Sep 04 '11 at 05:09
  • Yes, read all the project names from your wizard. Have each project reference's use variables defined in wizard. See this example: http://vsix.codeplex.com/ – Danny Varod Sep 04 '11 at 12:48
  • Yep, looks like adding a custom variable into the `.csproj` reference section does absolutely nothing. – Dmitri Nesteruk Sep 20 '11 at 10:00
  • The .vstemplate file must enable variable replacement for that .csproj file. – Danny Varod Sep 20 '11 at 13:11
  • how do we pass custom parameters down to the child template? – Alex Gordon Oct 03 '18 at 17:16
  • @AlexGordon I implemented this years ago, however, I recall that it just worked. Today I am using a much better approach though which doesn't use VS template mechanism. – Danny Varod Oct 04 '18 at 13:47
  • @DannyVarod is the approach you are using classified or is it something you would be potentially willing to publicly share here? – Alex Gordon Oct 04 '18 at 18:48
  • @AlexGordon Not classified, I can explain how it works and ask about publishing the code. The downside of the template projects is that they are hard to keep updated. That is why I came up with a new solution which we implemented - use a working code repository which compiles with runable unit and integration tests, with generic names e.g. VAL_ROOT_VAL, VAL_DOMAIN_VAL, VAL_PROJECT_VAL. Then use a wizard for cloning this repository with replacements, thus ending in a new repository with the specific names required. This solution makes updates much easier as the template compiles and has tests. – Danny Varod Oct 07 '18 at 10:21