From 16410fd81618b2b29bc0ae3efe63d787d327711e Mon Sep 17 00:00:00 2001
From: Truinto <47917181+Truinto@users.noreply.github.com>
Date: Sun, 5 Mar 2023 16:21:55 +0100
Subject: [PATCH 1/3] exclude compiler generated fields remove sealed
---
AssemblyPublicizer/AsmModuleExtension.cs | 8 ++++++--
AssemblyPublicizer/AssemblyPublicizer.csproj | 20 +++++++++++++-------
AssemblyPublicizer/AssemblyPublicizer.props | 2 +-
AssemblyPublicizer/PublicizeTask.cs | 6 ++++--
README.md | 3 ++-
5 files changed, 26 insertions(+), 13 deletions(-)
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..b861320 100644
--- a/AssemblyPublicizer/AssemblyPublicizer.csproj
+++ b/AssemblyPublicizer/AssemblyPublicizer.csproj
@@ -2,7 +2,7 @@
net472
- 9
+ latest
enable
true
true
@@ -16,9 +16,13 @@
MIT
2021 Vikash Balasubramanian
git
- 1.0.2
- 1.0.2
- 1.0.2
+ 1.0.3
+ 1.0.3
+ 1.0.3
+ README.md
+ true
+ tasks
+ none
@@ -28,8 +32,10 @@
-
-
-
+
+
+
+
+
diff --git a/AssemblyPublicizer/AssemblyPublicizer.props b/AssemblyPublicizer/AssemblyPublicizer.props
index 17978e8..b869f6a 100644
--- a/AssemblyPublicizer/AssemblyPublicizer.props
+++ b/AssemblyPublicizer/AssemblyPublicizer.props
@@ -1,6 +1,6 @@
- $(MSBuildThisFileDirectory)..\lib\net472\$(MSBuildThisFileName).dll
+ $(MSBuildThisFileDirectory)..\tasks\net472\$(MSBuildThisFileName).dll
\ No newline at end of file
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
From cb0e600db8cf981a1e7f20829dd2afd769f85fb5 Mon Sep 17 00:00:00 2001
From: Truinto <47917181+Truinto@users.noreply.github.com>
Date: Sun, 5 Mar 2023 16:51:19 +0100
Subject: [PATCH 2/3] clean format
---
AssemblyPublicizer/AssemblyPublicizer.csproj | 52 ++++++++++----------
AssemblyPublicizer/AssemblyPublicizer.props | 10 ++--
2 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/AssemblyPublicizer/AssemblyPublicizer.csproj b/AssemblyPublicizer/AssemblyPublicizer.csproj
index b861320..f90e2cd 100644
--- a/AssemblyPublicizer/AssemblyPublicizer.csproj
+++ b/AssemblyPublicizer/AssemblyPublicizer.csproj
@@ -1,36 +1,36 @@
-
- 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.3
- 1.0.3
- 1.0.3
+
+ 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.3
+ 1.0.3
+ 1.0.3
README.md
true
tasks
none
-
+
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/AssemblyPublicizer/AssemblyPublicizer.props b/AssemblyPublicizer/AssemblyPublicizer.props
index b869f6a..293ae37 100644
--- a/AssemblyPublicizer/AssemblyPublicizer.props
+++ b/AssemblyPublicizer/AssemblyPublicizer.props
@@ -1,6 +1,6 @@
-
- $(MSBuildThisFileDirectory)..\tasks\net472\$(MSBuildThisFileName).dll
-
-
-
\ No newline at end of file
+
+ $(MSBuildThisFileDirectory)..\tasks\net472\$(MSBuildThisFileName).dll
+
+
+
From 69b530f0eb0c48af8f42560a5aee57c153dd2a9f Mon Sep 17 00:00:00 2001
From: Truinto <47917181+Truinto@users.noreply.github.com>
Date: Sat, 16 Dec 2023 15:40:31 +0100
Subject: [PATCH 3/3] updated dependencies so it works for newer assemblies
---
AssemblyPublicizer/AssemblyPublicizer.csproj | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/AssemblyPublicizer/AssemblyPublicizer.csproj b/AssemblyPublicizer/AssemblyPublicizer.csproj
index f90e2cd..760c38a 100644
--- a/AssemblyPublicizer/AssemblyPublicizer.csproj
+++ b/AssemblyPublicizer/AssemblyPublicizer.csproj
@@ -16,9 +16,9 @@
MIT
2021 Vikash Balasubramanian
git
- 1.0.3
- 1.0.3
- 1.0.3
+ 1.0.4
+ 1.0.4
+ 1.0.4
README.md
true
tasks
@@ -26,10 +26,10 @@
-
-
-
-
+
+
+
+