提交 252db15d 编写于 作者: T Tom Meschter

Add a method to check for strong-named assemblies

Add a utility method to check for strong-named assemblies.

`AssemblyUtilities.HasStrongName` uses the metadata reader to check if
the assembly at a given path has a strong name or not.

This commit includes the code itself and a couple of unit tests. A later
commit will wire it into the compilers/VS.
上级 6f60f43d
......@@ -213,5 +213,23 @@ public void IdentifyMissingDependencies_MultipleMissing()
Assert.Contains("mscorlib", results);
Assert.Contains("Gamma", results);
}
[Fact]
public void HasStrongName_False()
{
var directory = Temp.CreateDirectory();
var alphaDll = directory.CreateFile("Alpha.dll").WriteAllBytes(TestResources.AssemblyLoadTests.AssemblyLoadTests.Alpha);
Assert.False(AssemblyUtilities.HasStrongName(alphaDll.Path));
}
[Fact]
public void HasStrongName_True()
{
string path = Assembly.GetExecutingAssembly().Location;
Assert.True(AssemblyUtilities.HasStrongName(path));
}
}
}
......@@ -130,6 +130,10 @@ public static ImmutableArray<string> FindSatelliteAssemblies(string filePath)
return builder.ToImmutable();
}
/// <summary>
/// Given a path to an assembly and a set of paths to possible dependencies,
/// identifies which of the assembly's references are missing.
/// </summary>
public static ImmutableArray<AssemblyIdentity> IdentifyMissingDependencies(string assemblyPath, IEnumerable<string> assemblySet)
{
if (assemblyPath == null)
......@@ -168,5 +172,25 @@ public static ImmutableArray<AssemblyIdentity> IdentifyMissingDependencies(strin
return ImmutableArray.CreateRange(assemblyReferences);
}
/// <summary>
/// Given a path to an assembly, returns true if the assembly has a strong
/// name (either a full key or a token) or false otherwise.
/// </summary>
public static bool HasStrongName(string assemblyPath)
{
if (assemblyPath == null)
{
throw new ArgumentNullException(nameof(assemblyPath));
}
using (var reader = new PEReader(FileUtilities.OpenRead(assemblyPath)))
{
var metadataReader = reader.GetMetadataReader();
var assemblyDefinition = metadataReader.ReadAssemblyIdentityOrThrow();
return assemblyDefinition.IsStrongName;
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册