diff --git a/BepInEx.AssemblyPublicizer.MSBuild/BepInEx.AssemblyPublicizer.MSBuild.props b/BepInEx.AssemblyPublicizer.MSBuild/BepInEx.AssemblyPublicizer.MSBuild.props index 68b2068..641eeb4 100644 --- a/BepInEx.AssemblyPublicizer.MSBuild/BepInEx.AssemblyPublicizer.MSBuild.props +++ b/BepInEx.AssemblyPublicizer.MSBuild/BepInEx.AssemblyPublicizer.MSBuild.props @@ -9,8 +9,12 @@ + + + $(IntermediateOutputPath)$(MSBuildProjectName).IgnoresAccessChecksTo.cs + - + @@ -19,9 +23,8 @@ - - <_Parameter1>%(_PublicizedReferences.Filename) - + + diff --git a/BepInEx.AssemblyPublicizer.MSBuild/PublicizeTask.cs b/BepInEx.AssemblyPublicizer.MSBuild/PublicizeTask.cs index 1c2abe3..06adb73 100644 --- a/BepInEx.AssemblyPublicizer.MSBuild/PublicizeTask.cs +++ b/BepInEx.AssemblyPublicizer.MSBuild/PublicizeTask.cs @@ -15,6 +15,9 @@ public class PublicizeTask : Task [Required] public string IntermediateOutputPath { get; set; } + [Required] + public string GeneratedIgnoresAccessChecksToFile { get; set; } + [Required] public ITaskItem[] ReferencePath { get; set; } @@ -123,12 +126,31 @@ public override bool Execute() Log.LogMessage($"Publicized {fileName}"); } + GenerateIgnoresAccessChecksToFile(publicizedReferences); + RemovedReferences = removedReferences.ToArray(); PublicizedReferences = publicizedReferences.ToArray(); return true; } + private void GenerateIgnoresAccessChecksToFile(List publicizedReferences) + { + var stringBuilder = new StringBuilder(); + + stringBuilder.AppendLine("// "); + stringBuilder.AppendLine("#pragma warning disable CS0436 // Type conflicts with imported type"); + stringBuilder.AppendLine(); + + foreach (var publicizedReference in publicizedReferences) + { + var assemblyName = Path.GetFileNameWithoutExtension(publicizedReference.ItemSpec); + stringBuilder.AppendLine($"[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute(\"{assemblyName}\")]"); + } + + File.WriteAllText(GeneratedIgnoresAccessChecksToFile, stringBuilder.ToString()); + } + private static string ComputeHash(byte[] bytes, AssemblyPublicizerOptions options) { static void Hash(ICryptoTransform hash, byte[] buffer)