Question

I'm in the process of creating a MVC starterkit for work and I'm having problems creating a multi-project template that doesn't require massive manual modification after creation.

What I have is 4 projects that have some dependencies on each other:

  • StarterKit.Common - no dependency
  • StarterKit.DAL - dependency to StarterKit.Common
  • StarterKit.BL - dependency to StarterKit.Common and StarterKit.DAL StarterKit.Web - dependency to the other three

I've tried going the route of exporting each project using the Export Template wizard, creating a root .vstemplate file and zipping it all up. Although this works (I can create a new solution based on this template), it has some serious problems.

Firstly, the export replaces the entire namespace of each project with $safeprojectname$, i.e. StarterKit.DAL => $safeprojectname$, StarterKit.Web => $safeprojectname$ etc.

This means that when the new project is created (let's call it XXX), what was previously in the namespace StarterKit.Web now ends up in the XXX namespace and what was previously StarterKit.BL also ends up in the XXX namespace!

This is obviously not going to work.

Secondly, some using statements are not replaced at all. For example using StarterKit.Common; is not replaced in the web project because it doesn't have the correct namespace (which is StarterKit.Web).

Thirdly, I have some .tt scripts that contains using statements I want to replace, but even though I set ReplaceParameters="true" in the project, these are not touched at all.

I also looked into creating a VSIX project, but frankly I don't see how I can use that. To me it looks mostly like a zip utility that creates the .vstemplate for you and renames the .zip to .vsix for me.

What I need to do is:

  • Package all the projects in a single deploy file available as a "New Project" template in VS
  • When a newproject is created, replace all "StarterKit" namespace references in .csproj, .cs, .cshtml and .tt files with whatever the user selected as the solution name
  • Figure out a simple process where I can easily update the templates whenever the base projects change (files added/removed, renamed, content changed etc)

Does anyone have any idea if this is even possible?

Was it helpful?

Solution

Full Disclosure: I am the creator of the below mentioned project.

You can achieve the desired result using the IWizard implementation I created called GlobalParams. It makes the information from the solution template level available to the child templates that also run the wizard by prefixing ALL solution level parameters with the word global and adding them to the parameters of the child template.

If you used GlobalParams with the above multi-project template and the user entered "StarterKit", the following would be true:

  • StarterKit.Common Could access
    • $safeprojectname$ = StarterKit.Common
    • $globalsafeprojectname$ = StarterKit
    • $globalguid1$ = E8C8A064601844439909D6C33AB90CB3
    • $globalguid2$ = 020DB5ABF76040C7BDA19EAC54DFE3D8
    • $globalguid3$ = 8392FB760F754C0AB87778845CC28B6D
    • $globalguid4$ = 13E07D43F523467587296B2C386DEE50
  • StarterKit.DAL
    • $safeprojectname$ = StarterKit.DAL
    • $globalsafeprojectname$ = StarterKit
    • $globalguid1$ = E8C8A064601844439909D6C33AB90CB3
    • $globalguid2$ = 020DB5ABF76040C7BDA19EAC54DFE3D8
    • $globalguid3$ = 8392FB760F754C0AB87778845CC28B6D
    • $globalguid4$ = 13E07D43F523467587296B2C386DEE50
  • StarterKit.BL
    • $safeprojectname$ = StarterKit.BL
    • $globalsafeprojectname$ = StarterKit
    • $globalguid1$ = E8C8A064601844439909D6C33AB90CB3
    • $globalguid2$ = 020DB5ABF76040C7BDA19EAC54DFE3D8
    • $globalguid3$ = 8392FB760F754C0AB87778845CC28B6D
    • $globalguid4$ = 13E07D43F523467587296B2C386DEE50
  • StarterKit.Web
    • $safeprojectname$ = StarterKit.Web
    • $globalsafeprojectname$ = StarterKit
    • $globalguid1$ = E8C8A064601844439909D6C33AB90CB3
    • $globalguid2$ = 020DB5ABF76040C7BDA19EAC54DFE3D8
    • $globalguid3$ = 8392FB760F754C0AB87778845CC28B6D
    • $globalguid4$ = 13E07D43F523467587296B2C386DEE50

With GlobalParams you have access to 100 Guids with the global prefix that are the same across child templates. So the StarterKit.Common project can be given the value of "$globalguid1$" as the project id with StarterKit.DAL and StarterKit.BL building project references to StarterKit.Common using "$globalsafeprojectname$.Common" as the name of the project being referenced and "$globalguid1$" as the id of the project being referenced. I think you can see how it will work for building the references between the rest of the projects.

OTHER TIPS

I never found an answer to this, so I've chosen another route.

I've created a PowerShell script that I include in a zip file with the solution files. The script renames the solution, projects and classes according to a project name chosen by the user.

The bummer is that this has to be run outside Visual Studio

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top