Created
October 9, 2022 23:31
-
-
Save baronfel/27f3cb04d2a1cfc398a250bb74080be4 to your computer and use it in GitHub Desktop.
MSBuild target to write license expressions to an assembly attribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project> | |
<!-- Create a target that will assign the license information for a project to an attribute --> | |
<Target Name="AssignLicenseAttribute"> | |
<!-- Only do this if the user is allowing assemblyinfo generation --> | |
<ItemGroup Condition="'$(GenerateAssemblyInfo)' == 'true'"> | |
<!-- Only generate if the license is present and the user has requested this attribute --> | |
<AssemblyAttribute | |
Include="System.Reflection.AssemblyMetadataAttribute" | |
Condition="'$(GenerateLicenseExpressionAttribute)' == 'true' and '$(PackageLicenseExpression)' != ''"> | |
<_Parameter1>LicenseExpression</_Parameter1> | |
<_Parameter2>$(PackageLicenseExpression)</_Parameter2> | |
</AssemblyAttribute> | |
</ItemGroup> | |
</Target> | |
<PropertyGroup> | |
<!-- Default the attribute to 'on' but allow for user overrides --> | |
<GenerateLicenseExpressionAttribute Condition="'$(GenerateLicenseExpressionAttribute)' == ''">true</GenerateLicenseExpressionAttribute> | |
<!-- Tell the build to run our target before the build command (so we generate the attribute before compilation) --> | |
<PrepareForBuildDependsOn> | |
AssignLicenseAttribute; | |
$(PrepareForBuildDependsOn) | |
</PrepareForBuildDependsOn> | |
</PropertyGroup> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment