Make AngleSharp not strong-named. Change assembly name to Microsoft.AspNetCore.Blazor.AngleSharp to ensure no conflicts with other usages.
This commit is contained in:
parent
15ddcd03b0
commit
5a9c41af0e
|
|
@ -34,7 +34,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\anglesharp\AngleSharpBuilder\AngleSharpBuilder.csproj" ReferenceOutputAssembly="false" />
|
<ProjectReference Include="..\anglesharp\AngleSharpBuilder\AngleSharpBuilder.csproj" ReferenceOutputAssembly="false" />
|
||||||
<Reference Include="AngleSharp" HintPath="..\anglesharp\AngleSharpBuilder\dist\AngleSharp.dll" />
|
<Reference Include="Microsoft.AspNetCore.Blazor.AngleSharp" HintPath="..\anglesharp\AngleSharpBuilder\dist\Microsoft.AspNetCore.Blazor.AngleSharp.dll" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,10 @@ namespace AngleSharpBuilder
|
||||||
* specifies [InternalsVisibleTo("Microsoft.AspNetCore.Blazor.Build")]. Longer term we can ask
|
* specifies [InternalsVisibleTo("Microsoft.AspNetCore.Blazor.Build")]. Longer term we can ask
|
||||||
* AngleSharp to expose HtmlTokenizer as a public API, and if that's not viable, possibly
|
* AngleSharp to expose HtmlTokenizer as a public API, and if that's not viable, possibly
|
||||||
* replace AngleSharp with a different library for HTML tokenization.
|
* replace AngleSharp with a different library for HTML tokenization.
|
||||||
|
*
|
||||||
|
* Similarly, we have build-process reasons for needing the assembly not to be strong
|
||||||
|
* named and be called Microsoft.AspNetCore.Blazor.AngleSharp. These requirements will
|
||||||
|
* not be permanent but it enables progress in the short term.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static class Program
|
public static class Program
|
||||||
|
|
@ -25,20 +29,41 @@ namespace AngleSharpBuilder
|
||||||
public static void Main()
|
public static void Main()
|
||||||
{
|
{
|
||||||
var outputDir = Path.Combine(Directory.GetCurrentDirectory(), "dist");
|
var outputDir = Path.Combine(Directory.GetCurrentDirectory(), "dist");
|
||||||
var angleSharpAssembly = Assembly.GetAssembly(typeof(HtmlParser));
|
var inputAssembly = Assembly.GetAssembly(typeof(HtmlParser));
|
||||||
WriteWithInternalsVisibleTo(
|
WriteModifiedAssembly(inputAssembly, outputDir);
|
||||||
angleSharpAssembly,
|
|
||||||
"Microsoft.AspNetCore.Blazor.Build",
|
|
||||||
outputDir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void WriteWithInternalsVisibleTo(Assembly assembly, string internalVisibleToArg, string outputDir)
|
private static void WriteModifiedAssembly(Assembly assembly, string outputDir)
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(outputDir);
|
Directory.CreateDirectory(outputDir);
|
||||||
|
|
||||||
var assemblyLocation = assembly.Location;
|
var assemblyLocation = assembly.Location;
|
||||||
var moduleDefinition = ModuleDefinition.ReadModule(assemblyLocation);
|
var moduleDefinition = ModuleDefinition.ReadModule(assemblyLocation);
|
||||||
|
|
||||||
|
AddInternalsVisibleTo(moduleDefinition, "Microsoft.AspNetCore.Blazor.Build");
|
||||||
|
RemoveStrongName(moduleDefinition);
|
||||||
|
SetAssemblyName(moduleDefinition, "Microsoft.AspNetCore.Blazor.AngleSharp");
|
||||||
|
|
||||||
|
moduleDefinition.Write(
|
||||||
|
Path.Combine(outputDir, $"{moduleDefinition.Name}.dll"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SetAssemblyName(ModuleDefinition moduleDefinition, string name)
|
||||||
|
{
|
||||||
|
moduleDefinition.Name = name;
|
||||||
|
moduleDefinition.Assembly.Name.Name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RemoveStrongName(ModuleDefinition moduleDefinition)
|
||||||
|
{
|
||||||
|
var assemblyName = moduleDefinition.Assembly.Name;
|
||||||
|
assemblyName.HasPublicKey = false;
|
||||||
|
assemblyName.PublicKey = new byte[0];
|
||||||
|
moduleDefinition.Attributes &= ~ModuleAttributes.StrongNameSigned;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddInternalsVisibleTo(ModuleDefinition moduleDefinition, string internalVisibleToArg)
|
||||||
|
{
|
||||||
var internalsVisibleToCtor = moduleDefinition.ImportReference(
|
var internalsVisibleToCtor = moduleDefinition.ImportReference(
|
||||||
typeof(InternalsVisibleToAttribute).GetConstructor(new[] { typeof(string) }));
|
typeof(InternalsVisibleToAttribute).GetConstructor(new[] { typeof(string) }));
|
||||||
|
|
||||||
|
|
@ -47,8 +72,6 @@ namespace AngleSharpBuilder
|
||||||
new CustomAttributeArgument(moduleDefinition.TypeSystem.String, internalVisibleToArg));
|
new CustomAttributeArgument(moduleDefinition.TypeSystem.String, internalVisibleToArg));
|
||||||
|
|
||||||
moduleDefinition.Assembly.CustomAttributes.Add(customAttribute);
|
moduleDefinition.Assembly.CustomAttributes.Add(customAttribute);
|
||||||
|
|
||||||
moduleDefinition.Write(Path.Combine(outputDir, Path.GetFileName(assemblyLocation)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\anglesharp\AngleSharpBuilder\AngleSharpBuilder.csproj" ReferenceOutputAssembly="false" />
|
<ProjectReference Include="..\..\src\anglesharp\AngleSharpBuilder\AngleSharpBuilder.csproj" ReferenceOutputAssembly="false" />
|
||||||
<Reference Include="AngleSharp" HintPath="..\..\src\anglesharp\AngleSharpBuilder\dist\AngleSharp.dll" />
|
<Reference Include="Microsoft.AspNetCore.Blazor.AngleSharp" HintPath="..\..\src\anglesharp\AngleSharpBuilder\dist\Microsoft.AspNetCore.Blazor.AngleSharp.dll" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue