Skip to content

Commit 61b3a79

Browse files
committed
Enable attribute preservation by default, to enable the usage analyzers
1 parent 73f4c55 commit 61b3a79

4 files changed

Lines changed: 25 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ If you wish to preserve these attributes in the build output, you can define the
624624
</PropertyGroup>
625625

626626
<!-- Add the package -->
627-
<PackageReference Include="NetEscapades.EnumGenerators" Version="1.0.0-beta20" PrivateAssets="all" />
627+
<PackageReference Include="NetEscapades.EnumGenerators" Version="1.0.0-beta20" />
628628
<!--You must not exclude the runtime assets in this case -->
629629

630630
</Project>

src/NetEscapades.EnumGenerators/NetEscapades.EnumGenerators.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@
2121

2222
<ItemGroup>
2323
<None Include="README.md" Pack="true" PackagePath="\" />
24+
<None Include="NetEscapades.EnumGenerators.targets" Pack="true" PackagePath="buildTransitive" Visible="true" />
2425
</ItemGroup>
2526
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project>
2+
<!--
3+
Define NETESCAPADES_ENUMGENERATORS_USAGES so that the [Conditional] attribute on [EnumExtensions]
4+
is satisfied. This preserves the attribute in IL, enabling usage analyzers to detect decorated
5+
enums in referenced assemblies.
6+
7+
This targets file is only included in the meta-package, so it only runs when the meta-package is
8+
referenced. We additionally verify the Attributes assembly will be available at runtime by checking
9+
ReferenceCopyLocalPaths, which guards against unsupported configurations like ExcludeAssets="runtime".
10+
11+
Set EnumGenerator_PreserveAttributes to "false" to disable this behavior.
12+
13+
Note: using PrivateAssets="All" or ExcludeAssets="runtime" on the meta-package is not supported.
14+
-->
15+
<Target Name="NetEscapadesEnumGenerators_DefineUsages" AfterTargets="ResolveReferences" BeforeTargets="CoreCompile"
16+
Condition="'$(EnumGenerator_PreserveAttributes)' != 'false'">
17+
<PropertyGroup>
18+
<DefineConstants Condition="'@(ReferenceCopyLocalPaths->AnyHaveMetadataValue(`FileName`, `NetEscapades.EnumGenerators.Attributes`))' == 'True'">$(DefineConstants);NETESCAPADES_ENUMGENERATORS_USAGES</DefineConstants>
19+
</PropertyGroup>
20+
</Target>
21+
</Project>

tests/NetEscapades.EnumGenerators.NetStandard.Interceptors.IntegrationTests/NetEscapades.EnumGenerators.NetStandard.Interceptors.IntegrationTests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
OutputItemType="Analyzer" ReferenceOutputAssembly="true" />
3131
</ItemGroup>
3232

33+
<Import Project="..\..\src\NetEscapades.EnumGenerators\NetEscapades.EnumGenerators.targets" />
34+
3335
<ItemGroup>
3436
<Content Include="..\NetEscapades.EnumGenerators.IntegrationTests\xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
3537
</ItemGroup>

0 commit comments

Comments
 (0)