Visual Studio MVC Template Generation Problem

I am trying to create my own ASP.NET MVC4 template. I start with a Basic MVC4 template, make my changes, and then use the Export Template wizard to create a template zip file. Right now (almost) everything is working smoothly. When I use a template to create a new MVC application, it recreates all my settings the way I want them, except one. For some reason, it changes the project properties for my web application to Action "Current Page" instead of "Specific Page" (for example, this was in the original template and as it is in my template). This setting is found in the project properties on the Web tab. This is what it has installed in my template app (before I generated the actual zip file):

Correct Settings

And this is how it looks when I create a new project using this template:

Incorrect Settings

How do I change my template to set this parameter correctly (or more precisely, how do I make it remember what I originally asked)?

+3


source to share


2 answers


Edit: The answer is fixed due to a misunderstanding of both the original request and the behavior of the previously proposed solution.

To set the Start Action for a custom MVC project template, you need to create a dll with a class that implements the interface Microsoft.VisualStudio.TemplateWizard.IWizard

. To use the wizard dll, you will need to copy it to the Visual Studio check path, which is (VS2010 Install Dir) \ Common7 \ IDE, (VS2010 Install Dir) \ Common7 \ IDE \ PrivateAssemblies or (VS2010 Install Dir) \ Common7 \ IDE \ PublicAssemblies. If you don't put the compiled dll in one of these directories, you will need to strong name and sign the dll and then add it to the GAC and get the dll library publish and add it to the Assembly element in the vstemplate file.

While testing the following code, I copied the dll to (VS2010 Install Dir) \ Common7 \ IDE \ PrivateAssemblies, so the DLL is unsigned.

Master code



using System.Collections.Generic;
using System.Linq;
using System.Xml;
using EnvDTE;
using Microsoft.VisualStudio.TemplateWizard;

namespace WarrenG.StartAction {
    public class Wizard : IWizard {
        private readonly Dictionary<string, object> data = new Dictionary<string, object>();


        public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary,
                               WizardRunKind runKind, object[] customParams) {
            if (replacementsDictionary.ContainsKey("$wizarddata$")) {
                string xml = replacementsDictionary["$wizarddata$"];
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml);
                foreach (XmlNode node in doc.ChildNodes) {
                    data.Add(node.Name, node.InnerText);
                }
            }
        }

        public bool ShouldAddProjectItem(string filePath) {
            return true;
        }

        public void RunFinished() {
        }

        public void BeforeOpeningFile(ProjectItem projectItem) {
        }

        public void ProjectItemFinishedGenerating(ProjectItem projectItem) {
        }

        public void ProjectFinishedGenerating(Project project) {
            if (data.ContainsKey("WebApplication.DebugStartAction")) {
                project.Properties.Item("WebApplication.DebugStartAction").Value =
                    data["WebApplication.DebugStartAction"];
            } else {
                project.Properties.Item("WebApplication.DebugStartAction").Value = 1;
            }
        }
    }
}

      

Add custom wizard items to vstemplate file of custom MVC project template

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
  <TemplateContent>
    <!-- various template content -->
  </TemplateContent>
  <!-- add the following -->
  <WizardExtension>
    <Assembly>WarrenG.StartAction, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=null</Assembly>
    <FullClassName>WarrenG.StartAction.Wizard</FullClassName>
  </WizardExtension>
  <WizardData>
    <WebApplication.DebugStartAction>1</WebApplication.DebugStartAction>
  </WizardData>
</VSTemplate>

      

Initial actions on the project page appear as numbers from 0 to 4, following the order in which they are displayed. A value of 1 corresponds to a specific page.

+4


source


Unfortunately, or fortunately, depending on the side of the coin you are in ...

Like the Startup Project option, this option is NOT part of the project file or generated template file. It is stored in files "SUO" or "Solution User Options". SUO is not included by the template generator.



Some background in SUO file: http://msdn.microsoft.com/en-us/library/bb165909(v=vs.80).aspx

0


source







All Articles