aspnetcore/eng/targets/CSharp.Common.targets

52 lines
2.4 KiB
XML

<Project>
<!-- For 'legacy' .csproj files, set map TargetFrameworkVersion back to TargetFramework -->
<PropertyGroup Condition=" '$(TargetFramework)' == '' AND '$(TargetFrameworks)' == '' ">
<TargetFramework>net$(TargetFrameworkVersion.Substring(1).Replace('.',''))</TargetFramework>
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
</PropertyGroup>
<Target Name="GetCustomAssemblyAttributes"
BeforeTargets="GetAssemblyAttributes"
DependsOnTargets="InitializeSourceControlInformation">
<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(SourceRevisionId)' != ''">
<_Parameter1>CommitHash</_Parameter1>
<_Parameter2>$(SourceRevisionId)</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="$(RepositoryUrl.StartsWith('https://github.com'))">
<_Parameter1>SourceCommitUrl</_Parameter1>
<_Parameter2>$(RepositoryUrl)/tree/$(SourceRevisionId)</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(Serviceable)' == 'true'">
<_Parameter1>Serviceable</_Parameter1>
<_Parameter2>True</_Parameter2>
</AssemblyAttribute>
</ItemGroup>
</Target>
<Choose>
<!--
C# 8.0's nullable annotations only work for .NET Core 3.0+ by default. However it can be made to work for other target frameworks
by compiling the annotations (as internal types).
The code block that follows sets it up so projects in this repo that target ns2.0 or netfx can compile when Nullable is configured.
Based on https://github.com/dotnet/runtime/blob/93b6c449d4f31ddd7d573d1d3769e681d5ebceb9/src/libraries/Directory.Build.targets#L215-L222
-->
<When Condition="'$(Nullable)' != '' AND ('$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFrameworkIdentifier)' == '.NETFramework')">
<PropertyGroup>
<DefineConstants>$(DefineConstants),INTERNAL_NULLABLE_ATTRIBUTES</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(SharedSourceRoot)Nullable\NullableAttributes.cs" />
</ItemGroup>
</When>
</Choose>
<Import Project="Packaging.targets" />
<Import Project="ResolveReferences.targets" />
</Project>