Directory.Build.targets 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <Project>
  2. <!-- Properties which should be set after the project has been evaluated -->
  3. <PropertyGroup>
  4. <!--
  5. By default, all projects which produce packages are not intended to ship to NuGet.org as a product package.
  6. Packages which are intended to ship to NuGet.org must opt-in by setting this to true in the project file.
  7. -->
  8. <IsShippingPackage Condition=" '$(IsShippingPackage)' == '' ">false</IsShippingPackage>
  9. <PackageOutputPath Condition=" '$(IsShippingPackage)' == 'true' ">$(ArtifactsShippingPackagesDir)</PackageOutputPath>
  10. <PackageOutputPath Condition=" '$(IsShippingPackage)' != 'true' ">$(ArtifactsNonShippingPackagesDir)</PackageOutputPath>
  11. <!-- 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. -->
  12. <SuppressDependenciesWhenPacking Condition="'$(SuppressDependenciesWhenPacking)' == '' AND '$(IsAnalyzersProject)' == 'true'">true</SuppressDependenciesWhenPacking>
  13. </PropertyGroup>
  14. <PropertyGroup Condition=" '$(MSBuildProjectExtension)' == '.csproj' ">
  15. <PackageId Condition=" '$(PackageId)' == '' ">$(AssemblyName)</PackageId>
  16. <IsPackable Condition="'$(IsPackable)' == '' AND ( '$(IsTestProject)' == 'true' OR '$(IsTestAssetProject)' == 'true' OR '$(IsBenchmarkProject)' == 'true' OR '$(IsSampleProject)' == 'true' ) ">false</IsPackable>
  17. </PropertyGroup>
  18. <Import Project="eng\Baseline.Designer.props" />
  19. <PropertyGroup Condition=" '$(IsPackable)' != 'false' AND '$(AspNetCorePatchVersion)' != '0' ">
  20. <IsPackageInThisPatch Condition="'$(IsPackageInThisPatch)' == ''">$(PackagesInPatch.Contains(' $(PackageId);'))</IsPackageInThisPatch>
  21. </PropertyGroup>
  22. <PropertyGroup Condition=" '$(IsPackable)' != 'false' AND '$(IsServicingBuild)' == 'true' ">
  23. <!-- Used to distinguish between packages building -->
  24. <IsPackableInNonServicingBuild>true</IsPackableInNonServicingBuild>
  25. <!-- Suppress creation of .nupkg for servicing builds. -->
  26. <IsPackable Condition=" '$(IsPackageInThisPatch)' != 'true' ">false</IsPackable>
  27. </PropertyGroup>
  28. <PropertyGroup Condition=" '$(IsPackageInThisPatch)' != 'true' AND '$(BaselinePackageVersion)' != '' AND '$(IsServicingBuild)' == 'true' ">
  29. <!-- 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. -->
  30. <AssemblyVersion Condition="$(BaselinePackageVersion.Contains('-'))">$(BaselinePackageVersion.Substring(0, $(BaselinePackageVersion.IndexOf('-')))).0</AssemblyVersion>
  31. <AssemblyVersion Condition="! $(BaselinePackageVersion.Contains('-'))">$(BaselinePackageVersion).0</AssemblyVersion>
  32. <!--
  33. Ideally, we would also set the project version to match the baseline in case NuGet turns a ProjectReference into a nuspec depenendency, but
  34. NuGet does not currently handle conflicts between packages and projects which have the same package id/version.
  35. See https://github.com/NuGet/Home/issues/6795.
  36. 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.
  37. -->
  38. <Version Condition="'$(NoBuild)' == 'true' AND '$(DesignTimeBuild)' == 'true'">$(BaselinePackageVersion)</Version>
  39. <PackageVersion Condition="'$(NoBuild)' == 'true' AND '$(DesignTimeBuild)' == 'true'">$(BaselinePackageVersion)</PackageVersion>
  40. </PropertyGroup>
  41. <PropertyGroup>
  42. <!-- Implementation projects are the projects which produce nuget packages or shipping assemblies. -->
  43. <IsImplementationProject Condition=" '$(IsImplementationProject)' == '' AND '$(IsAnalyzersProject)' != 'true' AND '$(IsTestAssetProject)' != 'true' AND '$(IsTestProject)' != 'true' AND '$(IsBenchmarkProject)' != 'true' AND '$(IsSampleProject)' != 'true' ">true</IsImplementationProject>
  44. <!-- This determines whether a project is available as a <Reference> to other projects in this repo. -->
  45. <IsProjectReferenceProvider Condition=" '$(IsProjectReferenceProvider)' == '' AND '$(IsImplementationProject)' == 'true' AND '$(PackAsTool)' != 'true' ">true</IsProjectReferenceProvider>
  46. <!-- Suppress KoreBuild warnings about the mismatch of repo version and local project version. The versioning in this mega repo is sufficiently complicated that KoreBuild's validation isn't helpful. -->
  47. <VerifyVersion>false</VerifyVersion>
  48. <EnableApiCheck Condition=" '$(EnableApiCheck)' != '' ">$(IsImplementationProject)</EnableApiCheck>
  49. <IsPackable Condition="'$(IsPackable)' == '' AND ('$(IsImplementationProject)' == 'true' OR '$(IsAnalyzersProject)' == 'true') ">true</IsPackable>
  50. <IsPackable Condition="'$(IsPackable)' == '' ">false</IsPackable>
  51. <RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp3.0' ">$(MicrosoftNETCoreAppPackageVersion)</RuntimeFrameworkVersion>
  52. <BuildHelixPayload Condition="'$(BuildHelixPayload)' == '' AND '$(IsTestProject)' == 'true'">true</BuildHelixPayload>
  53. </PropertyGroup>
  54. <Import Project="eng\Workarounds.targets" />
  55. <Import Project="eng\targets\ResolveIisReferences.targets" Condition=" '$(MSBuildProjectExtension)' != '.vcxproj' " />
  56. <Import Project="eng\targets\Cpp.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.vcxproj'" />
  57. <Import Project="eng\targets\CSharp.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.csproj'" />
  58. <Import Project="eng\targets\FSharp.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.fsproj'" />
  59. <Import Project="eng\targets\Wix.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.wixproj'" />
  60. <Import Project="eng\targets\Npm.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.npmproj'" />
  61. <!-- Move to CSharp.Common.props -->
  62. <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' AND '$(IsHelixJob)' == 'true' ">
  63. <PackageReference Include="xunit.runner.console" Version="2.4.1" />
  64. </ItemGroup>
  65. <!-- Prepares the test projects for helix by including xunit and publishing -->
  66. <Target Name="PrepareHelixPayload" Returns="@(HelixDirectory)">
  67. <ItemGroup>
  68. <_TargetFrameworks Remove="@(_TargetFrameworks)" />
  69. <_TargetFrameworks Include="$(TargetFrameworks);$(TargetFramework)" />
  70. </ItemGroup>
  71. <MSBuild Projects="$(MSBuildProjectFullPath)"
  72. Targets="_PrepareHelixPayloadInner"
  73. Properties="TargetFramework=%(_TargetFrameworks.Identity);IsWindowsHelixQueue=$(HelixTargetQueue.Contains('Windows'))">
  74. <Output TaskParameter="TargetOutputs" ItemName="HelixDirectory" />
  75. </MSBuild>
  76. </Target>
  77. <Target Name="_PrepareHelixPayloadInner"
  78. DependsOnTargets="Publish"
  79. Condition="'$(BuildHelixPayload)' == 'true'"
  80. Returns="@(HelixDirectory)">
  81. <ItemGroup>
  82. <HelixDirectory Include="$(MSBuildProjectFullPath)" />
  83. </ItemGroup>
  84. </Target>
  85. <!-- Build the actual helix work items to send to helix queues -->
  86. <Target Name="CreateHelixPayload" Returns="@(HelixPayload)">
  87. <ItemGroup>
  88. <_TargetFrameworks Remove="@(_TargetFrameworks)" />
  89. <_TargetFrameworks Include="$(TargetFrameworks);$(TargetFramework)" />
  90. </ItemGroup>
  91. <MSBuild Projects="$(MSBuildProjectFullPath)"
  92. Targets="_CreateHelixPayloadInner"
  93. Properties="TargetFramework=%(_TargetFrameworks.Identity);IsWindowsHelixQueue=$(HelixTargetQueue.Contains('Windows'))">
  94. <Output TaskParameter="TargetOutputs" ItemName="HelixPayload" />
  95. </MSBuild>
  96. </Target>
  97. <Target Name="CollectXunitConsoleRunner" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
  98. <PropertyGroup>
  99. <XunitConsoleRunnerDir>$([System.IO.Path]::GetDirectoryName($(XunitConsole472Path)))</XunitConsoleRunnerDir>
  100. </PropertyGroup>
  101. <ItemGroup>
  102. <XunitConsoleRunnerFiles Include="$(XunitConsoleRunnerDir)/**/*" />
  103. </ItemGroup>
  104. <Copy SourceFiles="@(XunitConsoleRunnerFiles)" DestinationFolder="$(PublishDir)" />
  105. </Target>
  106. <Target Name="_CreateHelixPayloadInner"
  107. DependsOnTargets="CollectXunitConsoleRunner"
  108. Condition="($(IsWindowsHelixQueue) OR '$(TargetFrameworkIdentifier)' != '.NETFramework')"
  109. Returns="@(HelixPayload)">
  110. <ConvertToAbsolutePath Paths="$(PublishDir)">
  111. <Output TaskParameter="AbsolutePaths" PropertyName="PublishAbsoluteDir" />
  112. </ConvertToAbsolutePath>
  113. <!-- Windows NetCore -->
  114. <ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework' AND $(IsWindowsHelixQueue)" >
  115. <_CopyItems Include="$(MSBuildThisFileDirectory)eng\helix\vstest\runtests.cmd" />
  116. </ItemGroup>
  117. <!-- Windows NetFramework -->
  118. <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' AND $(IsWindowsHelixQueue)" >
  119. <_CopyItems Include="$(MSBuildThisFileDirectory)eng\helix\xunit\runtests.cmd" />
  120. </ItemGroup>
  121. <!-- NonWindows -->
  122. <ItemGroup Condition="!$(IsWindowsHelixQueue)" >
  123. <_CopyItems Include="$(MSBuildThisFileDirectory)eng\helix\vstest\runtests.sh" />
  124. </ItemGroup>
  125. <Copy SourceFiles="@(_CopyItems)" DestinationFolder="$(PublishAbsoluteDir)" />
  126. <ItemGroup>
  127. <HelixPayload Include="$(PublishAbsoluteDir)">
  128. <TestAssembly>$(TargetFileName)</TestAssembly>
  129. <TestName>$(MSBuildProjectName)-$(TargetFramework)</TestName>
  130. <Command Condition="$(IsWindowsHelixQueue)">runtests.cmd $(TargetFileName) $(NETCoreSdkVersion) $(MicrosoftNETCoreAppPackageVersion)</Command>
  131. <Command Condition="!$(IsWindowsHelixQueue)">./runtests.sh $(TargetFileName) $(NETCoreSdkVersion) $(MicrosoftNETCoreAppPackageVersion)</Command>
  132. <TestTimeout>00:30:00</TestTimeout>
  133. </HelixPayload>
  134. </ItemGroup>
  135. </Target>
  136. </Project>