Skip to content

Commit

Permalink
Simplify [AssemblyMetadata]
Browse files Browse the repository at this point in the history
Simplify setting `[AssemblyMetadata]` attributes via .NET SDK feature.
  • Loading branch information
martincostello authored Oct 4, 2023
1 parent 2c52625 commit 1fbb701
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<CommitHash Condition=" '$(CommitHash)' == '' ">$(GITHUB_SHA)</CommitHash>
</PropertyGroup>
<Target Name="AddGitMetadaAssemblyAttributes"
BeforeTargets="CoreGenerateAssemblyInfo"
BeforeTargets="GetAssemblyAttributes"
Condition=" '$(GenerateGitMetadata)' == 'true' ">
<Exec Command="git rev-parse HEAD" ConsoleToMSBuild="true" StandardOutputImportance="low" IgnoreExitCode="true" Condition=" '$(CommitHash)' == '' ">
<Output TaskParameter="ConsoleOutput" PropertyName="CommitHash" />
Expand All @@ -13,18 +13,9 @@
<Output TaskParameter="ConsoleOutput" PropertyName="CommitBranch" />
</Exec>
<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>BuildTimestamp</_Parameter1>
<_Parameter2>$([System.DateTime]::UtcNow.ToString(yyyy-MM-ddTHH:mm:ssK))</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition=" $(CommitHash) != '' ">
<_Parameter1>CommitHash</_Parameter1>
<_Parameter2>$(CommitHash)</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition=" $(CommitBranch) != '' ">
<_Parameter1>CommitBranch</_Parameter1>
<_Parameter2>$(CommitBranch)</_Parameter2>
</AssemblyAttribute>
<AssemblyMetadata Include="BuildTimestamp" Value="$([System.DateTime]::UtcNow.ToString(yyyy-MM-ddTHH:mm:ssK))" />
<AssemblyMetadata Include="CommitHash" Value="$(CommitHash)" Condition=" $(CommitHash) != '' " />
<AssemblyMetadata Include="CommitBranch" Value="$(CommitBranch)" Condition=" $(CommitBranch) != '' " />
</ItemGroup>
</Target>
<PropertyGroup Condition=" '$(CollectCoverage)' == 'true' ">
Expand Down

0 comments on commit 1fbb701

Please sign in to comment.