I’m looking to create a Visual Studio 2008 template that will create a basic project and based on remove certain files/folders based on options the user enters.
Right now, I have followed some tutorials online which have let me create the form to query the user and pass the data into an IWizard class, but I don’t know what to do from there.
The tutorials provide a sample to do some simple substitution: code:
Form1 form = new Form1(); DialogResult dlg = form.ShowDialog(); if (dlg == DialogResult.OK) { foreach (KeyValuePair<string, string> pair in form.Parameters) { if (!replacementsDictionary.ContainsKey(pair.Key)) replacementsDictionary.Add(pair.Key, pair.Value); else replacementsDictionary[pair.Key] = pair.Value; } } form.Close();
but I’m looking to selectively include files based on the user settings, and if possible, selectively include code sections in a file based on settings.
Is there a clever way to do this, or will I manually have to delete project files in the IWizard:ProjectFinishedGenerating()?
In my experience,
ShouldAddProjectItemonly gets called for folders in the template project. As such, it’s pretty much useless.Instead, you would need to put code in your
ProjectFinishedGeneratingimplementation that uses the VS API to remove ProjectItems.In there, you can remove items like this: