From 623d7bf624cfa5a9b6fb3a58c9b833460a68afdf Mon Sep 17 00:00:00 2001 From: Alistair Chapman Date: Tue, 19 Mar 2019 15:38:01 -0700 Subject: [PATCH] Update to new VS2019 SDKs and APIs. Migrate to an AsyncPackage load. Signed-off-by: Alistair Chapman --- src/CakePackage.cs | 25 +++-- src/Menus/InstallBootstrapperCommand.cs | 7 +- src/Menus/InstallConfigFileCommand.cs | 7 +- src/Menus/InstallShellBootstrapperCommand.cs | 7 +- src/source.extension.vsixmanifest | 95 +++++++++---------- .../AddinTemplate/AddinTemplate.vstemplate | 5 + .../AddinTestBasicTemplate.vstemplate | 5 + .../AddinTestTemplate.vstemplate | 5 + template/ItemTemplate/ItemTemplate.vstemplate | 2 + .../ModuleTemplate/ModuleTemplate.vstemplate | 5 + 10 files changed, 87 insertions(+), 76 deletions(-) diff --git a/src/CakePackage.cs b/src/CakePackage.cs index 3394404..a05bfae 100644 --- a/src/CakePackage.cs +++ b/src/CakePackage.cs @@ -3,38 +3,42 @@ // See the LICENSE file in the project root for more information. using System.Runtime.InteropServices; -using System.ComponentModel.Design; using Cake.VisualStudio.ContentType; using Cake.VisualStudio.Helpers; using EnvDTE; using EnvDTE80; using Microsoft.VisualStudio; -using Microsoft.VisualStudio.OLE.Interop; using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Interop; +using System; +using System.Threading; +using IServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider; namespace Cake.VisualStudio { - [PackageRegistration(UseManagedResourcesOnly = true)] + [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)] [InstalledProductRegistration("#110", "#112", Vsix.Version, IconResourceID = 400)] - [ProvideAutoLoad(UIContextGuids80.SolutionExists)] + [ProvideAutoLoad(UIContextGuids80.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)] [Guid(PackageGuids.guidCakePackageString)] [ProvideMenuResource("Menus.ctmenu", 1)] [ProvideLanguageService(typeof(CakeLanguageService), Helpers.Constants.CakeContentType, 100)] [ProvideLanguageExtension(typeof(CakeLanguageService), ".cake")] - public sealed partial class CakePackage : Package, IVsShellPropertyEvents + public sealed partial class CakePackage : AsyncPackage, IVsShellPropertyEvents { private static DTE2 _dte; internal static DTE2 Dte => _dte ?? (_dte = (DTE2) GetGlobalService(typeof(DTE))); internal static IVsUIShell Shell => _shell ?? (_shell = (IVsUIShell) GetGlobalService(typeof(IVsUIShell))); - uint _cookie; private static IVsUIShell _shell; - protected override void Initialize() + protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress progress) { Logger.Initialize(this, Vsix.Name); - base.Initialize(); + //base.Initialize(); + + // switch to the UI thread + await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + var shellService = GetService(typeof(SVsShell)) as IVsShell; if (shellService != null) @@ -45,6 +49,7 @@ protected override void Initialize() Menus.InstallBootstrapperCommand.Initialize(this); Menus.InstallShellBootstrapperCommand.Initialize(this); Menus.InstallConfigFileCommand.Initialize(this); + //return base.InitializeAsync(cancellationToken, progress); } public static bool IsDocumentDirty(string documentPath, out IVsPersistDocData persistDocData) @@ -74,15 +79,15 @@ public int OnShellPropertyChange(int propid, object var) if ((bool)var == false) { // zombie state dependent code - // Dte = (DTE2)GetService(typeof(DTE)); // eventlistener no longer needed var shellService = GetService(typeof(SVsShell)) as IVsShell; if (shellService != null) - + { ErrorHandler.ThrowOnFailure(shellService.UnadviseShellPropertyChanges(_cookie)); + } _cookie = 0; } diff --git a/src/Menus/InstallBootstrapperCommand.cs b/src/Menus/InstallBootstrapperCommand.cs index affa047..3f730e3 100644 --- a/src/Menus/InstallBootstrapperCommand.cs +++ b/src/Menus/InstallBootstrapperCommand.cs @@ -38,12 +38,7 @@ internal sealed class InstallBootstrapperCommand /// Owner _package, not null. private InstallBootstrapperCommand(Package package) { - if (package == null) - { - throw new ArgumentNullException("package"); - } - - _package = package; + _package = package ?? throw new ArgumentNullException("package"); var commandService = ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (commandService != null) diff --git a/src/Menus/InstallConfigFileCommand.cs b/src/Menus/InstallConfigFileCommand.cs index 758268a..787802d 100644 --- a/src/Menus/InstallConfigFileCommand.cs +++ b/src/Menus/InstallConfigFileCommand.cs @@ -38,12 +38,7 @@ internal sealed class InstallConfigFileCommand /// Owner _package, not null. private InstallConfigFileCommand(Package package) { - if (package == null) - { - throw new ArgumentNullException("package"); - } - - _package = package; + _package = package ?? throw new ArgumentNullException("package"); var commandService = ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (commandService != null) diff --git a/src/Menus/InstallShellBootstrapperCommand.cs b/src/Menus/InstallShellBootstrapperCommand.cs index acf20cb..8662a9b 100644 --- a/src/Menus/InstallShellBootstrapperCommand.cs +++ b/src/Menus/InstallShellBootstrapperCommand.cs @@ -38,12 +38,7 @@ internal sealed class InstallShellBootstrapperCommand /// Owner _package, not null. private InstallShellBootstrapperCommand(Package package) { - if (package == null) - { - throw new ArgumentNullException("package"); - } - - _package = package; + _package = package ?? throw new ArgumentNullException("package"); var commandService = ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (commandService != null) diff --git a/src/source.extension.vsixmanifest b/src/source.extension.vsixmanifest index a0a6bb9..20eb06d 100644 --- a/src/source.extension.vsixmanifest +++ b/src/source.extension.vsixmanifest @@ -1,51 +1,50 @@  - - - Cake for Visual Studio - Adds support for the Cake build tool in Visual Studio 2015 and 2017. Includes support for the Task Runner Explorer, new templates and bootstrapping important Cake files. - https://github.com/cake-build/cake-vs - Resources\LICENSE - Resources\icon.png - Resources\preview.png - cake, build - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + Cake for Visual Studio + Adds support for the Cake build tool in Visual Studio 2015 and 2017. Includes support for the Task Runner Explorer, new templates and bootstrapping important Cake files. + https://github.com/cake-build/cake-vs + Resources\LICENSE + Resources\icon.png + Resources\preview.png + cake, build + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/template/AddinTemplate/AddinTemplate.vstemplate b/template/AddinTemplate/AddinTemplate.vstemplate index 6866068..0f431e7 100644 --- a/template/AddinTemplate/AddinTemplate.vstemplate +++ b/template/AddinTemplate/AddinTemplate.vstemplate @@ -5,6 +5,11 @@ Basic project template for creating a new Cake addin AddinTemplate.ico CSharp + csharp + linux + windows + macos + Cake 4.5 1000 10dcbe21-0d84-4a5b-88a3-220e234a7211 diff --git a/template/AddinTestBasicTemplate/AddinTestBasicTemplate.vstemplate b/template/AddinTestBasicTemplate/AddinTestBasicTemplate.vstemplate index 365eb92..adabbbf 100644 --- a/template/AddinTestBasicTemplate/AddinTestBasicTemplate.vstemplate +++ b/template/AddinTestBasicTemplate/AddinTestBasicTemplate.vstemplate @@ -7,6 +7,11 @@ Basic project template for creating unit tests for a Cake addin CakeTestTemplate.ico CSharp + csharp + linux + windows + macos + Cake 4.5 1000 8632940c-cc4f-4a8a-abc9-79c00818f4ef diff --git a/template/AddinTestTemplate/AddinTestTemplate.vstemplate b/template/AddinTestTemplate/AddinTestTemplate.vstemplate index 99e1429..9f706ad 100644 --- a/template/AddinTestTemplate/AddinTestTemplate.vstemplate +++ b/template/AddinTestTemplate/AddinTestTemplate.vstemplate @@ -7,6 +7,11 @@ Basic project template, including samples, for creating unit tests for a Cake addin CakeTestTemplate.ico CSharp + csharp + linux + windows + macos + Cake 4.5 1000 8e115642-736f-4d2d-975e-551dbfc1a088 diff --git a/template/ItemTemplate/ItemTemplate.vstemplate b/template/ItemTemplate/ItemTemplate.vstemplate index e0bc237..55f14ba 100644 --- a/template/ItemTemplate/ItemTemplate.vstemplate +++ b/template/ItemTemplate/ItemTemplate.vstemplate @@ -6,6 +6,8 @@ ItemTemplate.ico 7d181506-47e9-4f9d-8ac3-5ac65f6b8354 CSharp + csharp + Cake 1 build.cake diff --git a/template/ModuleTemplate/ModuleTemplate.vstemplate b/template/ModuleTemplate/ModuleTemplate.vstemplate index f9c23e1..406b3ce 100644 --- a/template/ModuleTemplate/ModuleTemplate.vstemplate +++ b/template/ModuleTemplate/ModuleTemplate.vstemplate @@ -7,6 +7,11 @@ Basic project template for creating a new Cake module, including a sample module. ModuleTemplate.ico CSharp + csharp + linux + windows + macos + Cake 4.5 1000 5e03cc59-29b1-40df-a2a4-042532a23176