From ea930e025c047094fa68954ba52decf39264fc25 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 16 Jan 2019 10:43:26 -0600 Subject: [PATCH 1/4] Switch to MSBuild.Sdk.Extras for WPF support --- .../ILSpy.BamlDecompiler.Tests.csproj | 14 ++++--------- ILSpy/ILSpy.csproj | 21 ++++--------------- SharpTreeView/ICSharpCode.TreeView.csproj | 10 ++++----- TestPlugin/TestPlugin.csproj | 10 ++++----- global.json | 5 +++++ 5 files changed, 21 insertions(+), 39 deletions(-) create mode 100644 global.json diff --git a/ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj b/ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj index 18c13fc75..f5923fd80 100644 --- a/ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj +++ b/ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj @@ -1,5 +1,5 @@  - + net46 @@ -7,11 +7,9 @@ False false - - - - - $(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets + true + false + false @@ -99,8 +97,4 @@ - - - - \ No newline at end of file diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index beb5823a6..a90bcbddb 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -1,5 +1,5 @@  - + net46 @@ -8,6 +8,9 @@ False false + true + false + false ICSharpCode.ILSpy @@ -34,11 +37,6 @@ ..\ICSharpCode.Decompiler\ICSharpCode.Decompiler.ruleset - - - $(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets - - @@ -258,7 +256,6 @@ - @@ -392,16 +389,6 @@ - - - - false - - - - $(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets - - diff --git a/TestPlugin/TestPlugin.csproj b/TestPlugin/TestPlugin.csproj index 4ded52538..36058d340 100644 --- a/TestPlugin/TestPlugin.csproj +++ b/TestPlugin/TestPlugin.csproj @@ -1,5 +1,5 @@  - + net461 @@ -8,6 +8,9 @@ False False + true + false + false @@ -21,11 +24,6 @@ true - - - $(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets - - diff --git a/global.json b/global.json new file mode 100644 index 000000000..8067f2c2a --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "msbuild-sdks": { + "MSBuild.Sdk.Extras": "1.6.65" + } +} From 6a2eab2a527272bb45dcbb4e99bcfba17b21350f Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 16 Jan 2019 11:13:20 -0600 Subject: [PATCH 2/4] Switch to AsyncPackage with background load --- ILSpy.AddIn/Commands/OpenCodeItemCommand.cs | 3 ++ ILSpy.AddIn/Commands/OpenILSpyCommand.cs | 5 +++ .../Commands/OpenProjectOutputCommand.cs | 3 ++ ILSpy.AddIn/Commands/OpenReferenceCommand.cs | 3 ++ ILSpy.AddIn/ILSpyAddInPackage.cs | 36 +++++++++++++------ 5 files changed, 39 insertions(+), 11 deletions(-) diff --git a/ILSpy.AddIn/Commands/OpenCodeItemCommand.cs b/ILSpy.AddIn/Commands/OpenCodeItemCommand.cs index 958b0e00a..0f26fa2d6 100644 --- a/ILSpy.AddIn/Commands/OpenCodeItemCommand.cs +++ b/ILSpy.AddIn/Commands/OpenCodeItemCommand.cs @@ -18,6 +18,7 @@ namespace ICSharpCode.ILSpy.AddIn.Commands public OpenCodeItemCommand(ILSpyAddInPackage owner) : base(owner, PkgCmdIDList.cmdidOpenCodeItemInILSpy) { + ThreadHelper.ThrowIfNotOnUIThread(); } protected override void OnBeforeQueryStatus(object sender, EventArgs e) @@ -185,6 +186,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands internal static void Register(ILSpyAddInPackage owner) { + ThreadHelper.ThrowIfNotOnUIThread(); + instance = new OpenCodeItemCommand(owner); } } diff --git a/ILSpy.AddIn/Commands/OpenILSpyCommand.cs b/ILSpy.AddIn/Commands/OpenILSpyCommand.cs index 6f1261d3c..317004f50 100644 --- a/ILSpy.AddIn/Commands/OpenILSpyCommand.cs +++ b/ILSpy.AddIn/Commands/OpenILSpyCommand.cs @@ -32,6 +32,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands protected ILSpyCommand(ILSpyAddInPackage owner, uint id) { + ThreadHelper.ThrowIfNotOnUIThread(); + this.owner = owner; CommandID menuCommandID = new CommandID(GuidList.guidILSpyAddInCmdSet, (int)id); OleMenuCommand menuItem = new OleMenuCommand(OnExecute, menuCommandID); @@ -120,6 +122,7 @@ namespace ICSharpCode.ILSpy.AddIn.Commands public OpenILSpyCommand(ILSpyAddInPackage owner) : base(owner, PkgCmdIDList.cmdidOpenILSpy) { + ThreadHelper.ThrowIfNotOnUIThread(); } protected override void OnExecute(object sender, EventArgs e) @@ -129,6 +132,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands internal static void Register(ILSpyAddInPackage owner) { + ThreadHelper.ThrowIfNotOnUIThread(); + instance = new OpenILSpyCommand(owner); } } diff --git a/ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs b/ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs index 924f8deaa..8fd06a50c 100644 --- a/ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs +++ b/ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs @@ -12,6 +12,7 @@ namespace ICSharpCode.ILSpy.AddIn.Commands public OpenProjectOutputCommand(ILSpyAddInPackage owner) : base(owner, PkgCmdIDList.cmdidOpenProjectOutputInILSpy) { + ThreadHelper.ThrowIfNotOnUIThread(); } protected override void OnBeforeQueryStatus(object sender, EventArgs e) @@ -36,6 +37,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands internal static void Register(ILSpyAddInPackage owner) { + ThreadHelper.ThrowIfNotOnUIThread(); + instance = new OpenProjectOutputCommand(owner); } } diff --git a/ILSpy.AddIn/Commands/OpenReferenceCommand.cs b/ILSpy.AddIn/Commands/OpenReferenceCommand.cs index 682f5659d..5c2b61fa8 100644 --- a/ILSpy.AddIn/Commands/OpenReferenceCommand.cs +++ b/ILSpy.AddIn/Commands/OpenReferenceCommand.cs @@ -17,6 +17,7 @@ namespace ICSharpCode.ILSpy.AddIn.Commands public OpenReferenceCommand(ILSpyAddInPackage owner) : base(owner, PkgCmdIDList.cmdidOpenReferenceInILSpy) { + ThreadHelper.ThrowIfNotOnUIThread(); } protected override void OnBeforeQueryStatus(object sender, EventArgs e) @@ -87,6 +88,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands internal static void Register(ILSpyAddInPackage owner) { + ThreadHelper.ThrowIfNotOnUIThread(); + instance = new OpenReferenceCommand(owner); } } diff --git a/ILSpy.AddIn/ILSpyAddInPackage.cs b/ILSpy.AddIn/ILSpyAddInPackage.cs index fe1d19bdc..aedbda510 100644 --- a/ILSpy.AddIn/ILSpyAddInPackage.cs +++ b/ILSpy.AddIn/ILSpyAddInPackage.cs @@ -3,6 +3,8 @@ using System.Diagnostics; using System.Globalization; using System.Runtime.InteropServices; using System.ComponentModel.Design; +using System.Threading; +using Microsoft; using Microsoft.VisualStudio; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Shell; @@ -11,6 +13,7 @@ using Microsoft.VisualStudio.ComponentModelHost; using Microsoft.VisualStudio.LanguageServices; using EnvDTE; using System.Collections.Generic; +using Task = System.Threading.Tasks.Task; namespace ICSharpCode.ILSpy.AddIn { @@ -26,15 +29,15 @@ namespace ICSharpCode.ILSpy.AddIn /// // This attribute tells the PkgDef creation utility (CreatePkgDef.exe) that this class is // a package. - [PackageRegistration(UseManagedResourcesOnly = true)] + [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)] // This attribute is used to register the information needed to show this package // in the Help/About dialog of Visual Studio. [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] // This attribute is needed to let the shell know that this package exposes some menus. [ProvideMenuResource("Menus.ctmenu", 1)] [Guid(GuidList.guidILSpyAddInPkgString)] - [ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_string)] - public sealed class ILSpyAddInPackage : Package + [ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_string, PackageAutoLoadFlags.BackgroundLoad)] + public sealed class ILSpyAddInPackage : AsyncPackage { /// /// Default constructor of the package. @@ -65,19 +68,24 @@ namespace ICSharpCode.ILSpy.AddIn /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// - protected override void Initialize() + protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress progress) { - Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); - base.Initialize(); + Debug.WriteLine($"Entering {nameof(InitializeAsync)}() of: {this}"); + + await base.InitializeAsync(cancellationToken, progress); + + await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + cancellationToken.ThrowIfCancellationRequested(); + + var componentModel = (IComponentModel)await GetServiceAsync(typeof(SComponentModel)); + Assumes.Present(componentModel); // Add our command handlers for menu (commands must exist in the .vsct file) - this.menuService = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; + this.menuService = (OleMenuCommandService)await GetServiceAsync(typeof(IMenuCommandService)); + Assumes.Present(menuService); - var componentModel = (IComponentModel)this.GetService(typeof(SComponentModel)); this.workspace = componentModel.GetService(); - - if (menuService == null || workspace == null) - return; + Assumes.Present(workspace); OpenILSpyCommand.Register(this); OpenProjectOutputCommand.Register(this); @@ -88,16 +96,22 @@ namespace ICSharpCode.ILSpy.AddIn public void ShowMessage(string format, params object[] items) { + ThreadHelper.ThrowIfNotOnUIThread(); + ShowMessage(OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_INFO, format, items); } public void ShowMessage(OLEMSGICON icon, string format, params object[] items) { + ThreadHelper.ThrowIfNotOnUIThread(); + ShowMessage(OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, icon, format, items); } public int ShowMessage(OLEMSGBUTTON buttons, OLEMSGDEFBUTTON defaultButton, OLEMSGICON icon, string format, params object[] items) { + ThreadHelper.ThrowIfNotOnUIThread(); + IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell)); Guid clsid = Guid.Empty; int result; From 6af75ce358c4568018e4832a43ea4869c550665e Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 16 Jan 2019 11:14:14 -0600 Subject: [PATCH 3/4] Update references --- ILSpy.AddIn/Commands/OpenILSpyCommand.cs | 4 ++-- ILSpy.AddIn/ILSpy.AddIn.csproj | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ILSpy.AddIn/Commands/OpenILSpyCommand.cs b/ILSpy.AddIn/Commands/OpenILSpyCommand.cs index 317004f50..898393005 100644 --- a/ILSpy.AddIn/Commands/OpenILSpyCommand.cs +++ b/ILSpy.AddIn/Commands/OpenILSpyCommand.cs @@ -6,9 +6,9 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; -using EnvDTE80; using Microsoft.VisualStudio.Shell; using Mono.Cecil; +using DTEConstants = EnvDTE.Constants; namespace ICSharpCode.ILSpy.AddIn.Commands { @@ -98,7 +98,7 @@ namespace ICSharpCode.ILSpy.AddIn.Commands protected EnvDTE.Project FindProject(IEnumerable projects, string projectFile) { foreach (var project in projects) { - if (project.Kind == ProjectKinds.vsProjectKindSolutionFolder) { + if (project.Kind == DTEConstants.vsProjectKindSolutionItems) { // This is a solution folder -> search in sub-projects var subProject = FindProject( project.ProjectItems.OfType().Select(pi => pi.SubProject).OfType(), diff --git a/ILSpy.AddIn/ILSpy.AddIn.csproj b/ILSpy.AddIn/ILSpy.AddIn.csproj index f3b2dd135..c8bb0b57b 100644 --- a/ILSpy.AddIn/ILSpy.AddIn.csproj +++ b/ILSpy.AddIn/ILSpy.AddIn.csproj @@ -51,9 +51,11 @@ - + + + From e8abb788b4b4b6a842ea2f0f867717282657d077 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 16 Jan 2019 11:14:31 -0600 Subject: [PATCH 4/4] Remove duplicate VSIX installation targets --- ILSpy.AddIn/source.extension.vsixmanifest.template | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ILSpy.AddIn/source.extension.vsixmanifest.template b/ILSpy.AddIn/source.extension.vsixmanifest.template index f2c56a440..b87e1d1dc 100644 --- a/ILSpy.AddIn/source.extension.vsixmanifest.template +++ b/ILSpy.AddIn/source.extension.vsixmanifest.template @@ -9,10 +9,6 @@ ILSpy-Large.ico - - - -