Skip to content

Commit

Permalink
Unify and future-proof Assembly*Attributes with Constants
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kzu committed Sep 17, 2024
1 parent 437436b commit a6c207d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 237 deletions.
111 changes: 0 additions & 111 deletions src/ThisAssembly.AssemblyInfo/AssemblyInfoGenerator.cs

This file was deleted.

56 changes: 0 additions & 56 deletions src/ThisAssembly.AssemblyInfo/CSharp.sbntxt

This file was deleted.

21 changes: 0 additions & 21 deletions src/ThisAssembly.AssemblyInfo/Model.cs

This file was deleted.

23 changes: 5 additions & 18 deletions src/ThisAssembly.AssemblyInfo/ThisAssembly.AssemblyInfo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<IsRoslynComponent>true</IsRoslynComponent>
<!-- This generator supports VB too -->
<PackFolder>analyzers/dotnet/roslyn$(ThisAssemblyMinimumRoslynVersion)</PackFolder>
<PackBuildOutput>false</PackBuildOutput>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -28,30 +27,18 @@ on the `ThisAssembly.Info` class.
</Description>
</PropertyGroup>

<PropertyGroup Label="SponsorLink">
<CustomAfterMicrosoftCSharpTargets>$(MSBuildThisFileDirectory)..\SponsorLink\SponsorLink.Analyzer.targets</CustomAfterMicrosoftCSharpTargets>
<FundingPackageId>ThisAssembly;$(PackageId)</FundingPackageId>
</PropertyGroup>
<ItemGroup>
<None Remove="ThisAssembly.AssemblyInfo.targets" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="NuGetizer" Version="1.2.2" />

<PackageReference Include="Scriban" Version="5.10.0" Pack="false" IncludeAssets="build" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />

<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" Pack="false" />
<PackageReference Include="PolySharp" Version="1.14.1" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="ThisAssembly.Tests" />
<ProjectReference Include="..\ThisAssembly.Constants\ThisAssembly.Constants.csproj" />
</ItemGroup>

<Target Name="VerifySponsorLink" AfterTargets="Build">
<Error Condition="'$(SponsorLinkImported)' != 'true'" Text="SponsorLink was not imported." />
</Target>

<Import Project="..\Shared\Shared.projitems" Label="Shared" />

</Project>
17 changes: 15 additions & 2 deletions src/ThisAssembly.AssemblyInfo/ThisAssembly.AssemblyInfo.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<Project>
<Import Project="..\..\buildTransitive\Devlooped.Sponsors.targets" Condition="Exists('..\..\buildTransitive\Devlooped.Sponsors.targets')"/>

<ItemGroup>
<CompilerVisibleProperty Include="ThisAssemblyNamespace" />

Expand All @@ -12,4 +10,19 @@
<FundingPackageId Include="ThisAssembly.AssemblyInfo" />
</ItemGroup>

<Target Name="PrepareAssemblyInfoConstants"
BeforeTargets="PrepareConstants"
DependsOnTargets="GetAssemblyAttributes">
<ItemGroup>
<AssemblyInfoAttribute Include="@(AssemblyAttribute)"
Exclude="System.Reflection.AssemblyMetadataAttribute;System.Reflection.AssemblyMetadata"
Condition="$([MSBuild]::ValueOrDefault('%(Identity)', '').StartsWith('System.Reflection.Assembly')) == 'true'">
<Name>$([MSBuild]::ValueOrDefault('%(Identity)', '').Substring(26).Replace('Attribute', ''))</Name>
</AssemblyInfoAttribute>
</ItemGroup>
<ItemGroup>
<Constant Include="@(AssemblyInfoAttribute -> 'Info.%(Name)')" Value="%(AssemblyInfoAttribute._Parameter1)" Root="." />
</ItemGroup>
</Target>

</Project>
29 changes: 0 additions & 29 deletions src/ThisAssembly.AssemblyInfo/Visual Basic.sbntxt

This file was deleted.

0 comments on commit a6c207d

Please sign in to comment.