1
1
using System ;
2
2
using System . ComponentModel . Composition ;
3
3
using System . Globalization ;
4
+ using System . IO ;
5
+ using System . Reflection ;
4
6
using System . Runtime . InteropServices ;
5
7
using GitHub . Extensions ;
6
8
using GitHub . Models ;
12
14
using Microsoft . VisualStudio . Shell ;
13
15
using Microsoft . VisualStudio . Shell . Interop ;
14
16
using Octokit ;
17
+ using System . Linq ;
15
18
16
19
namespace GitHub . VisualStudio
17
20
{
18
- /// <summary>
19
- /// This is the class that implements the package exposed by this assembly.
20
- ///
21
- /// The minimum requirement for a class to be considered a valid package for Visual Studio
22
- /// is to implement the IVsPackage interface and register itself with the shell.
23
- /// This package uses the helper classes defined inside the Managed Package Framework (MPF)
24
- /// to do it: it derives from the Package class that provides the implementation of the
25
- /// IVsPackage interface and uses the registration attributes defined in the framework to
26
- /// register itself and its components with the shell.
27
- /// </summary>
28
- // This attribute tells the PkgDef creation utility (CreatePkgDef.exe) that this class is
29
- // a package.
30
21
[ PackageRegistration ( UseManagedResourcesOnly = true ) ]
31
- // This attribute is used to register the information needed to show this package
32
- // in the Help/About dialog of Visual Studio.
33
22
[ InstalledProductRegistration ( "#110" , "#112" , "1.0" , IconResourceID = 400 ) ]
34
23
[ Guid ( GuidList . guidGitHubPkgString ) ]
35
24
//[ProvideBindingPath]
36
25
[ ProvideMenuResource ( "Menus.ctmenu" , 1 ) ]
37
26
//[ProvideAutoLoad(UIContextGuids.NoSolution)]
27
+ // this is the Git service GUID, so we load whenever it loads
38
28
[ ProvideAutoLoad ( "11B8E6D7-C08B-4385-B321-321078CDD1F8" ) ]
39
29
[ ProvideToolWindow ( typeof ( GitHubPane ) , Orientation = ToolWindowOrientation . Right , Style = VsDockStyle . Tabbed , Window = EnvDTE . Constants . vsWindowKindSolutionExplorer ) ]
40
30
[ ProvideOptionPage ( typeof ( OptionsPage ) , "GitHub for Visual Studio" , "General" , 0 , 0 , supportsAutomation : true ) ]
41
- public class GitHubPackage : PackageBase
31
+ public class GitHubPackage : Package
42
32
{
33
+ // list of assemblies to be loaded from the extension installation path
34
+ static readonly string [ ] ourAssemblies =
35
+ {
36
+ "GitHub.Api" ,
37
+ "GitHub.App" ,
38
+ "GitHub.CredentialManagement" ,
39
+ "GitHub.Exports" ,
40
+ "GitHub.Exports.Reactive" ,
41
+ "GitHub.Extensions" ,
42
+ "GitHub.Extensions.Reactive" ,
43
+ "GitHub.UI" ,
44
+ "GitHub.UI.Reactive" ,
45
+ "GitHub.VisualStudio" ,
46
+ "GitHub.TeamFoundation" ,
47
+ "GitHub.TeamFoundation.14" ,
48
+ "GitHub.TeamFoundation.15" ,
49
+ "GitHub.VisualStudio.UI" ,
50
+ "System.Windows.Interactivity"
51
+ } ;
52
+
53
+ readonly IServiceProvider serviceProvider ;
54
+
43
55
public GitHubPackage ( )
44
56
{
57
+ serviceProvider = this ;
45
58
}
46
59
47
60
public GitHubPackage ( IServiceProvider serviceProvider )
48
- : base ( serviceProvider )
49
61
{
62
+ this . serviceProvider = serviceProvider ;
50
63
}
51
64
52
-
53
65
protected override void Initialize ( )
54
66
{
67
+ AppDomain . CurrentDomain . AssemblyResolve += LoadAssemblyFromRunDir ;
68
+
55
69
base . Initialize ( ) ;
56
70
57
- var menus = ServiceProvider . GetExportedValue < IMenuProvider > ( ) ;
71
+ var menus = serviceProvider . GetExportedValue < IMenuProvider > ( ) ;
58
72
foreach ( var menu in menus . Menus )
59
- ServiceProvider . AddTopLevelMenuItem ( menu . Guid , menu . CmdId , ( s , e ) => menu . Activate ( ) ) ;
73
+ serviceProvider . AddTopLevelMenuItem ( menu . Guid , menu . CmdId , ( s , e ) => menu . Activate ( ) ) ;
60
74
61
75
foreach ( var menu in menus . DynamicMenus )
62
- ServiceProvider . AddDynamicMenuItem ( menu . Guid , menu . CmdId , menu . CanShow , menu . Activate ) ;
76
+ serviceProvider . AddDynamicMenuItem ( menu . Guid , menu . CmdId , menu . CanShow , menu . Activate ) ;
77
+ }
78
+
79
+ [ System . Diagnostics . CodeAnalysis . SuppressMessageAttribute ( "Microsoft.Reliability" , "CA2001:AvoidCallingProblematicMethods" ) ]
80
+ static Assembly LoadAssemblyFromRunDir ( object sender , ResolveEventArgs e )
81
+ {
82
+ try
83
+ {
84
+ var name = new AssemblyName ( e . Name ) ;
85
+ if ( ! ourAssemblies . Contains ( name . Name ) )
86
+ return null ;
87
+ var path = Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) ;
88
+ var filename = Path . Combine ( path , name . Name + ".dll" ) ;
89
+ if ( ! File . Exists ( filename ) )
90
+ return null ;
91
+ return Assembly . LoadFrom ( filename ) ;
92
+ }
93
+ catch ( Exception ex )
94
+ {
95
+ var log = string . Format ( CultureInfo . CurrentCulture ,
96
+ "Error occurred loading {0} from {1}.{2}{3}{4}" ,
97
+ e . Name ,
98
+ Assembly . GetExecutingAssembly ( ) . Location ,
99
+ Environment . NewLine ,
100
+ ex ,
101
+ Environment . NewLine ) ;
102
+ VsOutputLogger . Write ( log ) ;
103
+ }
104
+ return null ;
63
105
}
64
106
}
65
107
@@ -70,7 +112,6 @@ public class GHClient : GitHubClient
70
112
public GHClient ( IProgram program )
71
113
: base ( program . ProductHeader )
72
114
{
73
-
74
115
}
75
116
}
76
117
}
0 commit comments