From 633b3d7f459aa20067ddd088d9106fcdfb0c7bbb Mon Sep 17 00:00:00 2001
From: Doug Bunting <6431421+dougbu@users.noreply.github.com>
Date: Mon, 7 Feb 2022 18:06:45 -0800
Subject: [PATCH] Use `-noBuild` in second build steps of test jobs (#39998)

* Use `-noBuild` in second build steps of test jobs
- building again in Publish target adds nothing in most cases
- use `-noBuildRepoTasks` more consistently
  - again, building the repo tasks wastefully repeated work done in previous build step
- use `-noBuildJava` more consistently in quarantined pipelines
  - Java tests aren't worth testing _or building_ in these pipelines because they cannot be quarantined
- remove `-noRestore` and `-noBuildDeps` when `-noBuild` specified; redundant
- work around https://github.com/dotnet/sdk/issues/23777
  - do not publish .cshtml files of most test asset projects when `$(NoBuild)` is set
- update FunctionalTestWithAssets.targets to help Publish succeed when `$(NoBuild)` is set
  - fixes build jobs in quarantined-pr pipeline where `--no-build` was already specified
- for IIS test assets, perform all builds needed for their profiles within Build target
  - move `ReferenceTestTasks=false` and comments about it to where property matters
  - merge separate targets in FunctionalTest.props to make items available during (now separate) Publish

nits:
- touch up RunHelix.ps1 console output
- reorder command line arguments for consistency in changed parts of the YAML files
- move `NoBuild=true` setting out of FunctionalTestWithAssets.props
- use `BeforeTargets` in FunctionalTest.props to improve determinism
---
 .azure/pipelines/ci.yml                       |  4 ++--
 .azure/pipelines/helix-matrix.yml             |  3 ++-
 .azure/pipelines/quarantined-pr.yml           | 20 +++++++++++--------
 .azure/pipelines/quarantined-tests.yml        |  5 +++--
 eng/scripts/RunHelix.ps1                      |  3 ++-
 eng/targets/FunctionalTestWithAssets.props    |  1 -
 eng/targets/FunctionalTestWithAssets.targets  | 17 ++++++++++++++--
 src/Mvc/samples/MvcSandbox/MvcSandbox.csproj  |  9 ++++++++-
 ...soft.AspNetCore.Mvc.FunctionalTests.csproj |  3 ++-
 src/Mvc/test/WebSites/Directory.Build.props   |  4 ++--
 src/Mvc/test/WebSites/Directory.Build.targets | 14 +++++++++++++
 .../IIS/test/Common.LongTests/StartupTests.cs |  1 -
 src/Servers/IIS/IIS/test/FunctionalTest.props | 19 +++++++++---------
 .../test/testassets/Directory.Build.targets   |  2 +-
 .../InProcessNewShimWebSite.csproj            | 15 +++++++++++++-
 .../InProcessWebSite/InProcessWebSite.csproj  | 15 ++++++++++++--
 16 files changed, 99 insertions(+), 36 deletions(-)
 create mode 100644 src/Mvc/test/WebSites/Directory.Build.targets

diff --git a/.azure/pipelines/ci.yml b/.azure/pipelines/ci.yml
index 5df483b991d..55b35f32cee 100644
--- a/.azure/pipelines/ci.yml
+++ b/.azure/pipelines/ci.yml
@@ -228,7 +228,6 @@ stages:
                 -noBuildRepoTasks
                 -noBuildNative
                 -noBuild
-                -noRestore
                 -sign
                 /p:DotNetSignType=$(_SignType)
                 $(_BuildArgs)
@@ -685,7 +684,8 @@ stages:
         - script: ./eng/build.cmd -ci -nobl -all -pack -arch x64
                   /p:CrossgenOutput=false /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log $(_InternalRuntimeDownloadArgs)
           displayName: Build shared fx
-        - script: ./eng/build.cmd -ci -nobl -noBuildRepoTasks -noRestore -test -all -noBuildNative
+        # -noBuildRepoTasks -noBuildNative -noBuild to avoid repeating work done in the previous step.
+        - script: ./eng/build.cmd -ci -nobl -all -noBuildRepoTasks -noBuildNative -noBuild -test
                   -projects eng\helix\helix.proj /p:IsHelixPRCheck=true /p:IsHelixJob=true
                   /p:CrossgenOutput=false /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log $(_InternalRuntimeDownloadArgs)
           displayName: Run build.cmd helix target
diff --git a/.azure/pipelines/helix-matrix.yml b/.azure/pipelines/helix-matrix.yml
index a11aa5e0401..0684583d13b 100644
--- a/.azure/pipelines/helix-matrix.yml
+++ b/.azure/pipelines/helix-matrix.yml
@@ -33,7 +33,8 @@ jobs:
     - script: ./eng/build.cmd -ci -nobl -all -pack -arch x64
               /p:CrossgenOutput=false /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log
       displayName: Build shared fx
-    - script: .\eng\build.cmd -ci -nobl -noBuildRepoTasks -noRestore -test -all -noBuildNative
+    # -noBuildRepoTasks -noBuildNative -noBuild to avoid repeating work done in the previous step.
+    - script: .\eng\build.cmd -ci -nobl -all -noBuildRepoTasks -noBuildNative -noBuild -test
               -projects eng\helix\helix.proj /p:IsHelixJob=true
               /p:CrossgenOutput=false /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log
       displayName: Run build.cmd helix target
diff --git a/.azure/pipelines/quarantined-pr.yml b/.azure/pipelines/quarantined-pr.yml
index 4b32ae94406..203e9f3fdba 100644
--- a/.azure/pipelines/quarantined-pr.yml
+++ b/.azure/pipelines/quarantined-pr.yml
@@ -54,10 +54,11 @@ jobs:
     timeoutInMinutes: 120
     steps:
     # Build the shared framework
-    - script: ./eng/build.cmd -ci -nobl -all -pack -arch x64
+    - script: ./eng/build.cmd -ci -nobl -all -noBuildJava -pack -arch x64
               /p:CrossgenOutput=false /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log
       displayName: Build shared fx
-    - script: ./eng/build.cmd -ci -nobl -noBuildRepoTasks -noRestore -test -all -noBuildJava -noBuildNative
+    # -noBuildRepoTasks -noBuildNative -noBuild to avoid repeating work done in the previous step.
+    - script: ./eng/build.cmd -ci -nobl -all -noBuildRepoTasks -noBuildNative -noBuild -noBuildJava -test
               -projects eng\helix\helix.proj /p:IsHelixPRCheck=true /p:RunQuarantinedTests=true /p:IsHelixJob=true
               /p:CrossgenOutput=false /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log
       displayName: Run build.cmd helix target
@@ -79,9 +80,10 @@ jobs:
     isAzDOTestingJob: true
     enablePublishTestResults: false
     steps:
-    - powershell: "& ./eng/build.ps1 -CI -nobl -all -pack -NoBuildJava"
+    - script: ./eng/build.cmd -ci -nobl -all -noBuildJava -pack
       displayName: Build
-    - script: ./eng/build.cmd -ci -nobl -test -NoRestore -NoBuild -NoBuilddeps "/p:RunQuarantinedTests=true /p:SkipHelixReadyTests=true"
+    - script: ./eng/build.cmd -ci -nobl -all -noBuildRepoTasks -noBuildNative -NoBuild -noBuildJava -test
+              /p:RunQuarantinedTests=true /p:SkipHelixReadyTests=true
       displayName: Run Quarantined Tests
       continueOnError: true
     - task: PublishTestResults@2
@@ -112,9 +114,10 @@ jobs:
     isAzDOTestingJob: true
     enablePublishTestResults: false
     steps:
-    - bash: ./eng/build.sh --all --pack --ci --nobl --no-build-java
+    - bash: ./eng/build.sh --ci --nobl --all --no-build-java --pack
       displayName: Build
-    - bash: ./eng/build.sh --no-build --ci --nobl --test -p:RunQuarantinedTests=true -p:SkipHelixReadyTests=true
+    - bash: ./eng/build.sh --ci --nobl --all --no-build-repo-tasks --no-build --no-build-java --test
+            -p:RunQuarantinedTests=true -p:SkipHelixReadyTests=true
       displayName: Run Quarantined Tests
       continueOnError: true
     - task: PublishTestResults@2
@@ -146,9 +149,10 @@ jobs:
     enablePublishTestResults: false
     useHostedUbuntu: false
     steps:
-    - bash: ./eng/build.sh --all --pack --ci --nobl --no-build-java
+    - bash: ./eng/build.sh --ci --nobl --all --no-build-java --pack
       displayName: Build
-    - bash: ./eng/build.sh --no-build --ci --nobl --test -p:RunQuarantinedTests=true -p:SkipHelixReadyTests=true
+    - bash: ./eng/build.sh --ci --nobl --all --no-build-repo-tasks --no-build --no-build-java --test
+            -p:RunQuarantinedTests=true -p:SkipHelixReadyTests=true
       displayName: Run Quarantined Tests
       continueOnError: true
     - task: PublishTestResults@2
diff --git a/.azure/pipelines/quarantined-tests.yml b/.azure/pipelines/quarantined-tests.yml
index c97f007ea5d..ae481b7cbb4 100644
--- a/.azure/pipelines/quarantined-tests.yml
+++ b/.azure/pipelines/quarantined-tests.yml
@@ -25,10 +25,11 @@ jobs:
     timeoutInMinutes: 480
     steps:
     # Build the shared framework
-    - script: ./eng/build.cmd -ci -nobl -all -pack -arch x64
+    - script: ./eng/build.cmd -ci -nobl -all -noBuildJava -pack -arch x64
               /p:CrossgenOutput=false /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log
       displayName: Build shared fx
-    - script: ./eng/build.cmd -ci -nobl -noBuildRepoTasks -noRestore -test -all -noBuildJava -noBuildNative
+    # -noBuildRepoTasks -noBuildNative -noBuild to avoid repeating work done in the previous step.
+    - script: ./eng/build.cmd -ci -nobl -all -noBuildRepoTasks -noBuildNative -noBuild -noBuildJava -test
               -projects eng\helix\helix.proj /p:RunQuarantinedTests=true /p:IsHelixJob=true
               /p:CrossgenOutput=false /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log
       displayName: Run build.cmd helix target
diff --git a/eng/scripts/RunHelix.ps1 b/eng/scripts/RunHelix.ps1
index eee981c7e37..d0099e01738 100644
--- a/eng/scripts/RunHelix.ps1
+++ b/eng/scripts/RunHelix.ps1
@@ -52,7 +52,8 @@ $env:BUILD_REPOSITORY_NAME="aspnetcore"
 $env:SYSTEM_TEAMPROJECT="aspnetcore"
 
 Write-Host -ForegroundColor Yellow "If running tests that need the shared Fx, run './build -pack -all' before this."
-Write-Host -ForegroundColor Yellow "And if packing for a different platform, add '/p:CrossgenOutput=false'."
+Write-Host -ForegroundColor Yellow "If everything is up-to-date, add '/p:NoBuild=true' to this command."
+Write-Host -ForegroundColor Yellow "Or, if only the test project is out-of-date, add '/p:BuildProjectReferences=false'."
 
 $HelixQueues = $HelixQueues -replace ";", "%3B"
 dotnet msbuild $Project /t:Helix /p:TargetArchitecture="$TargetArchitecture" `
diff --git a/eng/targets/FunctionalTestWithAssets.props b/eng/targets/FunctionalTestWithAssets.props
index 126b2ca6288..2a8d04a3583 100644
--- a/eng/targets/FunctionalTestWithAssets.props
+++ b/eng/targets/FunctionalTestWithAssets.props
@@ -14,7 +14,6 @@
       <RelativeFolder>%(Filename)</RelativeFolder>
       <!-- Whether to _only_ publish the test asset into the test project's folders. -->
       <SkipBuild>false</SkipBuild>
-      <AdditionalProperties Condition=" '%(SkipBuild)' == 'true' ">NoBuild=true</AdditionalProperties>
     </TestAssetProjectReference>
   </ItemDefinitionGroup>
 </Project>
diff --git a/eng/targets/FunctionalTestWithAssets.targets b/eng/targets/FunctionalTestWithAssets.targets
index 2dca09ec9e2..29ecd437e30 100644
--- a/eng/targets/FunctionalTestWithAssets.targets
+++ b/eng/targets/FunctionalTestWithAssets.targets
@@ -7,12 +7,25 @@
   <Target Name="PublishTestAssets"
       BeforeTargets="Publish;RunTests;VSTest"
       Condition=" '@(TestAssetProjectReference->Count())' != 0 ">
-    <!-- Build and Publish test assets into folders relative to test project. -->
     <ItemGroup>
       <_ProjectsToPublish Include="@(TestAssetProjectReference)" />
+
+      <!-- Always Publish test assets relative to test project's output. -->
       <_ProjectsToPublish AdditionalProperties="%(_ProjectsToPublish.AdditionalProperties);
-          OutputPath=$(OutputPath)%(RelativeFolder);
           PublishDir=$(PublishDir)%(RelativeFolder)" />
+
+      <!-- Do not build when publishing if SkipBuild requested. -->
+      <_ProjectsToPublish Condition=" '%(SkipBuild)' == 'true' "
+          AdditionalProperties="%(_ProjectsToPublish.AdditionalProperties);NoBuild=true" />
+
+      <!--
+        Otherwise, both Build and Publish test assets into folders relative to test project's output. Reset
+        NoBuild because these projects aren't referenced anywhere else.
+      -->
+      <_ProjectsToPublish Condition=" '%(SkipBuild)' != 'true' "
+          AdditionalProperties="%(_ProjectsToPublish.AdditionalProperties);
+            NoBuild=false;
+            OutputPath=$(OutputPath)%(RelativeFolder)" />
     </ItemGroup>
 
     <!--
diff --git a/src/Mvc/samples/MvcSandbox/MvcSandbox.csproj b/src/Mvc/samples/MvcSandbox/MvcSandbox.csproj
index b37cc9ac046..daf009d84df 100644
--- a/src/Mvc/samples/MvcSandbox/MvcSandbox.csproj
+++ b/src/Mvc/samples/MvcSandbox/MvcSandbox.csproj
@@ -1,5 +1,4 @@
 <Project Sdk="Microsoft.NET.Sdk.Web">
-
   <PropertyGroup>
     <TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
     <PreserveCompilationContext>true</PreserveCompilationContext>
@@ -14,4 +13,12 @@
     <Reference Include="Microsoft.Extensions.Logging.Debug" />
   </ItemGroup>
 
+  <!-- Work around https://github.com/dotnet/sdk/issues/23777. Reset ContentWithTargetPath items if not building. -->
+  <Target Name="RemoveCshtmlFiles" BeforeTargets="GetCopyToPublishDirectoryItems" Condition=" '$(NoBuild)' == true ">
+    <ItemGroup>
+      <ContentWithTargetPath>
+        <CopyToPublishDirectory Condition=" '%(Extension)' == '.cshtml' ">None</CopyToPublishDirectory>
+      </ContentWithTargetPath>
+    </ItemGroup>
+  </Target>
 </Project>
diff --git a/src/Mvc/test/Mvc.FunctionalTests/Microsoft.AspNetCore.Mvc.FunctionalTests.csproj b/src/Mvc/test/Mvc.FunctionalTests/Microsoft.AspNetCore.Mvc.FunctionalTests.csproj
index 9729f62231e..ef1661548da 100644
--- a/src/Mvc/test/Mvc.FunctionalTests/Microsoft.AspNetCore.Mvc.FunctionalTests.csproj
+++ b/src/Mvc/test/Mvc.FunctionalTests/Microsoft.AspNetCore.Mvc.FunctionalTests.csproj
@@ -19,7 +19,8 @@
     <ProjectReference Include="..\..\shared\Mvc.Core.TestCommon\Microsoft.AspNetCore.Mvc.Core.TestCommon.csproj" />
     <ProjectReference Include="..\WebSites\*\*.csproj"
         Exclude="..\WebSites\ControllersFromServicesClassLibrary\ControllersFromServicesClassLibrary.csproj;
-          ..\WebSites\RazorBuildWebSite.*\RazorBuildWebSite.*.csproj" />
+          ..\WebSites\RazorBuildWebSite.*\RazorBuildWebSite.*.csproj;
+          ..\WebSites\RazorPagesClassLibrary\RazorPagesClassLibrary.csproj" />
 
     <Reference Include="AngleSharp" />
     <Reference Include="System.Net.Http" />
diff --git a/src/Mvc/test/WebSites/Directory.Build.props b/src/Mvc/test/WebSites/Directory.Build.props
index 7a0c61b8c7c..110e00b967e 100644
--- a/src/Mvc/test/WebSites/Directory.Build.props
+++ b/src/Mvc/test/WebSites/Directory.Build.props
@@ -7,6 +7,6 @@
     -->
     <StaticWebAssetsEnabled>false</StaticWebAssetsEnabled>
   </PropertyGroup>
-  <!-- Skip the parent folder to prevent getting test package references. -->
-  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\..\, Directory.Build.props))\Directory.Build.props" />
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, Directory.Build.props))\Directory.Build.props" />
 </Project>
diff --git a/src/Mvc/test/WebSites/Directory.Build.targets b/src/Mvc/test/WebSites/Directory.Build.targets
new file mode 100644
index 00000000000..c1fd69c7f57
--- /dev/null
+++ b/src/Mvc/test/WebSites/Directory.Build.targets
@@ -0,0 +1,14 @@
+<Project>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, Directory.Build.targets))\Directory.Build.targets" />
+
+  <!-- Work around https://github.com/dotnet/sdk/issues/23777. Reset ContentWithTargetPath items if not building. -->
+  <Target Name="RemoveCshtmlFiles"
+      BeforeTargets="GetCopyToPublishDirectoryItems"
+      Condition=" '$(RazorCompileOnPublish)' != false AND '$(NoBuild)' == true ">
+    <ItemGroup>
+      <ContentWithTargetPath>
+        <CopyToPublishDirectory Condition=" '%(Extension)' == '.cshtml' ">None</CopyToPublishDirectory>
+      </ContentWithTargetPath>
+    </ItemGroup>
+  </Target>
+</Project>
diff --git a/src/Servers/IIS/IIS/test/Common.LongTests/StartupTests.cs b/src/Servers/IIS/IIS/test/Common.LongTests/StartupTests.cs
index b0597655a08..0ceb0030440 100644
--- a/src/Servers/IIS/IIS/test/Common.LongTests/StartupTests.cs
+++ b/src/Servers/IIS/IIS/test/Common.LongTests/StartupTests.cs
@@ -217,7 +217,6 @@ public class StartupTests : IISFunctionalTestBase
         // We need the right dotnet on the path in IIS
         deploymentParameters.EnvironmentVariables["PATH"] = Path.GetDirectoryName(DotNetCommands.GetDotNetExecutable(deploymentParameters.RuntimeArchitecture));
 
-        // ReferenceTestTasks is workaround for https://github.com/dotnet/sdk/issues/2482
         var deploymentResult = await DeployAsync(deploymentParameters);
 
         Assert.True(File.Exists(Path.Combine(deploymentResult.ContentRoot, "InProcessWebSite.exe")));
diff --git a/src/Servers/IIS/IIS/test/FunctionalTest.props b/src/Servers/IIS/IIS/test/FunctionalTest.props
index 3c059a6ef63..7396b3e8b63 100644
--- a/src/Servers/IIS/IIS/test/FunctionalTest.props
+++ b/src/Servers/IIS/IIS/test/FunctionalTest.props
@@ -1,25 +1,24 @@
 <Project>
-
   <ItemGroup>
     <Content Include="..\Common.FunctionalTests\Infrastructure\*.config" CopyToOutputDirectory="PreserveNewest" />
   </ItemGroup>
 
-  <Target Name="BuildAssets" AfterTargets="Build" Condition="'$(ExcludeFromBuild)' != 'true'">
-    <MSBuild Projects="@(ProjectReference)" Targets="PublishTestsAssets" SkipNonexistentTargets="true" BuildInParallel="True">
+  <Target Name="CopyAssets" BeforeTargets="Publish" Condition=" '$(ExcludeFromBuild)' != true ">
+    <MSBuild Projects="@(ProjectReference)"
+        Targets="PublishTestsAssets"
+        SkipNonexistentTargets="true"
+        BuildInParallel="True">
       <Output TaskParameter="TargetOutputs" ItemName="PublishedTestAsset" />
     </MSBuild>
-  </Target>
-
-  <Target Name="CopyAssets" AfterTargets="Publish" Condition="'@(PublishedTestAsset->Count())' != '0'">
 
-    <ItemGroup>
+    <ItemGroup Condition=" @(PublishedTestAsset->Count()) != 0 ">
      <_FilesToCopy Include="%(PublishedTestAsset.Path)\**\*">
         <DestinationDir>$(PublishDir)\%(PublishedTestAsset.Identity)\</DestinationDir>
       </_FilesToCopy>
     </ItemGroup>
 
-    <Copy SourceFiles="@(_FilesToCopy)" DestinationFiles="@(_FilesToCopy->'%(DestinationDir)%(RecursiveDir)%(FileName)%(Extension)')" />
-
+    <Copy SourceFiles="@(_FilesToCopy)"
+        Condition=" @(PublishedTestAsset->Count()) != 0 "
+        DestinationFiles="@(_FilesToCopy->'%(DestinationDir)%(RecursiveDir)%(FileName)%(Extension)')" />
   </Target>
-
 </Project>
diff --git a/src/Servers/IIS/IIS/test/testassets/Directory.Build.targets b/src/Servers/IIS/IIS/test/testassets/Directory.Build.targets
index d1c86dc48f4..045983437fd 100644
--- a/src/Servers/IIS/IIS/test/testassets/Directory.Build.targets
+++ b/src/Servers/IIS/IIS/test/testassets/Directory.Build.targets
@@ -41,7 +41,7 @@
     <MSBuild Projects="$(MSBuildProjectFullPath)"
              Targets="PublishTestsAsset"
              RemoveProperties="Platform;PlatformTarget"
-             Properties="PublishDir=$(PublishDir);TestAssetProfile=%(TestAssetPublishProfile.Identity);ReferenceTestTasks=false;%(TestAssetPublishProfile.Properties)">
+             Properties="PublishDir=$(PublishDir);TestAssetProfile=%(TestAssetPublishProfile.Identity);%(TestAssetPublishProfile.Properties)">
       <Output TaskParameter="TargetOutputs" ItemName="PublishedTestAsset" />
     </MSBuild>
   </Target>
diff --git a/src/Servers/IIS/IIS/test/testassets/InProcessNewShimWebSite/InProcessNewShimWebSite.csproj b/src/Servers/IIS/IIS/test/testassets/InProcessNewShimWebSite/InProcessNewShimWebSite.csproj
index 267860b5d1d..fc765d46f86 100644
--- a/src/Servers/IIS/IIS/test/testassets/InProcessNewShimWebSite/InProcessNewShimWebSite.csproj
+++ b/src/Servers/IIS/IIS/test/testassets/InProcessNewShimWebSite/InProcessNewShimWebSite.csproj
@@ -11,7 +11,11 @@
 
   <ItemGroup Condition="'$(OS)' == 'Windows_NT'">
     <TestAssetPublishProfile Include="Portable" Properties="TargetFramework=$(DefaultNetCoreTargetFramework)" />
-    <TestAssetPublishProfile Condition="'$(TargetArchitecture)' != 'arm'" Include="Standalone-x64" Properties="RuntimeIdentifier=win-x64;" />
+
+    <!-- ReferenceTestTasks is workaround for https://github.com/dotnet/sdk/issues/2482 -->
+    <TestAssetPublishProfile Include="Standalone-x64"
+        Condition=" '$(TargetArchitecture)' != 'arm' "
+        Properties="RuntimeIdentifier=win-x64;ReferenceTestTasks=false" />
   </ItemGroup>
 
   <ItemGroup>
@@ -59,4 +63,13 @@
     </PackageReference>
     <Reference Include="xunit.assert" />
   </ItemGroup>
+
+  <!-- Repeat Build target for win-x64 to allow later Publish w/ NoBuild=true. -->
+  <Target Name="BuildX64"
+      BeforeTargets="Build"
+      Condition=" '$(RuntimeIdentifier)' != 'win-x64' AND '$(TargetArchitecture)' != 'arm' ">
+    <MSBuild Projects="$(MSBuildProjectFullPath)"
+        Properties="RuntimeIdentifier=win-x64;ReferenceTestTasks=false"
+        Targets="Build" />
+  </Target>
 </Project>
diff --git a/src/Servers/IIS/IIS/test/testassets/InProcessWebSite/InProcessWebSite.csproj b/src/Servers/IIS/IIS/test/testassets/InProcessWebSite/InProcessWebSite.csproj
index cb6d6071a05..2f207433c59 100644
--- a/src/Servers/IIS/IIS/test/testassets/InProcessWebSite/InProcessWebSite.csproj
+++ b/src/Servers/IIS/IIS/test/testassets/InProcessWebSite/InProcessWebSite.csproj
@@ -1,5 +1,4 @@
 <Project Sdk="Microsoft.NET.Sdk.Web">
-
   <Import Project="..\..\..\..\build\testsite.props" />
 
   <PropertyGroup>
@@ -9,7 +8,11 @@
 
   <ItemGroup Condition="'$(OS)' == 'Windows_NT'">
     <TestAssetPublishProfile Include="Portable" Properties="TargetFramework=$(DefaultNetCoreTargetFramework)" />
-    <TestAssetPublishProfile Condition="'$(TargetArchitecture)' != 'arm'" Include="Standalone-x64" Properties="RuntimeIdentifier=win-x64;" />
+
+    <!-- ReferenceTestTasks is workaround for https://github.com/dotnet/sdk/issues/2482 -->
+    <TestAssetPublishProfile Include="Standalone-x64"
+        Condition=" '$(TargetArchitecture)' != 'arm' "
+        Properties="RuntimeIdentifier=win-x64;ReferenceTestTasks=false" />
   </ItemGroup>
 
   <ItemGroup>
@@ -32,4 +35,12 @@
     <Reference Include="xunit.assert" />
   </ItemGroup>
 
+  <!-- Repeat Build target for win-x64 to allow later Publish w/ NoBuild=true. -->
+  <Target Name="BuildX64"
+      BeforeTargets="Build"
+      Condition=" '$(RuntimeIdentifier)' != 'win-x64' AND '$(TargetArchitecture)' != 'arm' ">
+    <MSBuild Projects="$(MSBuildProjectFullPath)"
+        Properties="RuntimeIdentifier=win-x64;ReferenceTestTasks=false"
+        Targets="Build" />
+  </Target>
 </Project>
-- 
GitLab