8000 [SPIKE] Stop TeamFoundation MEF exceptions when installing by jcansdale · Pull Request #970 · github/VisualStudio · GitHub
[go: up one dir, main page]

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

[SPIKE] Stop TeamFoundation MEF exceptions when installing #970

Closed
wants to merge 23 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c4f272c
Attempt at unifying the GitHub.TeamFoundation projects
jcansdale Apr 19, 2017
b54b2b3
Refine ResolvingTeamExplorerNavigationItem attribute
jcansdale Apr 19, 2017
fbe282c
Make GitHub.TeamFoundation.14 work in VS 2015 and 2017
jcansdale Apr 19, 2017
25a516e
Fix all TeamFoundation MEF errors when installing
jcansdale Apr 25, 2017
b4a3532
Use single resolution context for all TeamFoundation factories
jcansdale Apr 25, 2017
045a58a
Restore improved clone support in TeamFoundation 15+
jcansdale Apr 25, 2017
973f664
Fixed RegistryHelper to work in VS 2015 and 2017
jcansdale Apr 25, 2017
e739f15
Fix duplicate PullRequestsNavigationItem
jcansdale Apr 25, 2017
fc37978
Use public consts in TeamExplorer attributes
jcansdale Apr 25, 2017
e57b441
Leave Export attributes on TeamFoundation.14/15 MEF types
jcansdale Apr 25, 2017
3f91b83
Load TeamFoundation assemblies using Assembly.LoadFrom
jcansdale Apr 26, 2017
18dd2f3
Ensure that Microsoft.TeamFoundation assemblies are loaded consistently
jcansdale Apr 26, 2017
69afd80
Fix CodeAnalysis errors and use VsOutputLogger
jcansdale Apr 26, 2017
25a17b3
Removed Export attributes from factory classes
jcansdale May 2, 2017
f8d0bec
Fixed for updated GitHubHomeSection constructor
jcansdale May 2, 2017
5ab04db
Update Microsoft.TeamFoundation versions to 15.0.0.0
jcansdale May 3, 2017
93323af
Remove redundant `GitHub.TeamFoundation.14` project
jcansdale May 3, 2017
1646ccf
Move `GitHub.TeamFoundation.14` files into `GitHub.TeamFoundation`
jcansdale May 3, 2017
50d079d
Export ITeamFoundationResolver not its implementation
jcansdale May 3, 2017
25bf061
Remove obsolete TEAMEXPLORER14 #ifdefs
jcansdale May 3, 2017
325adae
Follow Dispose pattern and make TeamFoundationResolver public/extensible
jcansdale May 3, 2017
6623701
Factor out PriorityAssemblyResolver
jcansdale May 3, 2017
e6895d8
Reference Microsoft.VisualStudio.Threading 14.0
jcansdale May 4, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Follow Dispose pattern and make TeamFoundationResolver public/extensible
  • Loading branch information
jcansdale committed May 3, 2017
commit 325adae4cc2057a287bd73d4c6f21a41e6dd566c
61 changes: 43 additions & 18 deletions src/GitHub.VisualStudio/TeamFoundation/TeamFoundationResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,53 @@
namespace GitHub.VisualStudio.TeamFoundation
{
[Export(typeof(ITeamFoundationResolver))]
public sealed class TeamFoundationResolver : ITeamFoundationResolver, IDisposable
public class TeamFoundationResolver : ITeamFoundationResolver, IDisposable
{
const string BindingPath = @"CommonExtensions\Microsoft\TeamFoundation\Team Explorer";
const string AssemblyStartsWith = "Microsoft.TeamFoundation.";
const string AssemblyEndsWith = ", PublicKeyToken=b03f5f7f11d50a3a";
bool disposed;

internal static Type Resolve(Func<Type> func)
readonly string bindingPath;
readonly string assemblyStartsWith;
readonly string assemblyEndsWith;

public TeamFoundationResolver() : this(@"CommonExtensions\Microsoft\TeamFoundation\Team Explorer",
"Microsoft.TeamFoundation.", ", PublicKeyToken=b03f5f7f11d50a3a")
{
using (new TeamFoundationResolver())
TryAddPriorityAssemblyResolve(AppDomain.CurrentDomain, CurrentDomain_AssemblyResolve);
}

public TeamFoundationResolver(string bindingPath, string assemblyStartsWith, string assemblyEndsWith)
{
this.bindingPath = bindingPath;
this.assemblyStartsWith = assemblyStartsWith;
this.assemblyEndsWith = assemblyEndsWith;
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

public virtual void Dispose(bool disposing)
{
if (disposed)
{
return func();
return;
}

if (disposing)
{
AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
disposed = true;
}
}

internal TeamFoundationResolver()
public static Type Resolve(Func<Type> func)
{
TryAddPriorityAssemblyResolve(AppDomain.CurrentDomain, CurrentDomain_AssemblyResolve);
using (new TeamFoundationResolver())
{
return func();
}
}

// NOTE: This is a workaround for https://github.com/github/VisualStudio/issues/923#issuecomment-287537118
Expand Down Expand Up @@ -54,11 +84,6 @@ static void TryAddPriorityAssemblyResolve(AppDomain domain, ResolveEventHandler
}
}

public void Dispose()
{
AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
}

[SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods",
Justification = "Assembly.LoadFrom is normal for AssemblyResolve event")]
[SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", Justification = "I like $ strings")]
Expand All @@ -67,8 +92,8 @@ Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
try
{
var name = args.Name;
if (name.StartsWith(AssemblyStartsWith, StringComparison.Ordinal) &&
name.EndsWith(AssemblyEndsWith, StringComparison.Ordinal))
if (name.StartsWith(assemblyStartsWith, StringComparison.Ordinal) &&
name.EndsWith(assemblyEndsWith, StringComparison.Ordinal))
{
var assemblyName = new AssemblyName(name);
var path = GetTeamExplorerPath(assemblyName.Name);
Expand All @@ -88,9 +113,9 @@ Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
return null;
}

static string GetTeamExplorerPath(string name)
string GetTeamExplorerPath(string name)
{
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, BindingPath, name + ".dll");
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, bindingPath, name + ".dll");
}
}
}
0