I am currently creating a project template and I was wondering if it would be possible to execute a PowerShell script after the project has been created (similar to the install.ps1 in NuGet packages).

Any chance to do this without implementing my own IWizard?

share|improve this question
feedback

1 Answer

OK... I have tried many things, but finally I ended up with the custom IWizard.

public class InitScriptWizard : IWizard
{
    public void RunStarted(
        object automationObject,
        Dictionary<string, string> replacementsDictionary,
        WizardRunKind runKind,
        object[] customParams)
    { }

    public void ProjectFinishedGenerating(Project project)
    {
        var script =
            project.ProjectItems.FindProjectItem(
                item => item.Name.Equals("init.ps1"));

        if (script == null)
        {
            return;
        }

        var process =
            System.Diagnostics.Process.Start(
                "powershell",
                string.Concat(
                    "-NoProfile -ExecutionPolicy Unrestricted -File \"",
                    script.FileNames[0],
                    "\""));

        //if (process != null)
        //{
        //    process.WaitForExit();
        //}

        //script.Delete();
    }

    public void ProjectItemFinishedGenerating(ProjectItem projectItem)
    { }

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

    public void BeforeOpeningFile(ProjectItem projectItem)
    { }

    public void RunFinished()
    { }
}
share|improve this answer
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.