| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <Project>
- <!-- For 'legacy' .csproj files, set map TargetFrameworkVersion back to TargetFramework -->
- <PropertyGroup Condition=" '$(TargetFramework)' == '' AND '$(TargetFrameworks)' == '' ">
- <TargetFramework>net$(TargetFrameworkVersion.TrimStart('vV').Replace('.',''))</TargetFramework>
- <TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
- </PropertyGroup>
- <PropertyGroup>
- <!-- Ensure API changes show up clearly in PRs. -->
- <AddPublicApiAnalyzers Condition=" '$(AddPublicApiAnalyzers)' == '' AND
- '$(IsImplementationProject)' == 'true' AND
- ! $(RepoRelativeProjectDir.Contains('Tools')) ">true</AddPublicApiAnalyzers>
- <AddPublicApiAnalyzers Condition=" '$(AddPublicApiAnalyzers)' == '' ">false</AddPublicApiAnalyzers>
- <!-- Public members should not use oblivious types. Not done with all nullable annotations. -->
- <NoWarn>$(NoWarn);RS0041</NoWarn>
- <_IsSrcProject Condition="'$(IsImplementationProject)' == 'true' OR
- '$(IsAnalyzersProject)' == true OR
- '$(IsSpecificationTestProject)' == 'true'">true</_IsSrcProject>
- <Nullable Condition=" '$(Nullable)' == '' AND '$(_IsSrcProject)' == 'true'">enable</Nullable>
- <!-- Strip out non-public nullable annotations for src projects. This should help with size reduction -->
- <Features Condition="'$(_IsSrcProject)' == 'true'">$(Features);nullablePublicOnly</Features>
- <!-- Turn off platform compatibility analyzer warnings in test, test assets, and samples. -->
- <NoWarn Condition=" $(IsTestProject) OR
- '$(IsTestAssetProject)' == 'true' OR
- '$(ISBenchmarkProject)' == 'true' OR
- '$(IsSampleProject)' == 'true' OR
- '$(IsMicrobenchmarksProject)' == 'true'">$(NoWarn);CA1416</NoWarn>
- <!-- Turn off unused usings warning for multi-targeted projects. Fixing them using ifdefs looks worse than ignoring the warnings. -->
- <NoWarn Condition="'$(TargetFrameworks)' != ''">$(NoWarn);IDE0005</NoWarn>
- <!--
- Turn off ConfigureAwait analyzer rule in the projects that are exclusively meant to run in ASP.NET Core or Blazor contexts.
- Since we don't have a good way to detect this, we'll use the presence of ns2.0 as a proxy.
- -->
- <NoWarn Condition="'$(_IsSrcProject)' != 'true' OR !$(TargetFrameworks.Contains('netstandard'))">$(NoWarn);CA2007</NoWarn>
- <!-- Enable .NET code style analysis during build for src projects. -->
- <EnforceCodeStyleInBuild Condition="'$(EnforceCodeStyleInBuild)' == ''">true</EnforceCodeStyleInBuild>
- <!-- Enable trimming annotation validation in DI. See https://github.com/dotnet/runtime/blob/main/docs/workflow/trimming/feature-switches.md -->
- <VerifyDependencyInjectionOpenGenericServiceTrimmability Condition=" $(IsTestProject) ">true</VerifyDependencyInjectionOpenGenericServiceTrimmability>
- </PropertyGroup>
- <!-- Enable implicit usings for projects that target the default TFM -->
- <PropertyGroup Condition="'$(ImplicitUsings)' == '' AND '$(TargetFrameworks)' == '' AND '$(TargetFramework)' == '$(DefaultNetCoreTargetFramework)'">
- <ImplicitUsings>enable</ImplicitUsings>
- </PropertyGroup>
- <ItemGroup Condition="'$(ImplicitUsings)' == 'enable'">
- <!-- We should make it obvious when Linq is being used in shipping code -->
- <Using Remove="System.Linq" Condition="'$(_IsSrcProject)' == 'true'" />
- <!-- System.Net.Http types will frequently conflict with ASP.NET Core types-->
- <Using Remove="System.Net.Http" />
- <Using Include="Xunit" Condition=" $(IsTestProject) " />
- </ItemGroup>
- <ItemGroup Condition=" '$(DotNetBuildFromSource)' != 'true' AND $(AddPublicApiAnalyzers) ">
- <Reference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" ExcludeAssets="Compile" PrivateAssets="All" />
- </ItemGroup>
- <Target Name="_CheckIgnoredPublicApiFiles"
- BeforeTargets="Build;Restore"
- Condition=" Exists('$(MSBuildProjectDirectory)\PublicAPI.Shipped.txt') AND ! $(AddPublicApiAnalyzers) ">
- <Warning Text="Public API baseline files ignored." />
- </Target>
- <Target Name="_RemovePublicApiAnalyzer" BeforeTargets="RazorCoreCompile">
- <ItemGroup>
- <_PublicAPIAnalyzers Include="@(Analyzer->WithMetadataValue('NuGetPackageId','Microsoft.CodeAnalysis.PublicApiAnalyzers'))" />
- <Analyzer Remove="@(_PublicAPIAnalyzers)" />
- </ItemGroup>
- </Target>
- <Target Name="_RestorePublicApiAnalyzer" AfterTargets="RazorCoreCompile">
- <ItemGroup>
- <Analyzer Include="@(_PublicAPIAnalyzers)" />
- </ItemGroup>
- </Target>
- <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>
- <!-- Reference assemblies are shipped only in targeting packs. -->
- <Target Name="_RemoveReferenceAssembly" BeforeTargets="_GetPackageFiles;GenerateNuspec" Condition="$(HasReferenceAssembly)">
- <ItemGroup>
- <_PackageFilesToExclude Include="@(IntermediateRefAssembly);$(TargetRefPath)" />
- </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
- SuppressNullableAttributesImport to disable. Used when attributes are already present from another project because of InternalsVisibleTo.
- -->
- <When Condition=" ('$(Nullable)' == 'annotations' OR '$(Nullable)' == 'enable') AND
- '$(SuppressNullableAttributesImport)' != 'true' AND
- (('$(TargetFrameworkIdentifier)' == '.NETStandard' AND $([MSBuild]::VersionLessThanOrEquals('$(TargetFrameworkVersion)', '2.1'))) OR '$(TargetFrameworkIdentifier)' == '.NETFramework')">
- <PropertyGroup>
- <DefineConstants>$(DefineConstants),INTERNAL_NULLABLE_ATTRIBUTES</DefineConstants>
- <!-- Repo-specific property to enable nullability warnings for ns2.0 -->
- <NoWarn Condition=" '$(WarnOnNullable)' != 'true' ">$(NoWarn);nullable</NoWarn>
- </PropertyGroup>
- <ItemGroup>
- <Compile Include="$(SharedSourceRoot)Nullable\NullableAttributes.cs" />
- </ItemGroup>
- </When>
- </Choose>
- <Target Name="ValidateBenchmarks" BeforeTargets="Test" Condition="'$(IsMicrobenchmarksProject)' == 'true' AND '$(SkipMicrobenchmarksValidation)' != 'true'">
- <Message Text="%0ARunning benchmark validation for:%0A$(MSBuildProjectName)%0A"
- Importance="High" />
- <MSBuild Projects="$(MSBuildProjectFullPath)" Targets="GetTargetPath">
- <Output TaskParameter="TargetOutputs" PropertyName="ExecPath" />
- </MSBuild>
- <Exec Command="dotnet $(ExecPath) -f * --validate-fast" IgnoreStandardErrorWarningFormat="true" StandardOutputImportance="low" />
- </Target>
- <Import Project="Packaging.targets" />
- <Import Project="ResolveReferences.targets" />
- </Project>
|