Skip to content

Commit

Permalink
Check PublicKeyToken before resolving an assembly
Browse files Browse the repository at this point in the history
* If there is a request for one of our assemblies with another key do
not handle the AssemblyResolve event to let other resolvers have a
chance.
  • Loading branch information
AndyGerlicher committed Apr 5, 2018
1 parent 6b85603 commit 6b23661
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/MSBuildLocator/MSBuildLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;

namespace Microsoft.Build.Locator
{
public static class MSBuildLocator
{
private const string MSBuildPublicKeyToken = "b03f5f7f11d50a3a";

private static readonly string[] s_msBuildAssemblies =
{
"Microsoft.Build", "Microsoft.Build.Framework", "Microsoft.Build.Tasks.Core",
Expand Down Expand Up @@ -101,7 +104,24 @@ private static bool IsMSBuildAssembly(Assembly assembly)

private static bool IsMSBuildAssembly(AssemblyName assemblyName)
{
return s_msBuildAssemblies.Contains(assemblyName.Name, StringComparer.OrdinalIgnoreCase);
if (!s_msBuildAssemblies.Contains(assemblyName.Name, StringComparer.OrdinalIgnoreCase))
{
return false;
}

var publicKeyToken = assemblyName.GetPublicKeyToken();
if (publicKeyToken == null || publicKeyToken.Length == 0)
{
return false;
}

var sb = new StringBuilder();
foreach (var b in publicKeyToken)
{
sb.Append($"{b:x2}");
}

return sb.ToString().Equals(MSBuildPublicKeyToken, StringComparison.OrdinalIgnoreCase);
}

private static IEnumerable<VisualStudioInstance> GetInstances()
Expand Down

0 comments on commit 6b23661

Please sign in to comment.