Directory.Build.targets 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <Project>
  2. <PropertyGroup>
  3. <!-- When OnlyPackPlatformSpecificPackages is set, only produce packages for projects which set RuntimeIdentifier. -->
  4. <IsPackable Condition=" '$(OnlyPackPlatformSpecificPackages)' == 'true' AND '$(IsPackable)' != 'false' AND '$(RuntimeIdentifier)' == '' ">false</IsPackable>
  5. <!--
  6. By default, assemblies which are only in the Microsoft.AspNetCore.App shared framework are not available as NuGet packages.
  7. -->
  8. <IsPackable Condition="'$(IsAspNetCoreApp)' == 'true' AND '$(IsShippingPackage)' != 'true'">false</IsPackable>
  9. <!-- Only build assemblies in Microsoft.AspNetCore.App in source build -->
  10. <!-- Analyzer package are needed in source build for WebSDK -->
  11. <ExcludeFromSourceBuild Condition="'$(ExcludeFromSourceBuild)' == '' and '$(DotNetBuildFromSource)' == 'true' and '$(IsAspNetCoreApp)' != 'true' and '$(IsAnalyzersProject)' != 'true'">true</ExcludeFromSourceBuild>
  12. </PropertyGroup>
  13. <PropertyGroup Label="Resx settings">
  14. <GenerateResxSource Condition="$(GenerateResxSource) == ''">true</GenerateResxSource>
  15. <GenerateResxSourceEmitFormatMethods Condition="$(GenerateResxSourceEmitFormatMethods) == ''">true</GenerateResxSourceEmitFormatMethods>
  16. </PropertyGroup>
  17. <Import Project="Sdk.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />
  18. <!-- Properties which should be set after the project has been evaluated -->
  19. <PropertyGroup Label="Versioning settings">
  20. <!-- 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" -->
  21. <BrandingVersionSuffix />
  22. <BrandingVersionSuffix Condition="$(IncludePreReleaseLabelInPackageVersion)">$(PreReleaseBrandingLabel) Build $(VersionSuffix)</BrandingVersionSuffix>
  23. <PackageBrandingVersion>$(VersionPrefix)</PackageBrandingVersion>
  24. <PackageBrandingVersion Condition=" '$(VersionSuffix)' != '' ">$(PackageBrandingVersion) $(BrandingVersionSuffix.Trim())</PackageBrandingVersion>
  25. <SiteExtensionSuffix>$(VersionSuffix.Replace('.','-'))</SiteExtensionSuffix>
  26. <SiteExtensionPackageVersion>$(VersionPrefix)-$(SiteExtensionSuffix)</SiteExtensionPackageVersion>
  27. <OriginalPackageVersion>$(Version)</OriginalPackageVersion>
  28. <PackageVersion Condition=" '$(PackageVersion)' == '' ">$(Version)</PackageVersion>
  29. <PackageVersion Condition=" '$(NoSemVer20)' == 'true' ">$(SiteExtensionPackageVersion)</PackageVersion>
  30. <SharedFxVersion>$(PackageVersion)</SharedFxVersion>
  31. <TargetingPackVersion>$(TargetingPackVersionPrefix)</TargetingPackVersion>
  32. <TargetingPackVersion Condition=" '$(VersionSuffix)' != '' ">$(TargetingPackVersionPrefix)-$(VersionSuffix)</TargetingPackVersion>
  33. <SharedFxProductName>$(Product) $(PackageVersion) Shared Framework</SharedFxProductName>
  34. </PropertyGroup>
  35. <PropertyGroup>
  36. <!-- 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. -->
  37. <SuppressDependenciesWhenPacking Condition="'$(SuppressDependenciesWhenPacking)' == '' AND '$(IsAnalyzersProject)' == 'true'">true</SuppressDependenciesWhenPacking>
  38. </PropertyGroup>
  39. <PropertyGroup Condition="'$(PackAsTool)' == 'true' AND '$(IsShippingPackage)' == 'true'">
  40. <!-- This is a requirement for Microsoft tool packages only. -->
  41. <PackAsToolShimRuntimeIdentifiers>win-x64;win-x86</PackAsToolShimRuntimeIdentifiers>
  42. </PropertyGroup>
  43. <PropertyGroup Condition=" '$(MSBuildProjectExtension)' == '.csproj' ">
  44. <PackageId Condition=" '$(PackageId)' == '' ">$(AssemblyName)</PackageId>
  45. <IsPackable Condition="'$(IsPackable)' == '' AND ( '$(IsTestProject)' == 'true' OR '$(IsTestAssetProject)' == 'true' OR '$(IsBenchmarkProject)' == 'true' OR '$(IsSampleProject)' == 'true' OR '$(IsReferenceAssemblyProject)' == 'true' ) ">false</IsPackable>
  46. </PropertyGroup>
  47. <Import Project="eng\Baseline.Designer.props" />
  48. <PropertyGroup Condition=" '$(IsPackable)' != 'false' AND '$(AspNetCorePatchVersion)' != '0' ">
  49. <IsPackageInThisPatch Condition="'$(IsPackageInThisPatch)' == ''">$(PackagesInPatch.Contains(' $(PackageId);'))</IsPackageInThisPatch>
  50. </PropertyGroup>
  51. <PropertyGroup Condition=" '$(IsPackable)' != 'false' AND '$(IsServicingBuild)' == 'true' ">
  52. <!-- Used to distinguish between packages building -->
  53. <IsPackableInNonServicingBuild>true</IsPackableInNonServicingBuild>
  54. <!-- Suppress creation of .nupkg for servicing builds. -->
  55. <IsPackable Condition=" '$(IsPackageInThisPatch)' != 'true' ">false</IsPackable>
  56. </PropertyGroup>
  57. <PropertyGroup Condition=" '$(IsPackageInThisPatch)' != 'true' AND '$(BaselinePackageVersion)' != '' AND '$(IsServicingBuild)' == 'true' ">
  58. <!-- 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. -->
  59. <AssemblyVersion Condition="$(BaselinePackageVersion.Contains('-'))">$(BaselinePackageVersion.Substring(0, $(BaselinePackageVersion.IndexOf('-')))).0</AssemblyVersion>
  60. <AssemblyVersion Condition="! $(BaselinePackageVersion.Contains('-'))">$(BaselinePackageVersion).0</AssemblyVersion>
  61. <!--
  62. Ideally, we would also set the project version to match the baseline in case NuGet turns a ProjectReference into a nuspec depenendency, but
  63. NuGet does not currently handle conflicts between packages and projects which have the same package id/version.
  64. See https://github.com/NuGet/Home/issues/6795.
  65. 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.
  66. -->
  67. <Version Condition="'$(NoBuild)' == 'true' AND '$(DesignTimeBuild)' == 'true'">$(BaselinePackageVersion)</Version>
  68. <PackageVersion Condition="'$(NoBuild)' == 'true' AND '$(DesignTimeBuild)' == 'true'">$(BaselinePackageVersion)</PackageVersion>
  69. </PropertyGroup>
  70. <PropertyGroup>
  71. <!-- Implementation projects are the projects which produce nuget packages or shipping assemblies. -->
  72. <IsImplementationProject Condition=" '$(IsImplementationProject)' == '' AND '$(IsAnalyzersProject)' != 'true' AND '$(IsTestAssetProject)' != 'true' AND '$(IsTestProject)' != 'true' AND '$(IsBenchmarkProject)' != 'true' AND '$(IsSampleProject)' != 'true' AND '$(IsReferenceAssemblyProject)' != 'true' ">true</IsImplementationProject>
  73. <!-- This determines whether a project is available as a <Reference> to other projects in this repo. -->
  74. <IsProjectReferenceProvider Condition=" '$(IsProjectReferenceProvider)' == '' AND '$(IsImplementationProject)' == 'true' AND '$(PackAsTool)' != 'true' ">true</IsProjectReferenceProvider>
  75. <HasReferenceAssembly Condition="'$(HasReferenceAssembly)' == '' AND '$(IsProjectReferenceProvider)' == 'true'">true</HasReferenceAssembly>
  76. <HasReferenceAssembly Condition="'$(HasReferenceAssembly)' == ''">false</HasReferenceAssembly>
  77. <IsPackable Condition="'$(IsPackable)' == '' AND ('$(IsImplementationProject)' == 'true' OR '$(IsAnalyzersProject)' == 'true') ">true</IsPackable>
  78. <IsPackable Condition="'$(IsPackable)' == '' ">false</IsPackable>
  79. <BuildHelixPayload Condition="'$(BuildHelixPayload)' == '' AND '$(IsTestProject)' == 'true'">true</BuildHelixPayload>
  80. </PropertyGroup>
  81. <ItemGroup Condition="'$(Language)' == 'C#' AND '$(IsReferenceAssemblyProject)' == 'true'">
  82. <Compile Include="$(SharedSourceRoot)ReferenceAssemblyInfo.cs" LinkBase="Properties" />
  83. </ItemGroup>
  84. <ItemGroup>
  85. <KnownFrameworkReference Update="Microsoft.NETCore.App">
  86. <!-- Always update the 'latest version', whether the repo is servicing or not. -->
  87. <LatestRuntimeFrameworkVersion Condition="'%(TargetFramework)' == '$(DefaultNetCoreTargetFramework)'">$(MicrosoftNETCoreAppRuntimeVersion)</LatestRuntimeFrameworkVersion>
  88. <!-- Only update the default runtime version for preview builds. -->
  89. <DefaultRuntimeFrameworkVersion Condition="'%(TargetFramework)' == '$(DefaultNetCoreTargetFramework)' and '$(IsServicingBuild)' != 'true'">$(MicrosoftNETCoreAppRuntimeVersion)</DefaultRuntimeFrameworkVersion>
  90. <!-- Only update the targeting pack version for preview builds. -->
  91. <TargetingPackVersion Condition="'%(TargetFramework)' == '$(DefaultNetCoreTargetFramework)' and '$(IsServicingBuild)' != 'true'">$(MicrosoftNETCoreAppRefPackageVersion)</TargetingPackVersion>
  92. </KnownFrameworkReference>
  93. <KnownFrameworkReference Condition="'$(UseAspNetCoreSharedRuntime)' != 'true'" Remove="Microsoft.AspNetCore.App" />
  94. <KnownFrameworkReference Remove="Microsoft.WindowsDesktop.App" />
  95. <KnownFrameworkReference Condition="'$(UseAspNetCoreSharedRuntime)' == 'true'" Update="Microsoft.AspNetCore.App">
  96. <LatestRuntimeFrameworkVersion>$(SharedFxVersion)</LatestRuntimeFrameworkVersion>
  97. <DefaultRuntimeFrameworkVersion Condition="'$(IsServicingBuild)' != 'true'">$(SharedFxVersion)</DefaultRuntimeFrameworkVersion>
  98. <TargetingPackVersion Condition="'$(IsServicingBuild)' != 'true'">$(SharedFxVersion)</TargetingPackVersion>
  99. </KnownFrameworkReference>
  100. <KnownFrameworkReference Update="NETStandard.Library">
  101. <TargetingPackVersion Condition="'%(TargetFramework)' == 'netstandard2.1' and '$(IsServicingBuild)' != 'true'">$(NETStandardLibraryRefPackageVersion)</TargetingPackVersion>
  102. </KnownFrameworkReference>
  103. <!-- Track compiler separately from Arcade.-->
  104. <PackageReference Include="Microsoft.Net.Compilers.Toolset"
  105. Version="$(MicrosoftNetCompilersToolsetPackageVersion)"
  106. PrivateAssets="all"
  107. IsImplicitlyDefined="true" />
  108. </ItemGroup>
  109. <PropertyGroup Condition=" '$(CopySymbolsToArtifacts)' == 'true' AND '$(TargetFramework)' != '' ">
  110. <BuildDependsOn>$(BuildDependsOn);_CopySymbolsToArtifacts</BuildDependsOn>
  111. </PropertyGroup>
  112. <Target Name="_CopySymbolsToArtifacts">
  113. <Copy SourceFiles="$([System.IO.Path]::ChangeExtension('$(TargetPath)', 'pdb'))"
  114. DestinationFolder="$(SymbolsOutputPath)$(TargetFramework)"
  115. OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
  116. Retries="$(CopyRetryCount)"
  117. RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
  118. SkipUnchangedFiles="$(SkipCopyUnchangedFiles)" />
  119. </Target>
  120. <Import Project="eng\Workarounds.targets" />
  121. <Import Project="eng\targets\ResolveIisReferences.targets" Condition=" '$(MSBuildProjectExtension)' != '.vcxproj' " />
  122. <Import Project="eng\targets\Cpp.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.vcxproj'" />
  123. <Import Project="eng\targets\CSharp.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.csproj'" />
  124. <Import Project="eng\targets\FSharp.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.fsproj'" />
  125. <Import Project="eng\targets\Wix.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.wixproj'" />
  126. <Import Project="eng\targets\Npm.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.npmproj'" />
  127. <Import Project="eng\targets\ReferenceAssembly.targets" Condition=" '$(HasReferenceAssembly)' == 'true' " />
  128. </Project>