Reputation: 16755
I am attempting to create a custom ASP.NET MVC4 template. I start from the Basic MVC4 template, make my modifications, and then use the "Export Template" wizard to create the template zip file. Right now (almost) everything is working smoothly. When I use the template to create a new MVC application, it recreates all of my settings the way I want them except one. For some reason, it changes the project properties for my web application to have a Start Action of "Current Page" instead of "Specific Page" (like it was in the original template and like it is in my template). This setting is in the project properties under the Web tab. Here is what it is set to in my template application (before I generate the actual template zip file):
And here is what it is like when I create a new project using that template:
How do I modify my template to set this setting properly (or more accurately, how do I force it to remember what I set initially)?
Upvotes: 3
Views: 758
Reputation: 3084
Edit: answer revised due to misunderstanding of both original request and behavior of previously proposed solution.
To set the Start Action of a custom MVC project template, you'll need to create a dll with a class that implements the Microsoft.VisualStudio.TemplateWizard.IWizard
interface. To use the wizard dll, you'll either need to copy it to Visual Studio's probing 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 those directories, you'll need to strong name and sign the dll and add it to the GAC and get the publickeytoken of the dll and add it to the Assembly element in the vstemplate file.
In testing the following code I copied the dll to (VS2010 Install Dir)\Common7\IDE\PrivateAssemblies, so the dll is not signed.
Wizard 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 wizard specific elements 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>
The start actions on the project page appear to be numbers 0 through 4, following their display order. A value of 1 corresponds with Specific Page.
Upvotes: 4
Reputation: 548
Unfortunately, or fortunately, depending on the side of the coin you're on...
Like the "Startup Project" setting, that setting is NOT part of the project file or the template file that's generated. It is stored in the "SUO" or Solution User Options, file. The SUO is not included by the template generator.
Some background on the SUO file: http://msdn.microsoft.com/en-us/library/bb165909(v=vs.80).aspx
Upvotes: 0