Directory.Build.targets 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <Project>
  2. <PropertyGroup>
  3. <!-- Disable IsTrimmable on non-DefaultNetCoreTargetFrameworks even if explicitly enabled or else we'll get NETSDK1195 and NETSDK1210 errors -->
  4. <IsTrimmable Condition="'$(TargetFramework)' != '$(DefaultNetCoreTargetFramework)'"></IsTrimmable>
  5. <EnableAOTAnalyzer Condition=" '$(EnableAOTAnalyzer)' == '' ">$([MSBuild]::ValueOrDefault($(IsTrimmable),'false'))</EnableAOTAnalyzer>
  6. <!-- TODO: Remove when analyzer is enabled by default with AOT in SDK. See https://github.com/dotnet/sdk/issues/31284 -->
  7. <EnableSingleFileAnalyzer Condition=" '$(EnableSingleFileAnalyzer)' == '' ">$(EnableAOTAnalyzer)</EnableSingleFileAnalyzer>
  8. </PropertyGroup>
  9. <PropertyGroup>
  10. <!-- Ignore API doc requirements for test assets -->
  11. <NoWarn Condition="'$(IsTestAssetProject)' == 'true' or '$(IsSampleProject)' == 'true' or '$(IsBenchmarkProject)' == 'true' or
  12. '$(IsMicrobenchmarksProject)' == 'true'">$(NoWarn);CS1591</NoWarn>
  13. </PropertyGroup>
  14. <PropertyGroup Label="Resx settings">
  15. <GenerateResxSource Condition="'$(GenerateResxSource)' == ''">true</GenerateResxSource>
  16. <GenerateResxSourceEmitFormatMethods Condition="'$(GenerateResxSourceEmitFormatMethods)' == ''">true</GenerateResxSourceEmitFormatMethods>
  17. </PropertyGroup>
  18. <Import Project="Sdk.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />
  19. <!-- Properties which should be set after the project has been evaluated -->
  20. <PropertyGroup Label="Versioning settings">
  21. <!-- The 'human friendly' version to display in installers. In pre-release builds, this might be "2.0.7 Preview 2 Build 12356". In final builds, it should be "2.0.7" -->
  22. <BrandingVersionSuffix>$(PreReleaseBrandingLabel) Build $(VersionSuffix)</BrandingVersionSuffix>
  23. <PackageBrandingVersion>$(VersionPrefix)</PackageBrandingVersion>
  24. <PackageBrandingVersion Condition=" '$(VersionSuffix)' != '' ">$(PackageBrandingVersion) $(BrandingVersionSuffix.Trim())</PackageBrandingVersion>
  25. <SiteExtensionVersion>$(VersionPrefix)</SiteExtensionVersion>
  26. <SiteExtensionVersion Condition=" '$(VersionSuffix)' != '' ">$(VersionPrefix)-$(VersionSuffix.Replace('.','-'))</SiteExtensionVersion>
  27. <PackageVersion Condition=" '$(PackageVersion)' == '' ">$(Version)</PackageVersion>
  28. <SharedFxVersion>$(PackageVersion)</SharedFxVersion>
  29. <SharedFxVersion Condition=" '$(StabilizePackageVersion)' == 'true' ">$(VersionPrefix)</SharedFxVersion>
  30. <SharedFxProductName>$(Product) $(SharedFxVersion) Shared Framework</SharedFxProductName>
  31. <TargetingPackVersion>$(SharedFxVersion)</TargetingPackVersion>
  32. <PackageVersion Condition=" '$(NoSemVer20)' == 'true' ">$(SiteExtensionVersion)</PackageVersion>
  33. </PropertyGroup>
  34. <PropertyGroup>
  35. <!-- Analyzers package are special. In general, they should not have dependencies in the nuspec. Analyzer assemblies are not meant to be used for compilation or runtime. -->
  36. <SuppressDependenciesWhenPacking Condition="'$(SuppressDependenciesWhenPacking)' == '' AND '$(IsAnalyzersProject)' == 'true'">true</SuppressDependenciesWhenPacking>
  37. </PropertyGroup>
  38. <PropertyGroup Condition=" '$(MSBuildProjectExtension)' == '.csproj' ">
  39. <PackageId Condition=" '$(PackageId)' == '' ">$(AssemblyName)</PackageId>
  40. <IsPackable
  41. Condition="'$(IsPackable)' == '' AND ( $(IsTestProject) OR '$(IsTestAssetProject)' == 'true' OR
  42. '$(IsBenchmarkProject)' == 'true' OR '$(IsSampleProject)' == 'true' OR '$(IsMicrobenchmarksProject)' == 'true') ">false</IsPackable>
  43. </PropertyGroup>
  44. <Import Project="eng\Baseline.Designer.props" />
  45. <PropertyGroup Condition=" '$(IsPackable)' != 'false' AND '$(IsServicingBuild)' == 'true' ">
  46. <IsPackageInThisPatch Condition="'$(IsPackageInThisPatch)' == ''">true</IsPackageInThisPatch>
  47. <!-- Used to distinguish between packages building -->
  48. <IsPackableInNonServicingBuild>true</IsPackableInNonServicingBuild>
  49. <!-- Suppress creation of .nupkg for servicing builds of non-shipping projects. -->
  50. <IsPackable Condition=" '$(IsPackageInThisPatch)' != 'true' ">false</IsPackable>
  51. </PropertyGroup>
  52. <PropertyGroup>
  53. <!-- When OnlyPackPlatformSpecificPackages is set, only produce packages for projects which set RuntimeIdentifier. -->
  54. <!-- Keep this below where we set "IsPackageInThisPatch" -->
  55. <IsPackable Condition=" '$(OnlyPackPlatformSpecificPackages)' == 'true' AND '$(RuntimeIdentifier)' == '' ">false</IsPackable>
  56. </PropertyGroup>
  57. <PropertyGroup>
  58. <PackageVersionForPackageVersionInfo>$(PackageVersion)</PackageVersionForPackageVersionInfo>
  59. </PropertyGroup>
  60. <PropertyGroup Condition=" '$(IsPackageInThisPatch)' != 'true' AND '$(BaselinePackageVersion)' != '' AND '$(IsServicingBuild)' == 'true' ">
  61. <!-- This keeps assembly and package versions consistent across patches. If a package is not included in a patch, its version should stay at the baseline. -->
  62. <AssemblyVersion Condition="$(BaselinePackageVersion.Contains('-'))">$(BaselinePackageVersion.Substring(0, $(BaselinePackageVersion.IndexOf('-')))).0</AssemblyVersion>
  63. <AssemblyVersion Condition="! $(BaselinePackageVersion.Contains('-'))">$(BaselinePackageVersion).0</AssemblyVersion>
  64. <!--
  65. Ideally, we would also set the project version to match the baseline in case NuGet turns a ProjectReference into a nuspec depenendency, but
  66. NuGet does not currently handle conflicts between packages and projects which have the same package id/version.
  67. See https://github.com/NuGet/Home/issues/6795.
  68. Because we still use static analysis to scrape versions, only set this during static analysis, which can be detected by checking for both NoBuild and DesignTimeBuild.
  69. -->
  70. <Version Condition="'$(NoBuild)' == 'true' AND '$(DesignTimeBuild)' == 'true'">$(BaselinePackageVersion)</Version>
  71. <PackageVersion Condition="'$(NoBuild)' == 'true' AND '$(DesignTimeBuild)' == 'true'">$(BaselinePackageVersion)</PackageVersion>
  72. <!-- For servicing builds, we want to resolve baseline versions of project packages that aren't building, always -->
  73. <PackageVersionForPackageVersionInfo>$(BaselinePackageVersion)</PackageVersionForPackageVersionInfo>
  74. </PropertyGroup>
  75. <PropertyGroup>
  76. <!-- Implementation projects are the projects which produce nuget packages or shipping assemblies. -->
  77. <IsImplementationProject Condition=" '$(IsImplementationProject)' == '' AND
  78. '$(IsAnalyzersProject)' != 'true' AND
  79. '$(IsBenchmarkProject)' != 'true' AND
  80. '$(IsSampleProject)' != 'true' AND
  81. '$(IsSpecificationTestProject)' != 'true' AND
  82. '$(IsTestAssetProject)' != 'true' AND
  83. !$(IsTestProject) AND
  84. '$(IsMicrobenchmarksProject)' != 'true' ">true</IsImplementationProject>
  85. <!-- This determines whether a project is available as a <Reference> to other projects in this repo. -->
  86. <IsProjectReferenceProvider Condition=" '$(IsProjectReferenceProvider)' == '' AND
  87. ( '$(IsImplementationProject)' == 'true' OR '$(IsSpecificationTestProject)' == 'true' ) ">true</IsProjectReferenceProvider>
  88. <HasReferenceAssembly
  89. Condition=" '$(TargetFramework)' == '$(DefaultNetCoreTargetFramework)' AND '$(IsAspNetCoreApp)' == 'true' ">true</HasReferenceAssembly>
  90. <HasReferenceAssembly Condition="'$(HasReferenceAssembly)' == ''">false</HasReferenceAssembly>
  91. <ProduceReferenceAssembly>$(HasReferenceAssembly)</ProduceReferenceAssembly>
  92. <!-- Duplicate setting from Microsoft.Common.CurrentVersion.targets because this is imported after that file. -->
  93. <TargetRefPath
  94. Condition=" '$(TargetRefPath)' == '' and $(ProduceReferenceAssembly) ">$([MSBuild]::NormalizePath($(TargetDir), 'ref', $(TargetFileName)))</TargetRefPath>
  95. <IsPackable Condition="'$(IsPackable)' == '' AND ('$(IsImplementationProject)' == 'true' OR '$(IsAnalyzersProject)' == 'true') ">true</IsPackable>
  96. <IsPackable Condition="'$(IsPackable)' == '' ">false</IsPackable>
  97. <BuildHelixPayload Condition="'$(BuildHelixPayload)' == '' AND $(IsTestProject) ">true</BuildHelixPayload>
  98. <SkipTests Condition="'$(SkipHelixReadyTests)' == 'true' AND '$(BuildHelixPayload)' == 'true'">true</SkipTests>
  99. </PropertyGroup>
  100. <PropertyGroup>
  101. <PackageThirdPartyNoticesFile Condition="'$(PackageThirdPartyNoticesFile)' == ''">$(RepoRoot)THIRD-PARTY-NOTICES.TXT</PackageThirdPartyNoticesFile>
  102. </PropertyGroup>
  103. <ItemGroup Condition="'$(IsPackable)' == 'true'">
  104. <None Include="$(PackageThirdPartyNoticesFile)" Pack="true" PackagePath="." />
  105. </ItemGroup>
  106. <!--
  107. If assembly is in shared framework and not net4*, assembly version should remain fixed for an entire
  108. major.minor release even in servicing.
  109. -->
  110. <PropertyGroup Condition=" '$(IsAspNetCoreApp)' == 'true' AND
  111. '$(Language)' == 'C#' AND
  112. '$(TargetFrameworkIdentifier)' != '.NETFramework' ">
  113. <AssemblyVersion>$(AspNetCoreMajorMinorVersion).0.0</AssemblyVersion>
  114. </PropertyGroup>
  115. <PropertyGroup>
  116. <!-- Do not update the Microsoft.AspNetCore.App KnownFrameworkReference item unless requested. -->
  117. <UpdateAspNetCoreKnownFramework>false</UpdateAspNetCoreKnownFramework>
  118. <UpdateAspNetCoreKnownFramework Condition=" '$(UseAspNetCoreSharedRuntime)' == 'true' AND
  119. '$(DoNotApplyWorkaroundsToMicrosoftAspNetCoreApp)' != 'true' ">true</UpdateAspNetCoreKnownFramework>
  120. </PropertyGroup>
  121. <ItemGroup>
  122. <KnownFrameworkReference Condition="'$(UseAspNetCoreSharedRuntime)' != 'true'" Remove="Microsoft.AspNetCore.App" />
  123. <KnownFrameworkReference Remove="Microsoft.WindowsDesktop.App" />
  124. </ItemGroup>
  125. <PropertyGroup Condition=" '$(CopySymbolsToArtifacts)' == 'true' AND '$(TargetFramework)' != '' ">
  126. <BuildDependsOn>$(BuildDependsOn);_CopySymbolsToArtifacts</BuildDependsOn>
  127. </PropertyGroup>
  128. <!-- Properties for Package Validation -->
  129. <PropertyGroup Condition="'$(ExcludeFromSourceOnlyBuild)' != 'true'">
  130. <EnablePackageValidation Condition="'$(EnablePackageValidation)' == ''">true</EnablePackageValidation>
  131. <DisablePackageBaselineValidation Condition="'$(IsServicingBuild)' != 'true'">true</DisablePackageBaselineValidation>
  132. <GenerateCompatibilitySuppressionFile>true</GenerateCompatibilitySuppressionFile>
  133. </PropertyGroup>
  134. <Target Name="_CopySymbolsToArtifacts">
  135. <Copy SourceFiles="$([System.IO.Path]::ChangeExtension('$(TargetPath)', 'pdb'))"
  136. DestinationFolder="$(SymbolsOutputPath)$(TargetFramework)"
  137. OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
  138. Retries="$(CopyRetryCount)"
  139. RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
  140. SkipUnchangedFiles="$(SkipCopyUnchangedFiles)" />
  141. </Target>
  142. <Import Project="eng\Workarounds.targets" />
  143. <Import Project="artifacts\bin\GenerateFiles\Directory.Build.targets" Condition=" '$(MSBuildProjectName)' != 'GenerateFiles' " />
  144. <Import Project="eng\targets\ResolveIisReferences.targets" Condition=" '$(MSBuildProjectExtension)' != '.vcxproj' " />
  145. <Import Project="eng\targets\Cpp.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.vcxproj'" />
  146. <Import Project="eng\targets\CSharp.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.csproj'" />
  147. <Import Project="eng\targets\FSharp.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.fsproj'" />
  148. <Import Project="eng\targets\Wix.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.wixproj'" />
  149. <Import Project="eng\targets\Java.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.javaproj'" />
  150. <Import Project="eng\testing\linker\trimmingTests.targets" Condition="'$(IsPublishedAppTestProject)' == 'true'" />
  151. <Import Project="eng\targets\Helix.targets" Condition=" $(IsTestProject) " />
  152. <Import Project="eng\targets\FunctionalTestWithAssets.targets"
  153. Condition=" $(IsTestProject) AND $(ContainsFunctionalTestAssets) " />
  154. </Project>