From 9d2bd0553db141a2c830390333c7c26ef7832e40 Mon Sep 17 00:00:00 2001
From: Eli Arbel <496737+aelij@users.noreply.github.com>
Date: Thu, 30 Nov 2023 19:11:54 +0200
Subject: [PATCH] Use incremental build
---
.gitignore | 2 +
README.md | 11 +---
.../IgnoresAccessChecksToGenerator.targets | 34 ----------
...gnoresAccessChecksToGenerator.Tasks.csproj | 32 ++++++----
.../IgnoresAccessChecksToGenerator.nuspec | 21 -------
.../PublicizeInternals.cs | 59 +++--------------
.../IgnoresAccessChecksToGenerator.props | 3 +
.../IgnoresAccessChecksToGenerator.targets | 63 +++++++++++++++++++
...IgnoresAccessChecksToGenerator.Test.csproj | 9 +--
test/nuget.config | 6 ++
10 files changed, 111 insertions(+), 129 deletions(-)
delete mode 100644 src/Build/IgnoresAccessChecksToGenerator.targets
delete mode 100644 src/IgnoresAccessChecksToGenerator.Tasks/IgnoresAccessChecksToGenerator.nuspec
rename src/{Build => IgnoresAccessChecksToGenerator.Tasks/build}/IgnoresAccessChecksToGenerator.props (59%)
create mode 100644 src/IgnoresAccessChecksToGenerator.Tasks/build/IgnoresAccessChecksToGenerator.targets
create mode 100644 test/nuget.config
diff --git a/.gitignore b/.gitignore
index ccfa9bd..f65898c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -288,3 +288,5 @@ __pycache__/
*.xsd.cs
*.binlog
+
+.DS_Store
diff --git a/README.md b/README.md
index 1e4c9c3..4ac51f2 100644
--- a/README.md
+++ b/README.md
@@ -16,19 +16,12 @@ Just add the package and define `InternalsAssemblyName` items with the assemblie
+
-
+
```
-
-By default, the build tasks replaces all method bodies with `throw null;`. To keep the original bodies, you can specify:
-
-```xml
-
- false
-
-```
diff --git a/src/Build/IgnoresAccessChecksToGenerator.targets b/src/Build/IgnoresAccessChecksToGenerator.targets
deleted file mode 100644
index 0e90059..0000000
--- a/src/Build/IgnoresAccessChecksToGenerator.targets
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
-
- <_IACTG_TargetFramework Condition="'$(MSBuildRuntimeType)' == 'Core'">netstandard2.0
- <_IACTG_TargetFramework Condition="'$(MSBuildRuntimeType)' != 'Core'">net46
- <_IACTG_TaskAssembly>$(MSBuildThisFileDirectory)..\tools\$(_IACTG_TargetFramework)\IgnoresAccessChecksToGenerator.Tasks.dll
- <_IACTG_IntermediatePath>$(IntermediateOutputPath)/GeneratedPublicizedAssemblies
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <_IACTG_Directory Include="$(_IACTG_IntermediatePath)" />
-
-
-
-
-
diff --git a/src/IgnoresAccessChecksToGenerator.Tasks/IgnoresAccessChecksToGenerator.Tasks.csproj b/src/IgnoresAccessChecksToGenerator.Tasks/IgnoresAccessChecksToGenerator.Tasks.csproj
index e8219b7..52637d8 100644
--- a/src/IgnoresAccessChecksToGenerator.Tasks/IgnoresAccessChecksToGenerator.Tasks.csproj
+++ b/src/IgnoresAccessChecksToGenerator.Tasks/IgnoresAccessChecksToGenerator.Tasks.csproj
@@ -1,25 +1,33 @@
- netstandard2.0;net46
- PackageReference
- IgnoresAccessChecksToGenerator.nuspec
+ netstandard2.0;net462
+ IgnoresAccessChecksToGenerator
+ 0.7.0
+ true
+ Eli Arbel
+ https://github.com/aelij/IgnoresAccessChecksToGenerator
+ MIT
+ Generates IgnoresAccessChecksTo attributes and reference assemblies to allow compile-time access to internals
+ IgnoresAccessChecksToGenerator IgnoresAccessChecksTo IgnoresAccessChecksToAttribute internals
+ tools/$(TargetFramework)
+ true
+ $(TargetsForTfmSpecificBuildOutput);IncludePackageDependencies
-
-
-
- all
- runtime; build; native; contentfiles; analyzers
-
+
-
+
+
+
+
+
+
-
+
-
diff --git a/src/IgnoresAccessChecksToGenerator.Tasks/IgnoresAccessChecksToGenerator.nuspec b/src/IgnoresAccessChecksToGenerator.Tasks/IgnoresAccessChecksToGenerator.nuspec
deleted file mode 100644
index be0f21b..0000000
--- a/src/IgnoresAccessChecksToGenerator.Tasks/IgnoresAccessChecksToGenerator.nuspec
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
- IgnoresAccessChecksToGenerator
- 0.6.0
- aelij
- aelij
- MIT
- https://github.com/aelij/IgnoresAccessChecksToGenerator
- false
- Generates IgnoresAccessChecksTo attributes and reference assemblies to allow compile-time access to internals
-
- Copyright 2022
- IgnoresAccessChecksToGenerator internals
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/IgnoresAccessChecksToGenerator.Tasks/PublicizeInternals.cs b/src/IgnoresAccessChecksToGenerator.Tasks/PublicizeInternals.cs
index 67daf77..9f3cbab 100644
--- a/src/IgnoresAccessChecksToGenerator.Tasks/PublicizeInternals.cs
+++ b/src/IgnoresAccessChecksToGenerator.Tasks/PublicizeInternals.cs
@@ -10,8 +10,6 @@ namespace IgnoresAccessChecksToGenerator.Tasks
{
public class PublicizeInternals : Task
{
- private static readonly char[] Semicolon = { ';' };
-
private readonly AssemblyResolver _resolver = new AssemblyResolver();
[Required]
@@ -23,18 +21,10 @@ public class PublicizeInternals : Task
[Required]
public string IntermediateOutputPath { get; set; }
- public string ExcludeTypeNames { get; set; }
-
- public bool UseEmptyMethodBodies { get; set; } = true;
-
- [Output]
- public ITaskItem[] TargetReferences { get; set; }
-
- [Output]
- public ITaskItem[] RemovedReferences { get; set; }
+ [Required]
+ public string GeneratedCodeFilePath { get; set; }
- [Output]
- public ITaskItem[] GeneratedCodeFiles { get; set; }
+ public ITaskItem[] ExcludeTypeNames { get; set; }
public override bool Execute()
{
@@ -47,6 +37,8 @@ public override bool Execute()
return true;
}
+ var excludedTypeNames = new HashSet(AssemblyNames.Select(t => t.ItemSpec), StringComparer.OrdinalIgnoreCase);
+
var targetPath = IntermediateOutputPath;
Directory.CreateDirectory(targetPath);
@@ -58,37 +50,19 @@ public override bool Execute()
_resolver.AddSearchDirectory(assemblyPath);
}
- var targetReferences = new List();
- var removedReferences = new List();
-
foreach (var assembly in SourceReferences)
{
var assemblyPath = GetFullFilePath(targetPath, assembly.ItemSpec);
var assemblyName = Path.GetFileNameWithoutExtension(assemblyPath);
if (assemblyNames.Contains(assemblyName))
{
- // ReSharper disable once AssignNullToNotNullAttribute
var targetAssemblyPath = Path.Combine(targetPath, Path.GetFileName(assemblyPath));
- var targetAsemblyFileInfo = new FileInfo(targetAssemblyPath);
- if (!targetAsemblyFileInfo.Exists || targetAsemblyFileInfo.Length == 0)
- {
- CreatePublicAssembly(assemblyPath, targetAssemblyPath);
- Log.LogMessageFromText("Created publicized assembly at " + targetAssemblyPath, MessageImportance.Normal);
- }
- else
- {
- Log.LogMessageFromText("Publicized assembly already exists at " + targetAssemblyPath, MessageImportance.Low);
- }
-
- targetReferences.Add(new TaskItem(targetAssemblyPath));
- removedReferences.Add(assembly);
+ CreatePublicAssembly(assemblyPath, targetAssemblyPath, excludedTypeNames);
+ Log.LogMessageFromText("Created publicized assembly at " + targetAssemblyPath, MessageImportance.Normal);
}
}
- TargetReferences = targetReferences.ToArray();
- RemovedReferences = removedReferences.ToArray();
-
return true;
}
@@ -109,24 +83,19 @@ public IgnoresAccessChecksToAttribute(string assemblyName)
}
}
}";
- var filePath = Path.Combine(path, "IgnoresAccessChecksTo.cs");
- File.WriteAllText(filePath, content);
-
- GeneratedCodeFiles = new ITaskItem[] { new TaskItem(filePath) };
+ File.WriteAllText(GeneratedCodeFilePath, content);
Log.LogMessageFromText("Generated IgnoresAccessChecksTo attributes", MessageImportance.Low);
}
- private void CreatePublicAssembly(string source, string target)
+ private void CreatePublicAssembly(string source, string target, HashSet excludedTypeNames)
{
- var types = ExcludeTypeNames == null ? Array.Empty() : ExcludeTypeNames.Split(Semicolon);
-
var assembly = AssemblyDefinition.ReadAssembly(source,
new ReaderParameters { AssemblyResolver = _resolver });
foreach (var module in assembly.Modules)
{
- foreach (var type in module.GetTypes().Where(type=>!types.Contains(type.FullName)))
+ foreach (var type in module.GetTypes().Where(type => !excludedTypeNames.Contains(type.FullName)))
{
if (!type.IsNested && type.IsNotPublic)
{
@@ -151,14 +120,6 @@ private void CreatePublicAssembly(string source, string target)
foreach (var method in type.Methods)
{
- if (UseEmptyMethodBodies && method.HasBody)
- {
- var emptyBody = new Mono.Cecil.Cil.MethodBody(method);
- emptyBody.Instructions.Add(Mono.Cecil.Cil.Instruction.Create(Mono.Cecil.Cil.OpCodes.Ldnull));
- emptyBody.Instructions.Add(Mono.Cecil.Cil.Instruction.Create(Mono.Cecil.Cil.OpCodes.Throw));
- method.Body = emptyBody;
- }
-
if (method.IsAssembly ||
method.IsFamilyOrAssembly ||
method.IsFamilyAndAssembly)
diff --git a/src/Build/IgnoresAccessChecksToGenerator.props b/src/IgnoresAccessChecksToGenerator.Tasks/build/IgnoresAccessChecksToGenerator.props
similarity index 59%
rename from src/Build/IgnoresAccessChecksToGenerator.props
rename to src/IgnoresAccessChecksToGenerator.Tasks/build/IgnoresAccessChecksToGenerator.props
index e09bbb2..43237f1 100644
--- a/src/Build/IgnoresAccessChecksToGenerator.props
+++ b/src/IgnoresAccessChecksToGenerator.Tasks/build/IgnoresAccessChecksToGenerator.props
@@ -4,6 +4,9 @@
false
+
+ false
+
diff --git a/src/IgnoresAccessChecksToGenerator.Tasks/build/IgnoresAccessChecksToGenerator.targets b/src/IgnoresAccessChecksToGenerator.Tasks/build/IgnoresAccessChecksToGenerator.targets
new file mode 100644
index 0000000..831562a
--- /dev/null
+++ b/src/IgnoresAccessChecksToGenerator.Tasks/build/IgnoresAccessChecksToGenerator.targets
@@ -0,0 +1,63 @@
+
+
+
+ <_IACTG_TargetFramework Condition="'$(MSBuildRuntimeType)' == 'Core'">netstandard2.0
+ <_IACTG_TargetFramework Condition="'$(MSBuildRuntimeType)' != 'Core'">net462
+ <_IACTG_TaskAssembly>$(MSBuildThisFileDirectory)../tools/$(_IACTG_TargetFramework)/IgnoresAccessChecksToGenerator.Tasks.dll
+ <_IACTG_IntermediatePath>$(IntermediateOutputPath)/IgnoresAccessChecksToGenerator
+ <_IACTG_CodeFilePath>$(_IACTG_IntermediatePath)/IgnoresAccessChecksTo.cs
+ <_IACTG_ManifestFilePath>$(_IACTG_IntermediatePath)/IgnoresAccessChecksToGenerator.manifest
+
+
+
+
+
+
+
+
+
+
+
+ <_IACTG_ReferencePathJoin Include="@(ReferencePath)" InternalsAssemblyName="%(InternalsAssemblyName.Identity)" />
+ <_IACTG_InputReferencePath Include="@(_IACTG_ReferencePathJoin)" Condition=" '%(Filename)' == '%(InternalsAssemblyName)' " />
+ <_IACTG_ReferencePathJoin Remove="@(_IACTG_ReferencePathJoin)" />
+ <_IACTG_OutputReferencePath Include="@(_IACTG_InputReferencePath->'$(_IACTG_IntermediatePath)/%(Filename)%(Extension)')" OriginalItemSpec="%(Identity)" />
+
+
+ <_IACTG_Manifest Include="@(InternalsAssemblyExcludeTypeName)" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <_IACTG_Directory Include="$(_IACTG_IntermediatePath)" />
+
+
+
+
+
diff --git a/test/IgnoresAccessChecksToGenerator.Test/IgnoresAccessChecksToGenerator.Test.csproj b/test/IgnoresAccessChecksToGenerator.Test/IgnoresAccessChecksToGenerator.Test.csproj
index ac9e4f2..26ccf29 100644
--- a/test/IgnoresAccessChecksToGenerator.Test/IgnoresAccessChecksToGenerator.Test.csproj
+++ b/test/IgnoresAccessChecksToGenerator.Test/IgnoresAccessChecksToGenerator.Test.csproj
@@ -1,19 +1,20 @@
- net6.0
+ net8.0
Exe
- false
+ true
+
-
-
+
+
\ No newline at end of file
diff --git a/test/nuget.config b/test/nuget.config
new file mode 100644
index 0000000..80c0a50
--- /dev/null
+++ b/test/nuget.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+