Skip to content

Commit a6c207d

Browse files
committed
Unify and future-proof Assembly*Attributes with Constants
One more unification and this is likely the last one. Rather than a custom generator for assembly info attributes, we leverage MSBuild (similar to how the Metadata package does it) to transform the same set of attributes and turn them into @(Constant) items. Now that custom and dynamic roots are possible, this is really straightforward and should be 100% backwards compatible. In the future, if additional aseembly-level attributes matching the `Assembly[Name]Attribute` convention are added to the SDK, they will be surfaced automatically as well.
1 parent 437436b commit a6c207d

6 files changed

+20
-237
lines changed

src/ThisAssembly.AssemblyInfo/AssemblyInfoGenerator.cs

-111
This file was deleted.

src/ThisAssembly.AssemblyInfo/CSharp.sbntxt

-56
This file was deleted.

src/ThisAssembly.AssemblyInfo/Model.cs

-21
This file was deleted.

src/ThisAssembly.AssemblyInfo/ThisAssembly.AssemblyInfo.csproj

+5-18
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
<IsRoslynComponent>true</IsRoslynComponent>
7-
<!-- This generator supports VB too -->
8-
<PackFolder>analyzers/dotnet/roslyn$(ThisAssemblyMinimumRoslynVersion)</PackFolder>
7+
<PackBuildOutput>false</PackBuildOutput>
98
</PropertyGroup>
109

1110
<PropertyGroup>
@@ -28,30 +27,18 @@ on the `ThisAssembly.Info` class.
2827
</Description>
2928
</PropertyGroup>
3029

31-
<PropertyGroup Label="SponsorLink">
32-
<CustomAfterMicrosoftCSharpTargets>$(MSBuildThisFileDirectory)..\SponsorLink\SponsorLink.Analyzer.targets</CustomAfterMicrosoftCSharpTargets>
33-
<FundingPackageId>ThisAssembly;$(PackageId)</FundingPackageId>
34-
</PropertyGroup>
30+
<ItemGroup>
31+
<None Remove="ThisAssembly.AssemblyInfo.targets" />
32+
</ItemGroup>
3533

3634
<ItemGroup>
3735
<PackageReference Include="NuGetizer" Version="1.2.2" />
38-
39-
<PackageReference Include="Scriban" Version="5.10.0" Pack="false" IncludeAssets="build" />
40-
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
41-
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
42-
43-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" Pack="false" />
44-
<PackageReference Include="PolySharp" Version="1.14.1" PrivateAssets="All" />
4536
</ItemGroup>
4637

4738
<ItemGroup>
48-
<InternalsVisibleTo Include="ThisAssembly.Tests" />
39+
<ProjectReference Include="..\ThisAssembly.Constants\ThisAssembly.Constants.csproj" />
4940
</ItemGroup>
5041

51-
<Target Name="VerifySponsorLink" AfterTargets="Build">
52-
<Error Condition="'$(SponsorLinkImported)' != 'true'" Text="SponsorLink was not imported." />
53-
</Target>
54-
5542
<Import Project="..\Shared\Shared.projitems" Label="Shared" />
5643

5744
</Project>

src/ThisAssembly.AssemblyInfo/ThisAssembly.AssemblyInfo.targets

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<Project>
2-
<Import Project="..\..\buildTransitive\Devlooped.Sponsors.targets" Condition="Exists('..\..\buildTransitive\Devlooped.Sponsors.targets')"/>
3-
42
<ItemGroup>
53
<CompilerVisibleProperty Include="ThisAssemblyNamespace" />
64

@@ -12,4 +10,19 @@
1210
<FundingPackageId Include="ThisAssembly.AssemblyInfo" />
1311
</ItemGroup>
1412

13+
<Target Name="PrepareAssemblyInfoConstants"
14+
BeforeTargets="PrepareConstants"
15+
DependsOnTargets="GetAssemblyAttributes">
16+
<ItemGroup>
17+
<AssemblyInfoAttribute Include="@(AssemblyAttribute)"
18+
Exclude="System.Reflection.AssemblyMetadataAttribute;System.Reflection.AssemblyMetadata"
19+
Condition="$([MSBuild]::ValueOrDefault('%(Identity)', '').StartsWith('System.Reflection.Assembly')) == 'true'">
20+
<Name>$([MSBuild]::ValueOrDefault('%(Identity)', '').Substring(26).Replace('Attribute', ''))</Name>
21+
</AssemblyInfoAttribute>
22+
</ItemGroup>
23+
<ItemGroup>
24+
<Constant Include="@(AssemblyInfoAttribute -> 'Info.%(Name)')" Value="%(AssemblyInfoAttribute._Parameter1)" Root="." />
25+
</ItemGroup>
26+
</Target>
27+
1528
</Project>

src/ThisAssembly.AssemblyInfo/Visual Basic.sbntxt

-29
This file was deleted.

0 commit comments

Comments
 (0)