diff --git a/AssemblyPublicizer/AsmModuleExtension.cs b/AssemblyPublicizer/AsmModuleExtension.cs index 8be6d15..7ab1b5e 100644 --- a/AssemblyPublicizer/AsmModuleExtension.cs +++ b/AssemblyPublicizer/AsmModuleExtension.cs @@ -6,10 +6,11 @@ namespace AssemblyPublicizer { public static class AsmModuleExtension { - public static void Publicize(this ModuleDefinition moduleDefinition, bool publicizeExplicitImpls = false) + public static void Publicize(this ModuleDefinition moduleDefinition, bool publicizeExplicitImpls = false, bool publicizeCompilerGeneratedFields = false) { foreach (var type in moduleDefinition.GetAllTypes()) { + type.IsSealed = false; if (type.IsNested) type.IsNestedPublic = true; else @@ -27,7 +28,10 @@ public static void Publicize(this ModuleDefinition moduleDefinition, bool public foreach (var field in type.Fields) { - field.IsPublic = true; + if (publicizeCompilerGeneratedFields || !field.HasCustomAttribute("System.Runtime.CompilerServices", "CompilerGeneratedAttribute")) + { + field.IsPublic = true; + } } } } diff --git a/AssemblyPublicizer/AssemblyPublicizer.csproj b/AssemblyPublicizer/AssemblyPublicizer.csproj index 1eaed11..760c38a 100644 --- a/AssemblyPublicizer/AssemblyPublicizer.csproj +++ b/AssemblyPublicizer/AssemblyPublicizer.csproj @@ -1,35 +1,41 @@ - - net472 - 9 - enable - true - true - true - true - build - Assembly Publicizer - MSBuild Task to publicize assemblies - vikigenius - https://github.com/vikigenius/AssemblyPublicizer - MIT - 2021 Vikash Balasubramanian - git - 1.0.2 - 1.0.2 - 1.0.2 - + + net472 + latest + enable + true + true + true + true + build + Assembly Publicizer + MSBuild Task to publicize assemblies + vikigenius + https://github.com/vikigenius/AssemblyPublicizer + MIT + 2021 Vikash Balasubramanian + git + 1.0.4 + 1.0.4 + 1.0.4 + README.md + true + tasks + none + - - - - - - + + + + + + - - - + + + + + diff --git a/AssemblyPublicizer/AssemblyPublicizer.props b/AssemblyPublicizer/AssemblyPublicizer.props index 17978e8..293ae37 100644 --- a/AssemblyPublicizer/AssemblyPublicizer.props +++ b/AssemblyPublicizer/AssemblyPublicizer.props @@ -1,6 +1,6 @@  - - $(MSBuildThisFileDirectory)..\lib\net472\$(MSBuildThisFileName).dll - - - \ No newline at end of file + + $(MSBuildThisFileDirectory)..\tasks\net472\$(MSBuildThisFileName).dll + + + diff --git a/AssemblyPublicizer/PublicizeTask.cs b/AssemblyPublicizer/PublicizeTask.cs index e1a6f0f..3bcc50b 100644 --- a/AssemblyPublicizer/PublicizeTask.cs +++ b/AssemblyPublicizer/PublicizeTask.cs @@ -18,6 +18,8 @@ public class PublicizeTask : Microsoft.Build.Utilities.Task public virtual bool PublicizeExplicitImpls { get; set; } = false; + public virtual bool PublicizeCompilerGeneratedFields { get; set; } = false; + public override bool Execute() { Log.LogMessage($"Publicizing {InputAssemblies.Length} input assemblies provided"); @@ -46,7 +48,7 @@ private bool PublicizeItem(string assemblyPath) Log.LogMessage(MessageImportance.High, $"Generating publicized assembly from {assemblyPath}"); var moduleDefinition = ModuleDefinition.FromFile(assemblyPath); - moduleDefinition.Publicize(PublicizeExplicitImpls); + moduleDefinition.Publicize(PublicizeExplicitImpls, PublicizeCompilerGeneratedFields); if (!Directory.Exists(OutputDir)) { @@ -72,7 +74,7 @@ private string ComputeHash(string filePath) file.Close(); } - foreach (byte b in hash.Hash) + foreach (byte b in hash.Hash!) res.Append(b.ToString("X2")); } diff --git a/README.md b/README.md index 5c95d2d..489d198 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,5 @@ It addresses one key issue with other publicizers in that, it avoids publicizing 2. Create the MSBuild Target. Properties are: `InputAssemblies`: Assemblies to be publicized. `OutputDir`: Output directory to store the publicized assemblies. - `PublicizeExplicitImpls`: Whether or not to publicize explicit implementation. (False by default). \ No newline at end of file + `PublicizeExplicitImpls`: Whether or not to publicize explicit implementation. (False by default). + `PublicizeCompilerGeneratedFields`: Whether or not to publicize fields generated by the compiler. (False by default). \ No newline at end of file