Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
aelij committed Nov 22, 2022
1 parent 8ee9391 commit cf3816a
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,5 @@ __pycache__/
*.btm.cs
*.odx.cs
*.xsd.cs

*.binlog
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ Just add the package and define the `InternalsAssemblyNames` property with a sem
```xml
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<InternalsAssemblyNames>AssemblyToGrantAccessTo1;AssemblyToGrantAccessTo2</InternalsAssemblyNames>
</PropertyGroup>
<ItemGroup>
<InternalsAssemblyName Include="AssemblyToGrantAccessTo1" />
<InternalsAssemblyName Include="AssemblyToGrantAccessTo2" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="IgnoresAccessChecksToGenerator" Version="0.4.0" PrivateAssets="All" />
<PackageReference Include="IgnoresAccessChecksToGenerator" Version="0.6.0" PrivateAssets="All" />
</ItemGroup>

</Project>
Expand Down
9 changes: 9 additions & 0 deletions src/Build/IgnoresAccessChecksToGenerator.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project>

<ItemDefinitionGroup>
<InternalsAssemblyName>
<Visible>false</Visible>
</InternalsAssemblyName>
</ItemDefinitionGroup>

</Project>
29 changes: 18 additions & 11 deletions src/Build/IgnoresAccessChecksToGenerator.targets
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<_IACTG_TFM Condition="'$(MSBuildRuntimeType)' == 'Core'">netstandard2.0</_IACTG_TFM>
<_IACTG_TFM Condition="'$(MSBuildRuntimeType)' != 'Core'">net46</_IACTG_TFM>
<_IACTG_TaskAssembly>$(MSBuildThisFileDirectory)..\tools\$(_IACTG_TFM)\IgnoresAccessChecksToGenerator.Tasks.dll</_IACTG_TaskAssembly>
<_IACTG_TargetFramework Condition="'$(MSBuildRuntimeType)' == 'Core'">netstandard2.0</_IACTG_TargetFramework>
<_IACTG_TargetFramework Condition="'$(MSBuildRuntimeType)' != 'Core'">net46</_IACTG_TargetFramework>
<_IACTG_TaskAssembly>$(MSBuildThisFileDirectory)..\tools\$(_IACTG_TargetFramework)\IgnoresAccessChecksToGenerator.Tasks.dll</_IACTG_TaskAssembly>
<_IACTG_IntermediatePath>$(IntermediateOutputPath)/GeneratedPublicizedAssemblies</_IACTG_IntermediatePath>
</PropertyGroup>

<UsingTask AssemblyFile="$(_IACTG_TaskAssembly)" TaskName="IgnoresAccessChecksToGenerator.Tasks.PublicizeInternals" />

<Target Name="IgnoresAccessChecksToGenerator" AfterTargets="AfterResolveReferences">
<PublicizeInternals
SourceReferences="@(ReferencePath)"
AssemblyNames="$(InternalsAssemblyNames)"
ExcludeTypeNames="$(InternalsAssemblyExcludeTypeNames)"
UseEmptyMethodBodies="$(InternalsAssemblyUseEmptyMethodBodies)"
IntermediateOutputDirectory="$(IntermediateOutputPath)">
<Output ItemName="ReferencePath" TaskParameter="TargetReferences" />
<ItemGroup>
<InternalsAssemblyName Include="$(InternalsAssemblyNames.Split(;))" />
</ItemGroup>
<PublicizeInternals SourceReferences="@(ReferencePath)" AssemblyNames="@(InternalsAssemblyName)" ExcludeTypeNames="$(InternalsAssemblyExcludeTypeNames)" UseEmptyMethodBodies="$(InternalsAssemblyUseEmptyMethodBodies)" IntermediateOutputPath="$(_IACTG_IntermediatePath)">
<Output ItemName="_IACTG_ReferencePath" TaskParameter="TargetReferences" />
<Output ItemName="_IACTG_RemovedReferences" TaskParameter="RemovedReferences" />
<Output ItemName="Compile" TaskParameter="GeneratedCodeFiles" />
</PublicizeInternals>
<ItemGroup>
<ReferencePath Include="@(_IACTG_ReferencePath)" />
<ReferencePath Remove="@(_IACTG_RemovedReferences)" />
</ItemGroup>
</Target>

<Target Name="IgnoresAccessChecksToGeneratorClean" AfterTargets="Clean">
<ItemGroup>
<_IACTG_Directory Include="$(_IACTG_IntermediatePath)" />
</ItemGroup>
<RemoveDir Directories="@(_IACTG_Directory)" />
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<package>
<metadata>
<id>IgnoresAccessChecksToGenerator</id>
<version>0.5.0</version>
<version>0.6.0</version>
<authors>aelij</authors>
<owners>aelij</owners>
<license type="expression">MIT</license>
<projectUrl>https://github.com/aelij/IgnoresAccessChecksToGenerator</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Generates IgnoresAccessChecksTo attributes and reference assemblies to allow compile-time access to internals</description>
<releaseNotes></releaseNotes>
<copyright>Copyright 2021</copyright>
<copyright>Copyright 2022</copyright>
<tags>IgnoresAccessChecksToGenerator internals</tags>
</metadata>
<files>
Expand Down
21 changes: 8 additions & 13 deletions src/IgnoresAccessChecksToGenerator.Tasks/PublicizeInternals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public class PublicizeInternals : Task
public ITaskItem[] SourceReferences { get; set; }

[Required]
public string AssemblyNames { get; set; }
public ITaskItem[] AssemblyNames { get; set; }

[Required]
public string IntermediateOutputDirectory { get; set; }
public string IntermediateOutputPath { get; set; }

public string ExcludeTypeNames { get; set; }

Expand All @@ -40,22 +40,20 @@ public override bool Execute()
{
if (SourceReferences == null) throw new ArgumentNullException(nameof(SourceReferences));

var assemblyNames = new HashSet<string>(
(AssemblyNames ?? string.Empty).Split(Semicolon, StringSplitOptions.RemoveEmptyEntries),
StringComparer.OrdinalIgnoreCase);
var assemblyNames = new HashSet<string>(AssemblyNames.Select(t => t.ItemSpec), StringComparer.OrdinalIgnoreCase);

if (assemblyNames.Count == 0)
{
return true;
}

var targetPath = Path.Combine(IntermediateOutputDirectory, "GeneratedPublicizedAssemblies");
var targetPath = IntermediateOutputPath;
Directory.CreateDirectory(targetPath);

GenerateAttributes(targetPath, assemblyNames);

foreach (var assemblyPath in SourceReferences
.Select(a => Path.GetDirectoryName(GetFullFilePath(a.ItemSpec))))
.Select(a => Path.GetDirectoryName(GetFullFilePath(targetPath, a.ItemSpec))))
{
_resolver.AddSearchDirectory(assemblyPath);
}
Expand All @@ -65,7 +63,7 @@ public override bool Execute()

foreach (var assembly in SourceReferences)
{
var assemblyPath = GetFullFilePath(assembly.ItemSpec);
var assemblyPath = GetFullFilePath(targetPath, assembly.ItemSpec);
var assemblyName = Path.GetFileNameWithoutExtension(assemblyPath);
if (assemblyNames.Contains(assemblyName))
{
Expand Down Expand Up @@ -174,11 +172,8 @@ private void CreatePublicAssembly(string source, string target)
assembly.Write(target);
}

private string GetFullFilePath(string path)
{
path = Path.GetFullPath(path);
return path;
}
private string GetFullFilePath(string basePath, string path) =>
Path.IsPathRooted(path) ? Path.GetFullPath(path) : Path.Combine(basePath, path);

private class AssemblyResolver : IAssemblyResolver
{
Expand Down
13 changes: 6 additions & 7 deletions src/IgnoresAccessChecksToGenerator.sln
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.16
# 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
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{1CD3690D-3079-4F56-B140-036590665068}"
ProjectSection(SolutionItems) = preProject
IgnoresAccessChecksToGenerator.nuspec = IgnoresAccessChecksToGenerator.nuspec
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -29,4 +25,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {93618651-EC7C-40FD-9683-C87FEC4A4947}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<InternalsAssemblyNames>Microsoft.CodeAnalysis;Microsoft.CodeAnalysis.CSharp</InternalsAssemblyNames>
<InternalsAssemblyUseEmptyMethodBodies>false</InternalsAssemblyUseEmptyMethodBodies>
</PropertyGroup>

<ItemGroup>
<InternalsAssemblyName Include="Microsoft.CodeAnalysis" />
<InternalsAssemblyName Include="Microsoft.CodeAnalysis.CSharp" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="IgnoresAccessChecksToGenerator" Version="0.5.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.3.1" />
Expand Down

0 comments on commit cf3816a

Please sign in to comment.