From e19b6182fafbb348412263c6e14477dad98fcb1c Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Wed, 23 Aug 2017 17:38:06 -0700 Subject: [PATCH 1/3] Add icons to Wizard --- Nodejs/Product/Nodejs/Nodejs.csproj | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Nodejs/Product/Nodejs/Nodejs.csproj b/Nodejs/Product/Nodejs/Nodejs.csproj index 0637b3061..5dcad77d9 100644 --- a/Nodejs/Product/Nodejs/Nodejs.csproj +++ b/Nodejs/Product/Nodejs/Nodejs.csproj @@ -679,6 +679,36 @@ + + Resources\Icons\NewProjectDialogIconsICO\JSAzureApplication.ico + + + Resources\Icons\NewProjectDialogIconsICO\JSConsole.ico + + + Resources\Icons\NewProjectDialogIconsICO\JSWeb.ico + + + Resources\Icons\NewProjectDialogIconsICO\JSWorker.ico + + + Resources\Icons\NewProjectDialogIconsICO\NodeJSApplication.ico + + + Resources\Icons\NewProjectDialogIconsICO\NodeTSApplication.ico + + + Resources\Icons\NewProjectDialogIconsICO\TSAzureApplication.ico + + + Resources\Icons\NewProjectDialogIconsICO\TSConsole.ico + + + Resources\Icons\NewProjectDialogIconsICO\TSWeb.ico + + + Resources\Icons\NewProjectDialogIconsICO\TSWorker.ico + PreserveNewest true From 01771c5158e9ffb170f46a2b8639f93bbdb0528c Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Thu, 24 Aug 2017 15:25:04 -0700 Subject: [PATCH 2/3] Ensure the Create from existing works again Code update to fix create from existing. --- Nodejs/Product/Nodejs/Guids.cs | 2 +- Nodejs/Product/Nodejs/NodejsTools.vsct | 10 ++ Nodejs/Product/ProjectWizard/ImportWizard.cs | 102 +++++++++--------- .../ProjectWizardResources.Designer.cs | 17 ++- .../ProjectWizard/ProjectWizardResources.resx | 11 +- 5 files changed, 82 insertions(+), 60 deletions(-) diff --git a/Nodejs/Product/Nodejs/Guids.cs b/Nodejs/Product/Nodejs/Guids.cs index 700eb8ec3..ca407914f 100644 --- a/Nodejs/Product/Nodejs/Guids.cs +++ b/Nodejs/Product/Nodejs/Guids.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // MUST match guids.h diff --git a/Nodejs/Product/Nodejs/NodejsTools.vsct b/Nodejs/Product/Nodejs/NodejsTools.vsct index 3e0759ff2..e9e0c5b01 100644 --- a/Nodejs/Product/Nodejs/NodejsTools.vsct +++ b/Nodejs/Product/Nodejs/NodejsTools.vsct @@ -209,6 +209,16 @@ Attach Node.js Debugger + + diff --git a/Nodejs/Product/ProjectWizard/ImportWizard.cs b/Nodejs/Product/ProjectWizard/ImportWizard.cs index c4983009c..d0d1186e0 100644 --- a/Nodejs/Product/ProjectWizard/ImportWizard.cs +++ b/Nodejs/Product/ProjectWizard/ImportWizard.cs @@ -1,10 +1,9 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.IO; using System.Windows.Forms; -using EnvDTE; using Microsoft.VisualStudio; using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Interop; @@ -15,7 +14,7 @@ namespace Microsoft.NodejsTools.ProjectWizard { public sealed class NewProjectFromExistingWizard : IWizard { - public static Boolean IsAddNewProjectCmd { get; set; } + public static bool IsAddNewProjectCmd { get; set; } public void BeforeOpeningFile(EnvDTE.ProjectItem projectItem) { } public void ProjectFinishedGenerating(EnvDTE.Project project) { } public void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem) { } @@ -23,66 +22,67 @@ public sealed class NewProjectFromExistingWizard : IWizard public void RunStarted(object automationObject, Dictionary replacementsDictionary, WizardRunKind runKind, object[] customParams) { - var dte = automationObject as DTE; - if (dte == null) + var provider = automationObject as Microsoft.VisualStudio.OLE.Interop.IServiceProvider; + if (provider == null) { - var provider = automationObject as Microsoft.VisualStudio.OLE.Interop.IServiceProvider; - if (provider != null) - { - dte = new ServiceProvider(provider).GetService(typeof(DTE)) as DTE; - } + MessageBox.Show(ProjectWizardResources.ErrorNoDte, SR.ProductName); + throw new WizardBackoutException(); } - bool addingNewProject = false; - if (dte == null) + using (var serviceProvider = new ServiceProvider(provider)) { - MessageBox.Show(ProjectWizardResources.ImportWizzardCouldNotStartNotAutomationObjectErrorMessage, SR.ProductName); - } - else - { - // https://nodejstools.codeplex.com/workitem/462 - // we need to make sure our package is loaded before invoking our command - Guid packageGuid = new Guid(Guids.NodejsPackageString); - IVsPackage package; - ((IVsShell)Package.GetGlobalService(typeof(SVsShell))).LoadPackage( - ref packageGuid, - out package - ); + var hr = EnsurePackageLoaded(serviceProvider); + if (ErrorHandler.Failed(hr)) + { + MessageBox.Show(string.Format(ProjectWizardResources.ImportWizardCouldNotStartFailedToLoadPackage, hr), "Visual Studio"); + throw new WizardBackoutException(); + } + var uiShell = (IVsUIShell)serviceProvider.GetService(typeof(SVsUIShell)); - System.Threading.Tasks.Task.Factory.StartNew(() => + var projName = replacementsDictionary["$projectname$"]; + replacementsDictionary.TryGetValue("$specifiedsolutionname$", out var solnName); + string directory; + if (string.IsNullOrWhiteSpace(solnName)) + { + // Create directory is unchecked, destinationdirectory is the + // directory name the user entered plus the project name, we want + // to remove the solution directory. + directory = Path.GetDirectoryName(replacementsDictionary["$destinationdirectory$"]); + } + else { - string projName = replacementsDictionary["$projectname$"]; - string solnName = replacementsDictionary["$specifiedsolutionname$"]; - string directory; - if (string.IsNullOrWhiteSpace(solnName)) - { - // Create directory is unchecked, destinationdirectory is the - // directory name the user entered plus the project name, we want - // to remove the solution directory. - directory = Path.GetDirectoryName(replacementsDictionary["$destinationdirectory$"]); - } - else - { - // Create directory is checked, the destinationdirectory is the - // directory the user entered plus the project name plus the - // solution name. - directory = Path.GetDirectoryName(replacementsDictionary["$destinationdirectory$"]); - } + // Create directory is checked, the destinationdirectory is the + // directory the user entered plus the project name plus the + // solution name - we want to remove both extra folders + directory = Path.GetDirectoryName(Path.GetDirectoryName(replacementsDictionary["$destinationdirectory$"])); + } - var context = addingNewProject ? - (int)VSConstants.VSStd97CmdID.AddExistingProject : - (int)VSConstants.VSStd97CmdID.OpenProject; - object inObj = projName + "|" + directory + "|" + context, outObj = null; - dte.Commands.Raise(Guids.NodejsCmdSet.ToString("B"), (int)PkgCmdId.cmdidImportWizard, ref inObj, ref outObj); - }); + var context = IsAddNewProjectCmd ? (int)VSConstants.VSStd97CmdID.AddExistingProject : (int)VSConstants.VSStd97CmdID.OpenProject; + + object inObj = projName + "|" + directory + "|" + context; + var guid = Guids.NodejsCmdSet; + hr = uiShell.PostExecCommand(ref guid, (uint)PkgCmdId.cmdidImportWizard, 0, ref inObj); + if (ErrorHandler.Failed(hr)) + { + MessageBox.Show(string.Format(ProjectWizardResources.ImportWizardCouldNotStartUnexpectedError, hr), "Visual Studio"); + } } - addingNewProject = IsAddNewProjectCmd; + throw new WizardCancelledException(); } - public bool ShouldAddProjectItem(string filePath) + private static int EnsurePackageLoaded(IServiceProvider serviceProvider) { - return false; + var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell)); + var pkgGuid = new Guid(Guids.NodejsPackageString); + + if (ErrorHandler.Failed(shell.IsPackageLoaded(ref pkgGuid, out var pkg)) || pkg == null) + { + return shell.LoadPackage(ref pkgGuid, out pkg); + } + return VSConstants.S_OK; } + + public bool ShouldAddProjectItem(string filePath) => false; } } diff --git a/Nodejs/Product/ProjectWizard/ProjectWizardResources.Designer.cs b/Nodejs/Product/ProjectWizard/ProjectWizardResources.Designer.cs index 5bd08fabb..fecfc57f3 100644 --- a/Nodejs/Product/ProjectWizard/ProjectWizardResources.Designer.cs +++ b/Nodejs/Product/ProjectWizard/ProjectWizardResources.Designer.cs @@ -19,7 +19,7 @@ namespace Microsoft.NodejsTools.ProjectWizard { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class ProjectWizardResources { @@ -137,11 +137,20 @@ internal class ProjectWizardResources { } /// - /// Looks up a localized string similar to Unable to start wizard: no automation object available.. + /// Looks up a localized string similar to Unable to start wizard: failed to load Node Tools support Package (0x{0:X08}). + /// + internal static string ImportWizardCouldNotStartFailedToLoadPackage { + get { + return ResourceManager.GetString("ImportWizardCouldNotStartFailedToLoadPackage", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Unable to start wizard: Unexpected error 0x{0:X08}. /// - internal static string ImportWizzardCouldNotStartNotAutomationObjectErrorMessage { + internal static string ImportWizardCouldNotStartUnexpectedError { get { - return ResourceManager.GetString("ImportWizzardCouldNotStartNotAutomationObjectErrorMessage", resourceCulture); + return ResourceManager.GetString("ImportWizardCouldNotStartUnexpectedError", resourceCulture); } } } diff --git a/Nodejs/Product/ProjectWizard/ProjectWizardResources.resx b/Nodejs/Product/ProjectWizard/ProjectWizardResources.resx index 77818efcb..46b0cac2d 100644 --- a/Nodejs/Product/ProjectWizard/ProjectWizardResources.resx +++ b/Nodejs/Product/ProjectWizard/ProjectWizardResources.resx @@ -117,9 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Unable to start wizard: no automation object available. - These tools are a free download for your version of Visual Studio that allow you to write, deploy and debug applications for Microsoft Azure in a range of programming languages. @@ -145,7 +142,13 @@ Some manual steps will be required to configure your project. &Download and install now You will need to restart Visual Studio after installation. - + + Unable to start wizard: failed to load Node Tools support Package (0x{0:X08}) + + + Unable to start wizard: Unexpected error 0x{0:X08} + + Unable to start wizard: no automation object available. \ No newline at end of file From e074e55f0ebfbb63d2dd5342424808c037b5db55 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Fri, 25 Aug 2017 10:59:22 -0700 Subject: [PATCH 3/3] PR feedback --- Nodejs/Product/Nodejs/NodejsTools.vsct | 1 + Nodejs/Product/ProjectWizard/ImportWizard.cs | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Nodejs/Product/Nodejs/NodejsTools.vsct b/Nodejs/Product/Nodejs/NodejsTools.vsct index e9e0c5b01..5c6beb2a7 100644 --- a/Nodejs/Product/Nodejs/NodejsTools.vsct +++ b/Nodejs/Product/Nodejs/NodejsTools.vsct @@ -210,6 +210,7 @@ +