From f9559ab6e102814f822fa1194293e5bb6fe199ba Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sun, 5 Jul 2026 18:27:19 +0000
Subject: [PATCH 1/6] Initial plan
From bb74b71c6bad52afe55095e13ee7b84b86a03f4d Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sun, 5 Jul 2026 18:35:27 +0000
Subject: [PATCH 2/6] Add IgnoresAccessChecksToOmitAttributeDefinition MSBuild
property
---
README.md | 25 +++++++++++
.../PublicizeInternals.cs | 45 ++++++++++++-------
.../IgnoresAccessChecksToGenerator.targets | 3 +-
...sAccessChecksToGenerator.Tasks.Test.csproj | 27 +++++++++++
.../PublicizeInternalsTests.cs | 44 ++++++++++++++++++
.../nuget.config | 7 +++
6 files changed, 135 insertions(+), 16 deletions(-)
create mode 100644 test/IgnoresAccessChecksToGenerator.Tasks.Test/IgnoresAccessChecksToGenerator.Tasks.Test.csproj
create mode 100644 test/IgnoresAccessChecksToGenerator.Tasks.Test/PublicizeInternalsTests.cs
create mode 100644 test/IgnoresAccessChecksToGenerator.Tasks.Test/nuget.config
diff --git a/README.md b/README.md
index 3af9d90..4739ec6 100644
--- a/README.md
+++ b/README.md
@@ -25,3 +25,28 @@ Just add the package and define `IgnoresAccessChecksTo` items with the assemblie
```
+
+## MSBuild Properties
+
+### `IgnoresAccessChecksToOmitAttributeDefinition`
+
+When set to `true`, the generator will not emit the `IgnoresAccessChecksToAttribute` class definition in the generated file. This is useful when you already have the attribute defined elsewhere in your project (for example, when multiple packages use the same attribute).
+
+```xml
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+```
+
diff --git a/src/IgnoresAccessChecksToGenerator.Tasks/PublicizeInternals.cs b/src/IgnoresAccessChecksToGenerator.Tasks/PublicizeInternals.cs
index f74e70b..08ef60f 100644
--- a/src/IgnoresAccessChecksToGenerator.Tasks/PublicizeInternals.cs
+++ b/src/IgnoresAccessChecksToGenerator.Tasks/PublicizeInternals.cs
@@ -2,10 +2,13 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Runtime.CompilerServices;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Mono.Cecil;
+[assembly: InternalsVisibleTo("IgnoresAccessChecksToGenerator.Tasks.Test")]
+
namespace IgnoresAccessChecksToGenerator.Tasks
{
public class PublicizeInternals : Task
@@ -26,6 +29,8 @@ public class PublicizeInternals : Task
public ITaskItem[] ExcludeTypeNames { get; set; }
+ public bool OmitAttributeDefinition { get; set; }
+
public override bool Execute()
{
if (SourceReferences == null) throw new ArgumentNullException(nameof(SourceReferences));
@@ -46,7 +51,7 @@ public override bool Execute()
var targetPath = IntermediateOutputPath;
Directory.CreateDirectory(targetPath);
- GenerateAttributes(targetPath, assemblyNames);
+ GenerateAttributes(targetPath, assemblyNames, OmitAttributeDefinition);
foreach (var assemblyPath in SourceReferences
.Select(a => Path.GetDirectoryName(GetFullFilePath(targetPath, a.ItemSpec))))
@@ -70,22 +75,20 @@ public override bool Execute()
return true;
}
- private void GenerateAttributes(string path, IEnumerable assemblyNames)
+ private void GenerateAttributes(string path, IEnumerable assemblyNames, bool omitAttributeDefinition)
+ {
+ var content = BuildAttributeFileContent(assemblyNames, omitAttributeDefinition);
+ File.WriteAllText(GeneratedCodeFilePath, content, System.Text.Encoding.UTF8);
+
+ Log.LogMessageFromText("Generated IgnoresAccessChecksTo attributes", MessageImportance.Low);
+ }
+
+ internal static string BuildAttributeFileContent(IEnumerable assemblyNames, bool omitAttributeDefinition)
{
var attributes = string.Join(Environment.NewLine,
assemblyNames.Select(a => $@"[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(""{a}"")]"));
- var content = $$"""
-//------------------------------------------------------------------------------
-//
-// This code was generated by a tool.
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-//
-//------------------------------------------------------------------------------
-
-{{attributes}}
+ var attributeDefinition = omitAttributeDefinition ? "" : """
namespace System.Runtime.CompilerServices
{
@@ -98,9 +101,21 @@ public IgnoresAccessChecksToAttribute(string assemblyName)
}
}
""";
- File.WriteAllText(GeneratedCodeFilePath, content, System.Text.Encoding.UTF8);
- Log.LogMessageFromText("Generated IgnoresAccessChecksTo attributes", MessageImportance.Low);
+ var content = $$"""
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+{{attributes}}
+{{attributeDefinition}}
+""";
+ return content.TrimEnd() + Environment.NewLine;
}
private void CreatePublicAssembly(string source, string target, HashSet excludedTypeNames)
diff --git a/src/IgnoresAccessChecksToGenerator.Tasks/build/IgnoresAccessChecksToGenerator.targets b/src/IgnoresAccessChecksToGenerator.Tasks/build/IgnoresAccessChecksToGenerator.targets
index c53d664..75c401a 100644
--- a/src/IgnoresAccessChecksToGenerator.Tasks/build/IgnoresAccessChecksToGenerator.targets
+++ b/src/IgnoresAccessChecksToGenerator.Tasks/build/IgnoresAccessChecksToGenerator.targets
@@ -48,7 +48,8 @@
AssemblyNames="@(IgnoresAccessChecksTo)"
ExcludeTypeNames="@(IgnoresAccessChecksToExcludeTypeName)"
IntermediateOutputPath="$(_IACTG_IntermediatePath)"
- GeneratedCodeFilePath="$(_IACTG_CodeFilePath)" />
+ GeneratedCodeFilePath="$(_IACTG_CodeFilePath)"
+ OmitAttributeDefinition="$(IgnoresAccessChecksToOmitAttributeDefinition)" />
diff --git a/test/IgnoresAccessChecksToGenerator.Tasks.Test/IgnoresAccessChecksToGenerator.Tasks.Test.csproj b/test/IgnoresAccessChecksToGenerator.Tasks.Test/IgnoresAccessChecksToGenerator.Tasks.Test.csproj
new file mode 100644
index 0000000..280a009
--- /dev/null
+++ b/test/IgnoresAccessChecksToGenerator.Tasks.Test/IgnoresAccessChecksToGenerator.Tasks.Test.csproj
@@ -0,0 +1,27 @@
+
+
+
+ net9.0
+ enable
+ enable
+
+ false
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/IgnoresAccessChecksToGenerator.Tasks.Test/PublicizeInternalsTests.cs b/test/IgnoresAccessChecksToGenerator.Tasks.Test/PublicizeInternalsTests.cs
new file mode 100644
index 0000000..0b4d916
--- /dev/null
+++ b/test/IgnoresAccessChecksToGenerator.Tasks.Test/PublicizeInternalsTests.cs
@@ -0,0 +1,44 @@
+using IgnoresAccessChecksToGenerator.Tasks;
+
+namespace IgnoresAccessChecksToGenerator.Tasks.Test;
+
+public class PublicizeInternalsTests
+{
+ [Fact]
+ public void BuildAttributeFileContent_DefaultBehavior_EmitsAttributeDefinition()
+ {
+ var content = PublicizeInternals.BuildAttributeFileContent(["TestAssembly"], omitAttributeDefinition: false);
+
+ Assert.Contains("class IgnoresAccessChecksToAttribute", content);
+ Assert.Contains("[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(\"TestAssembly\")]", content);
+ }
+
+ [Fact]
+ public void BuildAttributeFileContent_OmitAttributeDefinition_DoesNotEmitAttributeClass()
+ {
+ var content = PublicizeInternals.BuildAttributeFileContent(["TestAssembly"], omitAttributeDefinition: true);
+
+ Assert.DoesNotContain("class IgnoresAccessChecksToAttribute", content);
+ Assert.Contains("[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(\"TestAssembly\")]", content);
+ }
+
+ [Fact]
+ public void BuildAttributeFileContent_MultipleAssemblies_EmitsAllAssemblyAttributes()
+ {
+ var content = PublicizeInternals.BuildAttributeFileContent(["Assembly1", "Assembly2"], omitAttributeDefinition: false);
+
+ Assert.Contains("[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(\"Assembly1\")]", content);
+ Assert.Contains("[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(\"Assembly2\")]", content);
+ Assert.Contains("class IgnoresAccessChecksToAttribute", content);
+ }
+
+ [Fact]
+ public void BuildAttributeFileContent_MultipleAssembliesOmitDefinition_EmitsAllAssemblyAttributesWithoutClass()
+ {
+ var content = PublicizeInternals.BuildAttributeFileContent(["Assembly1", "Assembly2"], omitAttributeDefinition: true);
+
+ Assert.Contains("[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(\"Assembly1\")]", content);
+ Assert.Contains("[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(\"Assembly2\")]", content);
+ Assert.DoesNotContain("class IgnoresAccessChecksToAttribute", content);
+ }
+}
diff --git a/test/IgnoresAccessChecksToGenerator.Tasks.Test/nuget.config b/test/IgnoresAccessChecksToGenerator.Tasks.Test/nuget.config
new file mode 100644
index 0000000..de291b7
--- /dev/null
+++ b/test/IgnoresAccessChecksToGenerator.Tasks.Test/nuget.config
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
From 91bfe7f89c06ca87bf7409c27321c1b0451c88e1 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sun, 5 Jul 2026 18:47:13 +0000
Subject: [PATCH 3/6] Move nuget.config to root, use MSTest.Sdk, upgrade to
.NET SDK 10.0.301
---
.github/workflows/dotnet.yml | 6 ++--
global.json | 12 ++++++++
.../nuget.config => nuget.config | 0
...sAccessChecksToGenerator.Tasks.Test.csproj | 14 +--------
.../PublicizeInternalsTests.cs | 29 ++++++++++---------
.../nuget.config | 2 +-
6 files changed, 32 insertions(+), 31 deletions(-)
create mode 100644 global.json
rename test/IgnoresAccessChecksToGenerator.Tasks.Test/nuget.config => nuget.config (100%)
rename test/{ => IgnoresAccessChecksToGenerator.Test}/nuget.config (53%)
diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml
index dbc6384..9d3838c 100644
--- a/.github/workflows/dotnet.yml
+++ b/.github/workflows/dotnet.yml
@@ -12,11 +12,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v4
- name: Setup .NET
- uses: actions/setup-dotnet@v1
+ uses: actions/setup-dotnet@v4
with:
- dotnet-version: 8.0.x
+ dotnet-version: 10.0.301
- name: Restore dependencies
run: dotnet restore src
- name: Build
diff --git a/global.json b/global.json
new file mode 100644
index 0000000..6afb88e
--- /dev/null
+++ b/global.json
@@ -0,0 +1,12 @@
+{
+ "sdk": {
+ "version": "10.0.301",
+ "rollForward": "latestFeature"
+ },
+ "msbuild-sdks": {
+ "MSTest.Sdk": "4.2.3"
+ },
+ "test": {
+ "runner": "Microsoft.Testing.Platform"
+ }
+}
diff --git a/test/IgnoresAccessChecksToGenerator.Tasks.Test/nuget.config b/nuget.config
similarity index 100%
rename from test/IgnoresAccessChecksToGenerator.Tasks.Test/nuget.config
rename to nuget.config
diff --git a/test/IgnoresAccessChecksToGenerator.Tasks.Test/IgnoresAccessChecksToGenerator.Tasks.Test.csproj b/test/IgnoresAccessChecksToGenerator.Tasks.Test/IgnoresAccessChecksToGenerator.Tasks.Test.csproj
index 280a009..9818107 100644
--- a/test/IgnoresAccessChecksToGenerator.Tasks.Test/IgnoresAccessChecksToGenerator.Tasks.Test.csproj
+++ b/test/IgnoresAccessChecksToGenerator.Tasks.Test/IgnoresAccessChecksToGenerator.Tasks.Test.csproj
@@ -1,4 +1,4 @@
-
+
net9.0
@@ -6,22 +6,10 @@
enable
false
- true
-
-
-
-
-
-
-
-
-
-
-
diff --git a/test/IgnoresAccessChecksToGenerator.Tasks.Test/PublicizeInternalsTests.cs b/test/IgnoresAccessChecksToGenerator.Tasks.Test/PublicizeInternalsTests.cs
index 0b4d916..23e7e0e 100644
--- a/test/IgnoresAccessChecksToGenerator.Tasks.Test/PublicizeInternalsTests.cs
+++ b/test/IgnoresAccessChecksToGenerator.Tasks.Test/PublicizeInternalsTests.cs
@@ -2,43 +2,44 @@
namespace IgnoresAccessChecksToGenerator.Tasks.Test;
+[TestClass]
public class PublicizeInternalsTests
{
- [Fact]
+ [TestMethod]
public void BuildAttributeFileContent_DefaultBehavior_EmitsAttributeDefinition()
{
var content = PublicizeInternals.BuildAttributeFileContent(["TestAssembly"], omitAttributeDefinition: false);
- Assert.Contains("class IgnoresAccessChecksToAttribute", content);
- Assert.Contains("[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(\"TestAssembly\")]", content);
+ StringAssert.Contains(content, "class IgnoresAccessChecksToAttribute");
+ StringAssert.Contains(content, "[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(\"TestAssembly\")]");
}
- [Fact]
+ [TestMethod]
public void BuildAttributeFileContent_OmitAttributeDefinition_DoesNotEmitAttributeClass()
{
var content = PublicizeInternals.BuildAttributeFileContent(["TestAssembly"], omitAttributeDefinition: true);
- Assert.DoesNotContain("class IgnoresAccessChecksToAttribute", content);
- Assert.Contains("[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(\"TestAssembly\")]", content);
+ Assert.IsFalse(content.Contains("class IgnoresAccessChecksToAttribute"));
+ StringAssert.Contains(content, "[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(\"TestAssembly\")]");
}
- [Fact]
+ [TestMethod]
public void BuildAttributeFileContent_MultipleAssemblies_EmitsAllAssemblyAttributes()
{
var content = PublicizeInternals.BuildAttributeFileContent(["Assembly1", "Assembly2"], omitAttributeDefinition: false);
- Assert.Contains("[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(\"Assembly1\")]", content);
- Assert.Contains("[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(\"Assembly2\")]", content);
- Assert.Contains("class IgnoresAccessChecksToAttribute", content);
+ StringAssert.Contains(content, "[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(\"Assembly1\")]");
+ StringAssert.Contains(content, "[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(\"Assembly2\")]");
+ StringAssert.Contains(content, "class IgnoresAccessChecksToAttribute");
}
- [Fact]
+ [TestMethod]
public void BuildAttributeFileContent_MultipleAssembliesOmitDefinition_EmitsAllAssemblyAttributesWithoutClass()
{
var content = PublicizeInternals.BuildAttributeFileContent(["Assembly1", "Assembly2"], omitAttributeDefinition: true);
- Assert.Contains("[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(\"Assembly1\")]", content);
- Assert.Contains("[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(\"Assembly2\")]", content);
- Assert.DoesNotContain("class IgnoresAccessChecksToAttribute", content);
+ StringAssert.Contains(content, "[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(\"Assembly1\")]");
+ StringAssert.Contains(content, "[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(\"Assembly2\")]");
+ Assert.IsFalse(content.Contains("class IgnoresAccessChecksToAttribute"));
}
}
diff --git a/test/nuget.config b/test/IgnoresAccessChecksToGenerator.Test/nuget.config
similarity index 53%
rename from test/nuget.config
rename to test/IgnoresAccessChecksToGenerator.Test/nuget.config
index 80c0a50..18ebdd6 100644
--- a/test/nuget.config
+++ b/test/IgnoresAccessChecksToGenerator.Test/nuget.config
@@ -1,6 +1,6 @@
-
+
From 148347e23a9f0e58eca756e4484b587e66935757 Mon Sep 17 00:00:00 2001
From: Eli Arbel <496737+aelij@users.noreply.github.com>
Date: Sun, 5 Jul 2026 23:15:39 +0300
Subject: [PATCH 4/6] Changes
---
.github/workflows/dotnet.yml | 2 -
Directory.Build.props | 10 ++++
Directory.Packages.props | 12 ++++
IgnoresAccessChecksToGenerator.slnx | 8 +++
README.md | 25 ++++++++
global.json | 3 +-
...gnoresAccessChecksToGenerator.Tasks.csproj | 13 ++--
.../PublicizeInternals.cs | 59 +++++++++++++++----
.../IgnoresAccessChecksToGenerator.targets | 9 +--
src/IgnoresAccessChecksToGenerator.sln | 31 ----------
...sAccessChecksToGenerator.Tasks.Test.csproj | 8 ---
.../PublicizeInternalsTests.cs | 51 ++++++++++++++++
...IgnoresAccessChecksToGenerator.Test.csproj | 5 +-
.../IgnoresAccessChecksToGenerator.Test.sln | 22 -------
.../nuget.config | 3 +-
15 files changed, 164 insertions(+), 97 deletions(-)
create mode 100644 Directory.Build.props
create mode 100644 Directory.Packages.props
create mode 100644 IgnoresAccessChecksToGenerator.slnx
delete mode 100644 src/IgnoresAccessChecksToGenerator.sln
delete mode 100644 test/IgnoresAccessChecksToGenerator.Test/IgnoresAccessChecksToGenerator.Test.sln
diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml
index 9d3838c..0ab94c8 100644
--- a/.github/workflows/dotnet.yml
+++ b/.github/workflows/dotnet.yml
@@ -15,8 +15,6 @@ jobs:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
- with:
- dotnet-version: 10.0.301
- name: Restore dependencies
run: dotnet restore src
- name: Build
diff --git a/Directory.Build.props b/Directory.Build.props
new file mode 100644
index 0000000..97b7b08
--- /dev/null
+++ b/Directory.Build.props
@@ -0,0 +1,10 @@
+
+
+
+ net10.0
+ enable
+ enable
+ 1.0.0
+
+
+
diff --git a/Directory.Packages.props b/Directory.Packages.props
new file mode 100644
index 0000000..372e07c
--- /dev/null
+++ b/Directory.Packages.props
@@ -0,0 +1,12 @@
+
+
+ true
+ true
+ $(NoWarn);NU1507
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/IgnoresAccessChecksToGenerator.slnx b/IgnoresAccessChecksToGenerator.slnx
new file mode 100644
index 0000000..d71693e
--- /dev/null
+++ b/IgnoresAccessChecksToGenerator.slnx
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/README.md b/README.md
index 4739ec6..827d9eb 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,31 @@ Just add the package and define `IgnoresAccessChecksTo` items with the assemblie
```
+### Excluding types
+
+Use `IgnoresAccessChecksToExcludeTypeName` to keep specific types from being publicized. By default an exclusion applies to every assembly being processed. To scope an exclusion to a single assembly, add the `Assembly` metadata:
+
+```xml
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+```
+
## MSBuild Properties
### `IgnoresAccessChecksToOmitAttributeDefinition`
diff --git a/global.json b/global.json
index 6afb88e..c0fa68d 100644
--- a/global.json
+++ b/global.json
@@ -1,7 +1,6 @@
{
"sdk": {
- "version": "10.0.301",
- "rollForward": "latestFeature"
+ "version": "10.0.301"
},
"msbuild-sdks": {
"MSTest.Sdk": "4.2.3"
diff --git a/src/IgnoresAccessChecksToGenerator.Tasks/IgnoresAccessChecksToGenerator.Tasks.csproj b/src/IgnoresAccessChecksToGenerator.Tasks/IgnoresAccessChecksToGenerator.Tasks.csproj
index cc1308f..ec89365 100644
--- a/src/IgnoresAccessChecksToGenerator.Tasks/IgnoresAccessChecksToGenerator.Tasks.csproj
+++ b/src/IgnoresAccessChecksToGenerator.Tasks/IgnoresAccessChecksToGenerator.Tasks.csproj
@@ -1,10 +1,9 @@
-
+
netstandard2.0;net462
latest
IgnoresAccessChecksToGenerator
- 0.9.0
true
Eli Arbel
https://github.com/aelij/IgnoresAccessChecksToGenerator
@@ -15,20 +14,16 @@
true
$(TargetsForTfmSpecificBuildOutput);IncludePackageDependencies
-
-
-
-
+
+
-
-
-
+
\ No newline at end of file
diff --git a/src/IgnoresAccessChecksToGenerator.Tasks/PublicizeInternals.cs b/src/IgnoresAccessChecksToGenerator.Tasks/PublicizeInternals.cs
index 08ef60f..34f7995 100644
--- a/src/IgnoresAccessChecksToGenerator.Tasks/PublicizeInternals.cs
+++ b/src/IgnoresAccessChecksToGenerator.Tasks/PublicizeInternals.cs
@@ -1,17 +1,14 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Runtime.CompilerServices;
+using System.Runtime.CompilerServices;
using Microsoft.Build.Framework;
-using Microsoft.Build.Utilities;
using Mono.Cecil;
[assembly: InternalsVisibleTo("IgnoresAccessChecksToGenerator.Tasks.Test")]
+#nullable disable
+
namespace IgnoresAccessChecksToGenerator.Tasks
{
- public class PublicizeInternals : Task
+ public class PublicizeInternals : Microsoft.Build.Utilities.Task
{
private readonly AssemblyResolver _resolver = new AssemblyResolver();
@@ -42,10 +39,13 @@ public override bool Execute()
return true;
}
- var excludedTypeNames = new HashSet(StringComparer.OrdinalIgnoreCase);
+ var excludedTypeNames = new TypeExclusions();
if (ExcludeTypeNames != null)
{
- excludedTypeNames = new HashSet(ExcludeTypeNames.Select(t => t.ItemSpec), StringComparer.OrdinalIgnoreCase);
+ foreach (var item in ExcludeTypeNames)
+ {
+ excludedTypeNames.Add(item.ItemSpec, item.GetMetadata("Assembly"));
+ }
}
var targetPath = IntermediateOutputPath;
@@ -67,7 +67,7 @@ public override bool Execute()
{
var targetAssemblyPath = Path.Combine(targetPath, Path.GetFileName(assemblyPath));
- CreatePublicAssembly(assemblyPath, targetAssemblyPath, excludedTypeNames);
+ CreatePublicAssembly(assemblyName, assemblyPath, targetAssemblyPath, excludedTypeNames);
Log.LogMessageFromText("Created publicized assembly at " + targetAssemblyPath, MessageImportance.Normal);
}
}
@@ -118,14 +118,14 @@ public IgnoresAccessChecksToAttribute(string assemblyName)
return content.TrimEnd() + Environment.NewLine;
}
- private void CreatePublicAssembly(string source, string target, HashSet excludedTypeNames)
+ private void CreatePublicAssembly(string assemblyName, string source, string target, TypeExclusions excludedTypeNames)
{
var assembly = AssemblyDefinition.ReadAssembly(source,
new ReaderParameters { AssemblyResolver = _resolver });
foreach (var module in assembly.Modules)
{
- foreach (var type in module.GetTypes().Where(type => !excludedTypeNames.Contains(type.FullName)))
+ foreach (var type in module.GetTypes().Where(type => !excludedTypeNames.IsExcluded(assemblyName, type.FullName)))
{
if (!type.IsNested && type.IsNotPublic)
{
@@ -174,6 +174,41 @@ private void CreatePublicAssembly(string source, string target, HashSet
private string GetFullFilePath(string basePath, string path) =>
Path.IsPathRooted(path) ? Path.GetFullPath(path) : Path.Combine(basePath, path);
+ internal sealed class TypeExclusions
+ {
+ private readonly HashSet _global = new HashSet(StringComparer.OrdinalIgnoreCase);
+ private readonly Dictionary> _perAssembly = new Dictionary>(StringComparer.OrdinalIgnoreCase);
+
+ public void Add(string typeName, string assemblyName)
+ {
+ if (string.IsNullOrEmpty(typeName))
+ {
+ return;
+ }
+
+ if (string.IsNullOrEmpty(assemblyName))
+ {
+ _global.Add(typeName);
+ }
+ else
+ {
+ if (!_perAssembly.TryGetValue(assemblyName, out var set))
+ {
+ set = new HashSet(StringComparer.OrdinalIgnoreCase);
+ _perAssembly[assemblyName] = set;
+ }
+
+ set.Add(typeName);
+ }
+ }
+
+ public bool IsExcluded(string assemblyName, string typeFullName)
+ {
+ return _global.Contains(typeFullName) ||
+ (_perAssembly.TryGetValue(assemblyName, out var set) && set.Contains(typeFullName));
+ }
+ }
+
private class AssemblyResolver : IAssemblyResolver
{
private readonly HashSet _directories = new HashSet(StringComparer.OrdinalIgnoreCase);
diff --git a/src/IgnoresAccessChecksToGenerator.Tasks/build/IgnoresAccessChecksToGenerator.targets b/src/IgnoresAccessChecksToGenerator.Tasks/build/IgnoresAccessChecksToGenerator.targets
index 75c401a..48bb792 100644
--- a/src/IgnoresAccessChecksToGenerator.Tasks/build/IgnoresAccessChecksToGenerator.targets
+++ b/src/IgnoresAccessChecksToGenerator.Tasks/build/IgnoresAccessChecksToGenerator.targets
@@ -11,13 +11,7 @@
-
@@ -33,7 +27,8 @@
<_IACTG_OutputReferencePath Include="@(_IACTG_InputReferencePath->'$(_IACTG_IntermediatePath)/%(Filename)%(Extension)')" OriginalItemSpec="%(Identity)" />
- <_IACTG_Manifest Include="@(IgnoresAccessChecksToExcludeTypeName)" />
+ <_IACTG_Manifest Include="@(IgnoresAccessChecksToExcludeTypeName->'%(Identity)^%(Assembly)')" />
+ <_IACTG_Manifest Include="@(_IACTG_InputReferencePath)" />
diff --git a/src/IgnoresAccessChecksToGenerator.sln b/src/IgnoresAccessChecksToGenerator.sln
deleted file mode 100644
index fd74240..0000000
--- a/src/IgnoresAccessChecksToGenerator.sln
+++ /dev/null
@@ -1,31 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 17
-VisualStudioVersion = 17.5.33103.201
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IgnoresAccessChecksToGenerator.Tasks", "IgnoresAccessChecksToGenerator.Tasks\IgnoresAccessChecksToGenerator.Tasks.csproj", "{FFFAEEE5-E216-442C-9162-168AD30F57F5}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{D43D3D13-84B1-4D21-8E36-52BED4056097}"
- ProjectSection(SolutionItems) = preProject
- Build\IgnoresAccessChecksToGenerator.props = Build\IgnoresAccessChecksToGenerator.props
- Build\IgnoresAccessChecksToGenerator.targets = Build\IgnoresAccessChecksToGenerator.targets
- EndProjectSection
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {FFFAEEE5-E216-442C-9162-168AD30F57F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {FFFAEEE5-E216-442C-9162-168AD30F57F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {FFFAEEE5-E216-442C-9162-168AD30F57F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {FFFAEEE5-E216-442C-9162-168AD30F57F5}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- SolutionGuid = {93618651-EC7C-40FD-9683-C87FEC4A4947}
- EndGlobalSection
-EndGlobal
diff --git a/test/IgnoresAccessChecksToGenerator.Tasks.Test/IgnoresAccessChecksToGenerator.Tasks.Test.csproj b/test/IgnoresAccessChecksToGenerator.Tasks.Test/IgnoresAccessChecksToGenerator.Tasks.Test.csproj
index 9818107..c71b797 100644
--- a/test/IgnoresAccessChecksToGenerator.Tasks.Test/IgnoresAccessChecksToGenerator.Tasks.Test.csproj
+++ b/test/IgnoresAccessChecksToGenerator.Tasks.Test/IgnoresAccessChecksToGenerator.Tasks.Test.csproj
@@ -1,13 +1,5 @@
-
- net9.0
- enable
- enable
-
- false
-
-
diff --git a/test/IgnoresAccessChecksToGenerator.Tasks.Test/PublicizeInternalsTests.cs b/test/IgnoresAccessChecksToGenerator.Tasks.Test/PublicizeInternalsTests.cs
index 23e7e0e..93e63bf 100644
--- a/test/IgnoresAccessChecksToGenerator.Tasks.Test/PublicizeInternalsTests.cs
+++ b/test/IgnoresAccessChecksToGenerator.Tasks.Test/PublicizeInternalsTests.cs
@@ -43,3 +43,54 @@ public void BuildAttributeFileContent_MultipleAssembliesOmitDefinition_EmitsAllA
Assert.IsFalse(content.Contains("class IgnoresAccessChecksToAttribute"));
}
}
+
+[TestClass]
+public class TypeExclusionsTests
+{
+ [TestMethod]
+ public void GlobalExclusion_AppliesToAllAssemblies()
+ {
+ var exclusions = new PublicizeInternals.TypeExclusions();
+ exclusions.Add("Namespace.TypeName", assemblyName: "");
+
+ Assert.IsTrue(exclusions.IsExcluded("AssemblyA", "Namespace.TypeName"));
+ Assert.IsTrue(exclusions.IsExcluded("AssemblyB", "Namespace.TypeName"));
+ }
+
+ [TestMethod]
+ public void AssemblyScopedExclusion_AppliesOnlyToThatAssembly()
+ {
+ var exclusions = new PublicizeInternals.TypeExclusions();
+ exclusions.Add("Namespace.TypeName", assemblyName: "AssemblyA");
+
+ Assert.IsTrue(exclusions.IsExcluded("AssemblyA", "Namespace.TypeName"));
+ Assert.IsFalse(exclusions.IsExcluded("AssemblyB", "Namespace.TypeName"));
+ }
+
+ [TestMethod]
+ public void AssemblyScopedExclusion_IsCaseInsensitive()
+ {
+ var exclusions = new PublicizeInternals.TypeExclusions();
+ exclusions.Add("Namespace.TypeName", assemblyName: "AssemblyA");
+
+ Assert.IsTrue(exclusions.IsExcluded("assemblya", "namespace.typename"));
+ }
+
+ [TestMethod]
+ public void UnknownType_IsNotExcluded()
+ {
+ var exclusions = new PublicizeInternals.TypeExclusions();
+ exclusions.Add("Namespace.TypeName", assemblyName: "AssemblyA");
+
+ Assert.IsFalse(exclusions.IsExcluded("AssemblyA", "Namespace.OtherType"));
+ }
+
+ [TestMethod]
+ public void EmptyTypeName_IsIgnored()
+ {
+ var exclusions = new PublicizeInternals.TypeExclusions();
+ exclusions.Add("", assemblyName: "AssemblyA");
+
+ Assert.IsFalse(exclusions.IsExcluded("AssemblyA", ""));
+ }
+}
diff --git a/test/IgnoresAccessChecksToGenerator.Test/IgnoresAccessChecksToGenerator.Test.csproj b/test/IgnoresAccessChecksToGenerator.Test/IgnoresAccessChecksToGenerator.Test.csproj
index b20dfb1..24e975d 100644
--- a/test/IgnoresAccessChecksToGenerator.Test/IgnoresAccessChecksToGenerator.Test.csproj
+++ b/test/IgnoresAccessChecksToGenerator.Test/IgnoresAccessChecksToGenerator.Test.csproj
@@ -1,7 +1,6 @@
- net8.0
Exe
@@ -12,8 +11,8 @@
-
-
+
+
diff --git a/test/IgnoresAccessChecksToGenerator.Test/IgnoresAccessChecksToGenerator.Test.sln b/test/IgnoresAccessChecksToGenerator.Test/IgnoresAccessChecksToGenerator.Test.sln
deleted file mode 100644
index b9b2090..0000000
--- a/test/IgnoresAccessChecksToGenerator.Test/IgnoresAccessChecksToGenerator.Test.sln
+++ /dev/null
@@ -1,22 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.26430.16
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IgnoresAccessChecksToGenerator.Test", "IgnoresAccessChecksToGenerator.Test.csproj", "{9BA0FB27-1DAF-43CD-A0EE-F952EE198D5F}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {9BA0FB27-1DAF-43CD-A0EE-F952EE198D5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {9BA0FB27-1DAF-43CD-A0EE-F952EE198D5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {9BA0FB27-1DAF-43CD-A0EE-F952EE198D5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {9BA0FB27-1DAF-43CD-A0EE-F952EE198D5F}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
-EndGlobal
diff --git a/test/IgnoresAccessChecksToGenerator.Test/nuget.config b/test/IgnoresAccessChecksToGenerator.Test/nuget.config
index 18ebdd6..5a846b6 100644
--- a/test/IgnoresAccessChecksToGenerator.Test/nuget.config
+++ b/test/IgnoresAccessChecksToGenerator.Test/nuget.config
@@ -1,6 +1,7 @@
-
+
+
From cfe67eb395f87acea2d7e33b272c0872a0be67d6 Mon Sep 17 00:00:00 2001
From: Eli Arbel <496737+aelij@users.noreply.github.com>
Date: Sun, 5 Jul 2026 23:19:26 +0300
Subject: [PATCH 5/6] Fix build
---
.github/workflows/dotnet.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml
index 0ab94c8..ee185c9 100644
--- a/.github/workflows/dotnet.yml
+++ b/.github/workflows/dotnet.yml
@@ -16,6 +16,6 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
- name: Restore dependencies
- run: dotnet restore src
+ run: dotnet restore
- name: Build
- run: dotnet build src --no-restore
+ run: dotnet build --no-restore
From 899af848cb5e41a7441a8c6f38bff9a7444a51d4 Mon Sep 17 00:00:00 2001
From: Eli Arbel <496737+aelij@users.noreply.github.com>
Date: Sun, 5 Jul 2026 23:20:06 +0300
Subject: [PATCH 6/6] Add test
---
.github/workflows/dotnet.yml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml
index ee185c9..2d3f9fc 100644
--- a/.github/workflows/dotnet.yml
+++ b/.github/workflows/dotnet.yml
@@ -19,3 +19,5 @@ jobs:
run: dotnet restore
- name: Build
run: dotnet build --no-restore
+ - name: Test
+ run: dotnet test --no-build