Skip to content

Commit

Permalink
#19: Add comment // <auto-generated> and attribute GeneratedCodeAttri…
Browse files Browse the repository at this point in the history
…bute to IgnoresAccessChecksToAttribute
  • Loading branch information
Tadej Koderman committed Oct 21, 2024
1 parent 47fbd6e commit 4e0a649
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
<LangVersion>latest</LangVersion>
<PackageId>IgnoresAccessChecksToGenerator</PackageId>
<Version>0.7.0</Version>
<Version>0.7.1</Version>
<DevelopmentDependency>true</DevelopmentDependency>
<Authors>Eli Arbel</Authors>
<RepositoryUrl>https://github.com/aelij/IgnoresAccessChecksToGenerator</RepositoryUrl>
Expand Down
18 changes: 16 additions & 2 deletions src/IgnoresAccessChecksToGenerator.Tasks/PublicizeInternals.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.Build.Framework;
Expand Down Expand Up @@ -72,21 +73,34 @@ public override bool Execute()

private void GenerateAttributes(string path, IEnumerable<string> assemblyNames)
{
var version = FileVersionInfo.GetVersionInfo(typeof(PublicizeInternals).Assembly.Location);
var attributes = string.Join(Environment.NewLine,
assemblyNames.Select(a => $@"[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo(""{a}"")]"));

var content = attributes + @"
var content = $$"""
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
{{attributes}}
namespace System.Runtime.CompilerServices
{
[global::System.CodeDom.Compiler.GeneratedCode("{{nameof(IgnoresAccessChecksToGenerator)}}", "{{version.ProductVersion}}")]
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}";
}
""";
File.WriteAllText(GeneratedCodeFilePath, content);

Log.LogMessageFromText("Generated IgnoresAccessChecksTo attributes", MessageImportance.Low);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="IgnoresAccessChecksToGenerator" Version="0.7.0" PrivateAssets="all" />
<PackageReference Include="IgnoresAccessChecksToGenerator" Version="0.7.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
</ItemGroup>

Expand Down

0 comments on commit 4e0a649

Please sign in to comment.