5

I created a wizard for a custom template in VS2010 And it works like a charm.

But since the wizard contains a form required to finish the creation of the project, i feel that the user should be able to cancel the creation of the project.

So my question being..

Is it possible to cancel the creation of a project/template process from inside a wizard implementing IWizard?

These are the events i got at my disposal.

public void BeforeOpeningFile(ProjectItem projectItem)

public void ProjectFinishedGenerating(Project project)

public void ProjectItemFinishedGenerating(ProjectItem projectItem)

public void RunFinished()

public void RunStarted(object automationObject,
        Dictionary<string, string> replacementsDictionary,
        WizardRunKind runKind, object[] customParams)

public bool ShouldAddProjectItem(string filePath)

Thank you!

Moulde
  • 3,438
  • 4
  • 29
  • 38

1 Answers1

11

Yes. To indicate that the user has cancelled the wizard, just throw a new WizardCancelledException in your IWizard implementation.

A very interesting article which explains all this: Pitfalls of cancelling a VSIX project template in an IWizard

Aaron Marten
  • 6,548
  • 1
  • 32
  • 41
  • Before i did it by deleting the project from the ProjectFinishedGenerating event. And that actually works exactly the same as throwing the exception from the RunStarted method. You still end up with an empty solution folder inside the projects folder. But at least its the "right way" to do it, Thanks =) – Moulde Aug 27 '10 at 21:03
  • 7
    This thread is old, however with Visual Studio 2012, there is a WizardBackoutException that can be thrown which will return you to the New Project screen and will not create the blank project folder for your solution. – Rockdocta Sep 04 '13 at 15:57
  • @Rockdocta Throwing a `WizardBackoutException` in **VS2013** backs out however the folder **remains on disk** –  Jan 07 '15 at 09:30
  • More than 4 years ago Aaron Marten posted this answer and it was accepted for any reason... Any reason which we cant know today because the link he shared does not exist anymore. So that is why if you answer a question, write exactly the solution so that it will help people forever... – hakan Mar 24 '15 at 17:52
  • The solution/explanation is still there, and still valid (i.e. throw a WizardCancelledException). FWIW, the post referred to appears to have been moved to a new location. I'll update the link in the answer. – Aaron Marten Apr 14 '15 at 15:01