Datei: NDOPackage/NDOPackage.cs

Last Commit (bff399f)
1 //
2 // Copyright (c) 2002-2019 Mirko Matytschak
3 // (www.netdataobjects.de)
4 //
5 // Author: Mirko Matytschak
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10 // Software, and to permit persons to whom the Software is furnished to do so, subject to the following
11 // conditions:
12
13 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
14 // of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22 global using Community.VisualStudio.Toolkit;
23 global using Microsoft.VisualStudio.Shell;
24 global using System;
25 global using Task = System.Threading.Tasks.Task;
26 using dte=EnvDTE;
27 using Microsoft.VisualStudio.Shell.Interop;
28 using System.Runtime.InteropServices;
29 using System.Threading;
 
 
 
 
 
 
30
31 namespace NDOVsPackage
32 {
33 ····[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
34 ····[InstalledProductRegistration(Vsix.Name, Vsix.Description, Vsix.Version)]
35 ····[ProvideAutoLoad(UIContextGuids80.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)]
36 ····[ProvideMenuResource("Menus.ctmenu", 1)]
37 ····[Guid(PackageGuids.NDOPackageString)]
38 ····public sealed class NDOPackage : ToolkitPackage
39 ····{
40 ········BuildEventHandler buildEventHandler;
 
 
41 ········protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
42 ········{
43 ············await this.RegisterCommandsAsync();
44 ············await JoinableTaskFactory.SwitchToMainThreadAsync();
45 ············var dte = (dte._DTE) await this.GetServiceAsync(typeof(dte._DTE));
46 ············ApplicationObject.VisualStudioApplication = dte;
47 ············this.buildEventHandler = new BuildEventHandler();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48 ········}
 
 
 
 
49 ····}
50 }
New Commit (90ec57c)
1 //
2 // Copyright (c) 2002-2019 Mirko Matytschak
3 // (www.netdataobjects.de)
4 //
5 // Author: Mirko Matytschak
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10 // Software, and to permit persons to whom the Software is furnished to do so, subject to the following
11 // conditions:
12
13 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
14 // of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22 global using Community.VisualStudio.Toolkit;
23 global using Microsoft.VisualStudio.Shell;
24 global using System;
25 global using Task = System.Threading.Tasks.Task;
26 using dte=EnvDTE;
27 using Microsoft.VisualStudio.Shell.Interop;
28 using System.Runtime.InteropServices;
29 using System.Threading;
30 using Microsoft.VisualStudio.Shell.ServiceBroker;
31 using Microsoft.VisualStudio;
32 using NuGet.VisualStudio.Contracts;
33 using System.Linq;
34 using System.Threading.Tasks;
35 using System.Text.RegularExpressions;
36
37 namespace NDOVsPackage
38 {
39 ····[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
40 ····[InstalledProductRegistration(Vsix.Name, Vsix.Description, Vsix.Version)]
41 ····[ProvideAutoLoad(UIContextGuids80.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)]
42 ····[ProvideMenuResource("Menus.ctmenu", 1)]
43 ····[Guid(PackageGuids.NDOPackageString)]
44 ····public sealed class NDOPackage : ToolkitPackage
45 ····{
46 ········BuildEventHandler buildEventHandler;
47 ········public static NDOPackage Instance { get; set; }
48 ········static Regex regex = new Regex(@"(\d)\.(\d)", RegexOptions.Compiled);
49 ········protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
50 ········{
51 ············await this.RegisterCommandsAsync();
52 ············await JoinableTaskFactory.SwitchToMainThreadAsync();
53 ············var dte = (dte._DTE) await this.GetServiceAsync(typeof(dte._DTE));
54 ············ApplicationObject.VisualStudioApplication = dte;
55 ············this.buildEventHandler = new BuildEventHandler();
56 ············Instance = this;
57 ········}
58
59
60 ········public async Task<NuGetInstalledPackage> GetNdoPackageAsync( Project project )
61 ········{
62 ············var brokeredServiceContainer = await NDOPackage.Instance.GetServiceAsync<SVsBrokeredServiceContainer, IBrokeredServiceContainer>();
63 ············if (brokeredServiceContainer != null)
64 ············{
65 ················var serviceBroker = brokeredServiceContainer.GetFullAccessServiceBroker();
66 ················using (var disposable = await serviceBroker.GetProxyAsync<INuGetProjectService>( NuGetServices.NuGetProjectServiceV1 ) as IDisposable)
67 ················{
68 ····················var nugetService = disposable as INuGetProjectService;
69 ····················var hier = project.GetVsHierarchy();
70 ····················hier.GetGuidProperty( VSConstants.VSITEMID_ROOT,
71 ················································(int) __VSHPROPID.VSHPROPID_ProjectIDGuid,
72 ················································out Guid projGuid );
73 ····················var packagesResult = await nugetService.GetInstalledPackagesAsync( projGuid, CancellationToken.None );
74 ····················return packagesResult.Packages.FirstOrDefault( p => String.Compare( "ndo.dll", p.Id, true ) == 0 );
75 ················}
76 ············}
77
78 ············return null;
79 ········}
80
81 ········public async Task<string> GetNdoVersionAsync( Project project )
82 ········{
83 ············var ndoPackage = await GetNdoPackageAsync(project);
84 ············if (ndoPackage != null)
85 ············{
86 ················var match = regex.Match(ndoPackage.Version);
87 ················var major = int.Parse(match.Groups[1].Value);
88 ················if (major >= 5)
89 ····················return "5.0";
90 ············}
91
92 ············return "4.0";
93 ········}
94
95 ····}
96 }