Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 7a88701

Browse files
committed
Put the assembly resolver in the package class
Instead of relying on the xaml controls to include the class that hooks up the resolver, just hook it up on package initialization so it always runs. Also, remove useless base package class, it's not really doing anything useful.
1 parent e5a67eb commit 7a88701

File tree

6 files changed

+114
-169
lines changed

6 files changed

+114
-169
lines changed

src/GitHub.VisualStudio/Base/PackageBase.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/GitHub.VisualStudio/GitHub.VisualStudio.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@
214214
<Compile Include="Menus\AddConnection.cs" />
215215
<Compile Include="Menus\CopyLink.cs" />
216216
<Compile Include="Menus\MenuProvider.cs" />
217-
<Compile Include="Base\PackageBase.cs" />
218217
<Compile Include="Properties\AssemblyInfo.cs" />
219218
<Compile Include="Helpers\Browser.cs" />
220219
<Compile Include="Settings\Constants.cs" />
@@ -375,10 +374,6 @@
375374
<Generator>MSBuild:Compile</Generator>
376375
<CustomToolNamespace>GitHub.VisualStudio.UI</CustomToolNamespace>
377376
</Page>
378-
<Page Include="UI\Settings\OptionsStyles.xaml">
379-
<SubType>Designer</SubType>
380-
<Generator>MSBuild:Compile</Generator>
381-
</Page>
382377
<Page Include="UI\Views\Controls\ActionLinkButton.xaml">
383378
<SubType>Designer</SubType>
384379
<Generator>MSBuild:Compile</Generator>
Lines changed: 62 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.ComponentModel.Composition;
33
using System.Globalization;
4+
using System.IO;
5+
using System.Reflection;
46
using System.Runtime.InteropServices;
57
using GitHub.Extensions;
68
using GitHub.Models;
@@ -12,54 +14,94 @@
1214
using Microsoft.VisualStudio.Shell;
1315
using Microsoft.VisualStudio.Shell.Interop;
1416
using Octokit;
17+
using System.Linq;
1518

1619
namespace GitHub.VisualStudio
1720
{
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.
3021
[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.
3322
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
3423
[Guid(GuidList.guidGitHubPkgString)]
3524
//[ProvideBindingPath]
3625
[ProvideMenuResource("Menus.ctmenu", 1)]
3726
//[ProvideAutoLoad(UIContextGuids.NoSolution)]
27+
// this is the Git service GUID, so we load whenever it loads
3828
[ProvideAutoLoad("11B8E6D7-C08B-4385-B321-321078CDD1F8")]
3929
[ProvideToolWindow(typeof(GitHubPane), Orientation = ToolWindowOrientation.Right, Style = VsDockStyle.Tabbed, Window = EnvDTE.Constants.vsWindowKindSolutionExplorer)]
4030
[ProvideOptionPage(typeof(OptionsPage), "GitHub for Visual Studio", "General", 0, 0, supportsAutomation: true)]
41-
public class GitHubPackage : PackageBase
31+
public class GitHubPackage : Package
4232
{
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+
4355
public GitHubPackage()
4456
{
57+
serviceProvider = this;
4558
}
4659

4760
public GitHubPackage(IServiceProvider serviceProvider)
48-
: base(serviceProvider)
4961
{
62+
this.serviceProvider = serviceProvider;
5063
}
5164

52-
5365
protected override void Initialize()
5466
{
67+
AppDomain.CurrentDomain.AssemblyResolve += LoadAssemblyFromRunDir;
68+
5569
base.Initialize();
5670

57-
var menus = ServiceProvider.GetExportedValue<IMenuProvider>();
71+
var menus = serviceProvider.GetExportedValue<IMenuProvider>();
5872
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());
6074

6175
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;
63105
}
64106
}
65107

@@ -70,7 +112,6 @@ public class GHClient : GitHubClient
70112
public GHClient(IProgram program)
71113
: base(program.ProductHeader)
72114
{
73-
74115
}
75116
}
76117
}

src/GitHub.VisualStudio/UI/Settings/OptionsControl.xaml

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,61 @@
55
xmlns:local="clr-namespace:GitHub.VisualStudio.UI"
66
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
77
xmlns:prop="clr-namespace:GitHub.VisualStudio.UI;assembly=GitHub.VisualStudio.UI"
8-
xmlns:cache="clr-namespace:GitHub.VisualStudio.Helpers"
98
d:DesignHeight="200"
109
mc:Ignorable="d">
1110
<UserControl.Resources>
12-
<ResourceDictionary>
13-
<ResourceDictionary.MergedDictionaries>
14-
<cache:SharedDictionaryManager Source="pack://application:,,,/GitHub.VisualStudio;component/UI/Settings/OptionsStyles.xaml" />
15-
</ResourceDictionary.MergedDictionaries>
16-
</ResourceDictionary>
11+
<BorderGapMaskConverter x:Key="BorderGapMaskConverter" />
12+
<Style x:Key="GroupBoxFlat" TargetType="{x:Type GroupBox}">
13+
<Setter Property="BorderBrush" Value="#D5DFE5" />
14+
<Setter Property="BorderThickness" Value="1" />
15+
<Setter Property="Template">
16+
<Setter.Value>
17+
<ControlTemplate TargetType="{x:Type GroupBox}">
18+
<Grid SnapsToDevicePixels="true">
19+
<Grid.ColumnDefinitions>
20+
<ColumnDefinition Width="6" />
21+
<ColumnDefinition Width="Auto" />
22+
<ColumnDefinition Width="*" />
23+
<ColumnDefinition Width="6" />
24+
</Grid.ColumnDefinitions>
25+
<Grid.RowDefinitions>
26+
<RowDefinition Height="Auto" />
27+
<RowDefinition Height="Auto" />
28+
<RowDefinition Height="*" />
29+
<RowDefinition Height="6" />
30+
</Grid.RowDefinitions>
31+
<Border x:Name="Header"
32+
Grid.Row="0"
33+
Grid.RowSpan="2"
34+
Grid.Column="1"
35+
Padding="3,1,3,0">
36+
<ContentPresenter ContentSource="Header" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
37+
</Border>
38+
<Border Grid.Row="1"
39+
Grid.RowSpan="3"
40+
Grid.ColumnSpan="4"
41+
BorderBrush="Transparent"
42+
BorderThickness="{TemplateBinding BorderThickness}"
43+
CornerRadius="4">
44+
<Border.OpacityMask>
45+
<MultiBinding Converter="{StaticResource BorderGapMaskConverter}" ConverterParameter="7">
46+
<Binding ElementName="Header" Path="ActualWidth" />
47+
<Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}" />
48+
<Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}" />
49+
</MultiBinding>
50+
</Border.OpacityMask>
51+
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3" />
52+
</Border>
53+
<ContentPresenter Grid.Row="2"
54+
Grid.Column="1"
55+
Grid.ColumnSpan="2"
56+
Margin="{TemplateBinding Padding}"
57+
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
58+
</Grid>
59+
</ControlTemplate>
60+
</Setter.Value>
61+
</Setter>
62+
</Style>
1763
</UserControl.Resources>
1864
<GroupBox Height="85"
1965
Margin="8,0,8,0"

src/GitHub.VisualStudio/UI/Settings/OptionsStyles.xaml

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/common/SharedDictionaryManager.cs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,65 +11,11 @@ namespace GitHub.VisualStudio.Helpers
1111
{
1212
public class SharedDictionaryManager : ResourceDictionary
1313
{
14-
static readonly string[] ourAssemblies =
15-
{
16-
"GitHub.Api",
17-
"GitHub.App",
18-
"GitHub.CredentialManagement",
19-
"GitHub.Exports",
20-
"GitHub.Exports.Reactive",
21-
"GitHub.Extensions",
22-
"GitHub.Extensions.Reactive",
23-
"GitHub.UI",
24-
"GitHub.UI.Reactive",
25-
"GitHub.VisualStudio",
26-
"GitHub.TeamFoundation",
27-
"GitHub.TeamFoundation.14",
28-
"GitHub.TeamFoundation.15",
29-
"GitHub.VisualStudio.UI"
30-
};
31-
32-
readonly static int VSVersion;
33-
static SharedDictionaryManager()
34-
{
35-
AppDomain.CurrentDomain.AssemblyResolve += LoadAssemblyFromRunDir;
36-
var asm = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.FullName.StartsWith("Microsoft.TeamFoundation", StringComparison.Ordinal));
37-
VSVersion = asm?.GetName().Version.Major ?? 14;
38-
}
39-
4014
public SharedDictionaryManager()
4115
{
4216
currentTheme = Colors.DetectTheme();
4317
}
4418

45-
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods")]
46-
static Assembly LoadAssemblyFromRunDir(object sender, ResolveEventArgs e)
47-
{
48-
try
49-
{
50-
var name = new AssemblyName(e.Name);
51-
if (!ourAssemblies.Contains(name.Name))
52-
return null;
53-
// This assembly should only be loaded in the matching VS version
54-
if (name.Name.StartsWith("GitHub.TeamFoundation", StringComparison.Ordinal))
55-
{
56-
if (!String.Equals("GitHub.TeamFoundation." + VSVersion, name.Name, StringComparison.Ordinal))
57-
return null;
58-
}
59-
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
60-
var filename = Path.Combine(path, name.Name + ".dll");
61-
if (!File.Exists(filename))
62-
return null;
63-
return Assembly.LoadFrom(filename);
64-
}
65-
catch (Exception ex)
66-
{
67-
var log = string.Format(CultureInfo.CurrentCulture, "Error occurred loading {0} from {1}.{2}{3}{4}", e.Name, Assembly.GetExecutingAssembly().Location, Environment.NewLine, ex, Environment.NewLine);
68-
VsOutputLogger.Write(log);
69-
}
70-
return null;
71-
}
72-
7319
#region ResourceDictionaryImplementation
7420
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
7521
string currentTheme;

0 commit comments

Comments
 (0)