-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathLibraryManagerPackage.cs
More file actions
97 lines (85 loc) · 4.39 KB
/
LibraryManagerPackage.cs
File metadata and controls
97 lines (85 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) .NET Foundation. 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.ComponentModel.Composition;
using System.ComponentModel.Design;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.ServiceBroker;
using Microsoft.Web.LibraryManager.Vsix.Commands;
using Microsoft.Web.LibraryManager.Vsix.Contracts;
using Microsoft.Web.LibraryManager.Vsix.Shared;
using NuGet.VisualStudio.Contracts;
using Tasks = System.Threading.Tasks;
namespace Microsoft.Web.LibraryManager.Vsix
{
[Guid(PackageGuids.guidPackageString)]
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[ProvideMenuResource("Menus.ctmenu", 1)]
[ProvideUIContextRule(PackageGuids.guidUiContextConfigFileString,
name: "ConfigFile",
expression: "(WAP | WebSite | DotNetCoreWeb ) & Config",
termNames: new string[] {
"WAP",
"WebSite",
"DotNetCoreWeb",
"Config"
},
termValues: new string[] {
"ActiveProjectFlavor:" + Constants.WAP,
"ActiveProjectFlavor:" + Constants.WebsiteProject,
"ActiveProjectCapability:" + Constants.DotNetCoreWebCapability,
"HierSingleSelectionName:" + Constants.ConfigFileName + "$" })]
[ProvideUIContextRule(PackageGuids.guidUiContextString,
name: Vsix.Name,
expression: "(WAP | WebSite | DotNetCoreWeb )",
termNames: new string[] {
"WAP",
"WebSite",
"DotNetCoreWeb"
},
termValues: new string[] {
"ActiveProjectFlavor:" + Constants.WAP,
"ActiveProjectFlavor:" + Constants.WebsiteProject,
"ActiveProjectCapability:" + Constants.DotNetCoreWebCapability })]
internal sealed class LibraryManagerPackage : AsyncPackage
{
[Import]
internal ILibraryCommandService LibraryCommandService { get; set; }
[Import]
internal IDependenciesFactory DependenciesFactory { get; private set; }
[SuppressMessage("Reliability", "ISB001:Dispose of proxies", Justification = "It is in Dispose()")]
public INuGetProjectService NugetProjectService { get; private set; }
protected override async Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
var componentModel = GetService(typeof(SComponentModel)) as IComponentModel;
Assumes.Present(componentModel);
componentModel.DefaultCompositionService.SatisfyImportsOnce(this);
IAsyncServiceProvider asyncServiceProvider = this;
IBrokeredServiceContainer brokeredServiceContainer = await asyncServiceProvider.GetServiceAsync<SVsBrokeredServiceContainer, IBrokeredServiceContainer>();
ServiceHub.Framework.IServiceBroker serviceBroker = brokeredServiceContainer.GetFullAccessServiceBroker();
#pragma warning disable ISB001 // Dispose of proxies
NugetProjectService = await serviceBroker.GetProxyAsync<INuGetProjectService>(NuGetServices.NuGetProjectServiceV1);
#pragma warning restore ISB001 // Dispose of proxies
var commandService = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (commandService != null && LibraryCommandService != null)
{
InstallLibraryCommand.Initialize(this, commandService, LibraryCommandService, DependenciesFactory);
CleanCommand.Initialize(this, commandService, LibraryCommandService);
RestoreCommand.Initialize(this, commandService, LibraryCommandService);
RestoreSolutionCommand.Initialize(this, commandService, LibraryCommandService);
RestoreOnBuildCommand.Initialize(this, commandService, DependenciesFactory);
ManageLibrariesCommand.Initialize(this, commandService, LibraryCommandService, DependenciesFactory);
}
}
protected override void Dispose(bool disposing)
{
(NugetProjectService as IDisposable)?.Dispose();
base.Dispose(disposing);
}
}
}