Browse Source

Further centralize shared Fx and TFM transition workarounds (#27473)

* Further centralize shared Fx and TFM transition workarounds
  - make generated `Directory.Build.*` files more widely applicable
    - warn if requested Microsoft.AspNetCore.App version does not exist in `$(DOTNET_ROOT)`
    - add `$(UpdateAspNetCoreKnownFramework)` for Microsoft.AspNetCore.App `@(KnownFrameworkReference)` update
    - remove central `$(BuildingTestAppsIndependently)` special case
      - not needed because compiler toolset version is always available
    - correct `$(KnownAppHostPackOrFrameworkReferenceTfm)` when not targeting the default TFM
      - use MSBuild intrinsic functions for this and in framework projects; future-proofing
    - correct `@(KnownFrameworkReference)` metadata when in servicing
       - should not override default runtime and targeting pack versions
  - use generated `Directory.Build.*` files in regular build
    - remove now-duplicate property and item settings outside generated `Directory.Build.*` files
  - use generated `Directory.Build.*` files for local Razor tests
    - set `$(TargetLatestRuntimePatch)` instead of `$(RuntimeFrameworkVersion)`; simpler
    - do not restore Razor SDK test asset projects until just before tests run
    - depend on Microsoft.AspNetCore.App projects
    - disable `$(TreatWarningsAsErrors)` for a few Razor SDK tests
      - tests expect projects to build successfully despite a few warnings
  - improve (widen) Microsoft.AspNetCore.App `Condition` in Blazor SDK tests

nit: do not pass `$(MicrosoftNetCompilersToolsetVersion)` into Razor test asset projects
  - not needed because generated files already contain the right information
  - even without that, the Directory.Build.props file imports eng/Versions.props

* Use generated `Directory.Build.*` files for local template tests
  - move Infrastructure/ files to TestInfrastructure/
    - Infrastructure/ sub-directories were functionally identical
  - move shared parts of template test project files to PrepareForTest.targets

* Describe errors with missing generated files and the new warning in BuildFromSource.md
  - address numerous Markdown lint warnings, typos, and spelling mistakes in this file

* Apply suggestions from code review
  - thanks @captainsafia

* Move all troubleshooting information into BuildErrors.md
  - some was already duplicated
  - fix Markdown lint issues in BuildErrors.md too

* Reorder App.Runtime build slightly
  - move `_InstallFrameworkIntoLocalDotNet` earlier because other builds depend on this part
    - this target sometimes executes after dependent projects continue
  - add `DependsOnTargets` attributes to further constrain ordering

nit: `IncludeFrameworkListFile` should run before `_ResolveSharedFrameworkContent`

* Add temporary workaround for `[AssemblyVersion]` changes

* Address @wtgodbe's nit from #27653
  - https://github.com/dotnet/aspnetcore/pull/27653#pullrequestreview-529368502

Co-authored-by: Safia Abdalla <[email protected]>
Doug Bunting 5 years ago
parent
commit
5fd1db2625
32 changed files with 399 additions and 646 deletions
  1. 2 3
      Directory.Build.props
  2. 10 23
      Directory.Build.targets
  3. 75 12
      docs/BuildErrors.md
  4. 65 104
      docs/BuildFromSource.md
  5. 0 19
      eng/Workarounds.targets
  6. 0 1
      eng/tools/GenerateFiles/Directory.Build.props.in
  7. 67 18
      eng/tools/GenerateFiles/Directory.Build.targets.in
  8. 2 1
      eng/tools/GenerateFiles/GenerateFiles.csproj
  9. 4 4
      src/Components/WebAssembly/Sdk/integrationtests/Microsoft.NET.Sdk.BlazorWebAssembly.IntegrationTests.csproj
  10. 0 7
      src/Components/WebAssembly/Sdk/testassets/Directory.Build.props
  11. 10 7
      src/Framework/App.Runtime/src/Microsoft.AspNetCore.App.Runtime.csproj
  12. 2 1
      src/Framework/Directory.Build.props
  13. 1 100
      src/ProjectTemplates/BlazorTemplates.Tests/BlazorTemplates.Tests.csproj
  14. 0 4
      src/ProjectTemplates/BlazorTemplates.Tests/Directory.Build.targets
  15. 0 8
      src/ProjectTemplates/BlazorTemplates.Tests/Infrastructure/Directory.Build.props.in
  16. 0 3
      src/ProjectTemplates/BlazorTemplates.Tests/Infrastructure/Directory.Build.targets.in
  17. 0 30
      src/ProjectTemplates/BlazorTemplates.Tests/Infrastructure/GenerateTestProps.targets
  18. 0 58
      src/ProjectTemplates/BlazorTemplates.Tests/Infrastructure/TemplateTests.props.in
  19. 12 0
      src/ProjectTemplates/TestInfrastructure/Directory.Build.props.in
  20. 22 0
      src/ProjectTemplates/TestInfrastructure/Directory.Build.targets.in
  21. 98 0
      src/ProjectTemplates/TestInfrastructure/PrepareForTest.targets
  22. 0 0
      src/ProjectTemplates/TestInfrastructure/runtimeconfig.norollforward.json
  23. 0 4
      src/ProjectTemplates/test/Directory.Build.targets
  24. 0 6
      src/ProjectTemplates/test/Infrastructure/Directory.Build.props.in
  25. 0 3
      src/ProjectTemplates/test/Infrastructure/Directory.Build.targets.in
  26. 0 30
      src/ProjectTemplates/test/Infrastructure/GenerateTestProps.targets
  27. 0 57
      src/ProjectTemplates/test/Infrastructure/TemplateTests.props.in
  28. 0 3
      src/ProjectTemplates/test/Infrastructure/runtimeconfig.norollforward.json
  29. 1 100
      src/ProjectTemplates/test/ProjectTemplates.Tests.csproj
  30. 17 5
      src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/Microsoft.NET.Sdk.Razor.IntegrationTests.csproj
  31. 10 15
      src/Razor/test/testassets/Directory.Build.props
  32. 1 20
      src/Razor/test/testassets/Directory.Build.targets

+ 2 - 3
Directory.Build.props

@@ -21,8 +21,7 @@
           $(MSBuildProjectName.EndsWith('.Test')) OR
           $(MSBuildProjectName.EndsWith('.FunctionalTest')) ) ">true</IsUnitTestProject>
     <IsTestAssetProject Condition=" $(RepoRelativeProjectDir.Contains('testassets')) ">true</IsTestAssetProject>
-    <IsSampleProject Condition=" $(RepoRelativeProjectDir.Contains('sample')) OR
-        $(RepoRelativeProjectDir.Contains('Sample')) ">true</IsSampleProject>
+    <IsSampleProject Condition=" $(RepoRelativeProjectDir.ToUpperInvariant().Contains('SAMPLE')) ">true</IsSampleProject>
     <IsAnalyzersProject Condition="$(MSBuildProjectName.EndsWith('.Analyzers'))">true</IsAnalyzersProject>
     <IsShipping Condition=" '$(IsSampleProject)' == 'true' OR
         '$(IsTestAssetProject)' == 'true' OR
@@ -101,7 +100,6 @@
 
   <!-- Warnings and errors -->
   <PropertyGroup>
-    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
     <!-- For local builds, don't make missing XML docs a fatal build error, but still surface so we have visibility into undocumented APIs. -->
     <WarningsNotAsErrors Condition=" '$(ContinuousIntegrationBuild)' != 'true' ">$(WarningsNotAsErrors);CS1591</WarningsNotAsErrors>
     <!-- For CI builds, ensure API docs are available. -->
@@ -216,6 +214,7 @@
   </PropertyGroup>
 
   <Import Project="eng\Workarounds.props" />
+  <Import Project="artifacts\bin\GenerateFiles\Directory.Build.props" Condition=" '$(MSBuildProjectName)' != 'GenerateFiles' " />
   <Import Project="eng\Dependencies.props" />
   <Import Project="eng\ProjectReferences.props" />
   <Import Project="eng\SharedFramework.Local.props" />

+ 10 - 23
Directory.Build.targets

@@ -151,34 +151,20 @@
 
   <PropertyGroup>
     <KnownAppHostPackOrFrameworkReferenceTfm>$(DefaultNetCoreTargetFramework)</KnownAppHostPackOrFrameworkReferenceTfm>
-    <KnownAppHostPackOrFrameworkReferenceTfm Condition=" '$(TargetFrameworkIdentifier)' == '$(NETCoreAppFrameworkIdentifier)' AND
-      $([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '5.0')) ">netcoreapp$(TargetFrameworkVersion.TrimStart('vV'))</KnownAppHostPackOrFrameworkReferenceTfm>
+    <_DefaultTargetFrameworkIdentifier>$([MSBuild]::GetTargetFrameworkIdentifier('$(DefaultNetCoreTargetFramework)'))</_DefaultTargetFrameworkIdentifier>
+    <_DefaultTargetFrameworkVersionNoV>$([MSBuild]::GetTargetFrameworkVersion('$(DefaultNetCoreTargetFramework)', 2))</_DefaultTargetFrameworkVersionNoV>
+    <KnownAppHostPackOrFrameworkReferenceTfm Condition=" '$(_DefaultTargetFrameworkIdentifier)' == '$(NETCoreAppFrameworkIdentifier)' AND
+      $([MSBuild]::VersionGreaterThanOrEquals('$(_DefaultTargetFrameworkVersionNoV)', '5.0')) ">netcoreapp$(_DefaultTargetFrameworkVersionNoV)</KnownAppHostPackOrFrameworkReferenceTfm>
+
+    <!-- Do not update the Microsoft.AspNetCore.App KnownFrameworkReference item unless requested. -->
+    <UpdateAspNetCoreKnownFramework>false</UpdateAspNetCoreKnownFramework>
+    <UpdateAspNetCoreKnownFramework Condition=" '$(UseAspNetCoreSharedRuntime)' == 'true' AND
+      '$(DoNotApplyWorkaroundsToMicrosoftAspNetCoreApp)' != 'true' ">true</UpdateAspNetCoreKnownFramework>
   </PropertyGroup>
 
   <ItemGroup>
-    <KnownFrameworkReference Update="Microsoft.NETCore.App">
-      <!-- Always update the 'latest version', whether the repo is servicing or not. -->
-      <LatestRuntimeFrameworkVersion Condition="'%(TargetFramework)' == '$(KnownAppHostPackOrFrameworkReferenceTfm)'">$(MicrosoftNETCoreAppRuntimeVersion)</LatestRuntimeFrameworkVersion>
-      <!-- Only update the default runtime version for preview builds. -->
-      <DefaultRuntimeFrameworkVersion Condition="'%(TargetFramework)' == '$(KnownAppHostPackOrFrameworkReferenceTfm)' and '$(IsServicingBuild)' != 'true'">$(MicrosoftNETCoreAppRuntimeVersion)</DefaultRuntimeFrameworkVersion>
-      <!-- Only update the targeting pack version for preview builds. -->
-      <TargetingPackVersion Condition="'%(TargetFramework)' == '$(KnownAppHostPackOrFrameworkReferenceTfm)' and '$(IsServicingBuild)' != 'true'">$(MicrosoftNETCoreAppRefVersion)</TargetingPackVersion>
-    </KnownFrameworkReference>
-
     <KnownFrameworkReference Condition="'$(UseAspNetCoreSharedRuntime)' != 'true'" Remove="Microsoft.AspNetCore.App" />
     <KnownFrameworkReference Remove="Microsoft.WindowsDesktop.App" />
-
-    <KnownFrameworkReference Condition="'$(UseAspNetCoreSharedRuntime)' == 'true' AND '$(DoNotApplyWorkaroundsToMicrosoftAspNetCoreApp)' != 'true'" Update="Microsoft.AspNetCore.App">
-      <LatestRuntimeFrameworkVersion>$(SharedFxVersion)</LatestRuntimeFrameworkVersion>
-      <DefaultRuntimeFrameworkVersion Condition="'$(IsServicingBuild)' != 'true'">$(SharedFxVersion)</DefaultRuntimeFrameworkVersion>
-      <TargetingPackVersion Condition="'$(IsServicingBuild)' != 'true'">$(TargetingPackVersion)</TargetingPackVersion>
-    </KnownFrameworkReference>
-
-    <!-- Track compiler separately from Arcade.-->
-    <PackageReference Include="Microsoft.Net.Compilers.Toolset"
-        Version="$(MicrosoftNetCompilersToolsetVersion)"
-        PrivateAssets="all"
-        IsImplicitlyDefined="true" />
   </ItemGroup>
 
   <PropertyGroup Condition=" '$(CopySymbolsToArtifacts)' == 'true' AND '$(TargetFramework)' != '' ">
@@ -195,6 +181,7 @@
   </Target>
 
   <Import Project="eng\Workarounds.targets" />
+  <Import Project="artifacts\bin\GenerateFiles\Directory.Build.targets" Condition=" '$(MSBuildProjectName)' != 'GenerateFiles' " />
   <Import Project="eng\targets\ResolveIisReferences.targets" Condition=" '$(MSBuildProjectExtension)' != '.vcxproj' " />
   <Import Project="eng\targets\Cpp.Common.targets"  Condition="'$(MSBuildProjectExtension)' == '.vcxproj'" />
   <Import Project="eng\targets\CSharp.Common.targets"  Condition="'$(MSBuildProjectExtension)' == '.csproj'" />

+ 75 - 12
docs/BuildErrors.md

@@ -1,33 +1,96 @@
-Build Errors
-------------
+# Build Errors
 
 This document is for common build errors and how to resolve them.
 
-### Warning BUILD001
+## Warning BUILD001
 
-> warning BUILD001: Package references changed since the last release...
+> warning BUILD001: Reference to '&hellip;' was removed since the last stable release of this package. &hellip;
 
 This warning indicates a breaking change might have been made to a package or assembly due to the removal of a reference which was used
-in a previous release of this assembly. See <./ReferenceResolution.md> for how to suppress.
+in a previous release of this assembly. See [ReferenceResolution](./ReferenceResolution.md) for how to suppress.
 
-### Error BUILD002
+## Error BUILD002
 
-> error BUILD002: Package references changed since the last release...
+> error BUILD002: Package references changed since the last release&hellip;
 
-Similar to BUILD001, but this error is not suppressable. This error only appears in servicing builds, which should not change references between assemblies or packages.
+Similar to BUILD001, but this error is not suppressible. This error only appears in servicing builds, which should not change references between assemblies or packages.
 
-### Error BUILD003
+## Error BUILD003
 
 > error BUILD003: Multiple project files named 'Banana.csproj' exist. Project files should have a unique name to avoid conflicts in build output.
 
-This repo uses a common output directory (artifacts/bin/$(ProjectName) and artifacts/obj/$(ProjectName)). To avoid confllicts in build output, each
+This repo uses a common output directory (artifacts/bin/$(ProjectName) and artifacts/obj/$(ProjectName)). To avoid conflicts in build output, each
 project file should have a unique name.
 
-### Error MSB4236 / Unable to locate the .NET Core SDK
-  
+## Error CS0006
+
+Opening solution filters and building may produce an error code CS0006 with a message such as
+
+> Error CS0006 Metadata file '&hellip;\AspNetCore\artifacts\bin\Microsoft.AspNetCore.Metadata\Debug\netstandard2.0\Microsoft.AspNetCore.Metadata.dll' could not be found
+
+The cause of this problem is that the solution filter you are using does not include the project that produces this .dll. This most often occurs after we have added new projects to the repo, but failed to update our .sln/slnf files to include the new project. In some cases, it is sometimes the intended behavior of the .slnf which has been crafted to only include a subset of projects.
+
+### You can fix this in one of three ways
+
+1. Build the project on command line. In most cases, running `build.cmd` on command line solves this problem.
+2. If the project is missing from the .sln file entirely, you can use `dotnet sln add` to add it, or else right click on the solution/folder in Visual Studio and choose Add->Existing Project, and adding it.
+3. If it is present in the .sln, but not the .slnf, you can update the solution filter to include the missing project. You can either do this one by right-clicking on project in Visual Studio and choosing to load it's direct dependencies, and then saving.  Alternatively, you can hand edit the .slnf file - it's a fairly simple json format.
+
+## Error MSB4019: The imported project "&hellip;\artifacts\bin\GenerateFiles\Directory.Build.props" was not found
+
+You have likely attempted to use `dotnet` to build a project in the repo without first generating the required files.
+Prior to building without `.\build.cmd` or `./build.sh` at least the following **must** be executed:
+
+```powershell
+.\build.cmd -noBuildNative -noBuildManaged
+```
+
+or
+
+```bash
+./build.sh --no-build-managed
+```
+
+## Error MSB4236: Unable to locate the .NET Core SDK
+
 Executing `.\restore.cmd` or `.\build.cmd` may produce these errors:
 
 > error : Unable to locate the .NET Core SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version.
 > error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.
 
 In most cases, this is because the option _Use previews of the .NET Core SDK_ in VS2019 is not checked. Start Visual Studio, go to _Tools > Options_ and check _Use previews of the .NET Core SDK_ under _Environment > Preview Features_.
+
+## Error: HTTP Error 500.33 - ANCM Request Handler Load Failure
+
+The [ASP.NET Core Module](https://docs.microsoft.com/aspnet/core/host-and-deploy/aspnet-core-module) (ANCM) for IIS is not supported when running projects in this repository.
+
+After using `startvs.cmd` to open a solution in Visual Studio, the Kestrel web host option must be used (name of the project) and not IIS Express.
+
+Example of running the `MvcSandbox` project:
+
+`.\startvs.cmd .\src\Mvc\Mvc.sln`
+
+![Web host options in Visual Studio](./vs-iis-express-aspnet-core-mvc-sandbox.jpg)
+
+## Error: Unable to load the service index for &hellip;
+
+When attempting to restore servicing tags e.g. `v3.1.7`,  the NuGet.config file may contain internal feeds that are not accessible. This will result in errors such as
+
+> &hellip;\aspnetcore\.dotnet\sdk\3.1.103\NuGet.targets(123,5): error : Unable to load the service index for source https://pkgs.dev.azure.com/dnceng/_packaging/darc-int-dotnet-extensions-784b0ffa/nuget/v3/index.json. [&hellip;\Temp\1gsd3rdo.srb\restore.csproj] [&hellip;\.nuget\packages\microsoft.dotnet.arcade.sdk\1.0.0-beta.20213.4\tools\Tools.proj]
+
+The `darc-int-...` feeds in NuGet.config are used only when building internally and are not needed after the tags are created. Delete all such entries in the file and retry.
+
+## Warning: Requested Microsoft.AspNetCore.App v&hellip; does not exist
+
+You have likely attempted to build projects or execute tests which require the just-build Microsoft.AspNetCore.App
+shared framework. Execute the following to ensure that exists within the `$(DOTNET_ROOT)` folder:
+
+```powershell
+.\build.cmd -projects src\Framework\App.Runtime\src\Microsoft.AspNetCore.App.Runtime.csproj
+```
+
+or
+
+```bash
+./build.sh --projects "$PWD/src/Framework/App.Runtime/src/Microsoft.AspNetCore.App.Runtime.csproj"
+```

+ 65 - 104
docs/BuildFromSource.md

@@ -15,13 +15,13 @@ This tutorial assumes that you are familiar with:
 
 ASP.NET Core uses git submodules to include the source from a few other projects. In order to pull the sources of the these submodules when cloning the repo, be sure to pass the `--recursive` flag to the `git clone` command.
 
-```ps1
+```powershell
 git clone --recursive https://github.com/dotnet/aspnetcore
 ```
 
 If you've already cloned the aspnetcore repo without fetching subdmoule sources, you can fetch them after cloning by running the following command.
 
-```ps1
+```powershell
 git submodule update --init --recursive
 ```
 
@@ -45,61 +45,63 @@ Visual Studio 2019 (16.8) is required to build the repo locally. If you don't ha
 > :bulb: To install Visual Studio from the preview channel, you can use the `-Channel` flag to set the channel (`-Channel Preview`).
 > :bulb: Even if you have installed Visual Studio, we still recommend using this script to install again to avoid errors due to missing components.
 
-```ps1
-PS> ./eng/scripts/InstallVisualStudio.ps1  [-Edition {Enterprise|Community|Professional}] [-Channel {Release|Preview}]
+```powershell
+./eng/scripts/InstallVisualStudio.ps1  [-Edition {Enterprise|Community|Professional}] [-Channel {Release|Preview}]
 ```
 
 > :bulb: To execute the setup script or other PowerShell scripts in the repo, you may need to update the execution policy on your machine.
 > You can do so by running the `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser` command
-> in PowerShell. For more information on execution policies, you can read the [execution policy docs](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy).
+> in PowerShell. For more information on execution policies, you can read the [execution policy docs](https://docs.microsoft.com/powershell/module/microsoft.powershell.security/set-executionpolicy).
 
 The  [global.json](/global.json) file specifies the minimum requirements needed to build using `msbuild`. The [eng/scripts/vs.json](/eng/scripts/vs.json) file provides a description of the components needed to build within VS. If you plan on developing in Visual Studio, you will need to have these components installed.
 
-> :bulb: The `IntallVisualStudio.ps1` script mentioned above reads from the `vs.json` file to determine what components to install.
+> :bulb: The `InstallVisualStudio.ps1` script mentioned above reads from the `vs.json` file to determine what components to install.
 
-#### [Git](https://git-scm.org)
+#### [Git](https://git-scm.org) on Windows
 
 If you're reading this, you probably already have Git installed to support cloning the repo as outlined in Step 1.
 
-#### [NodeJS](https://nodejs.org)
+#### [NodeJS](https://nodejs.org) on Windows
 
-Building the repo requires version 10.14.2 or newer of Node. You can find installation executables for Node at https://nodejs.org.
+Building the repo requires version 10.14.2 or newer of Node. You can find installation executables for Node at <https://nodejs.org>.
 
-#### [Yarn](https://yarnpkg.com/)
+#### [Yarn](https://yarnpkg.com/) on Windows
 
-NodeJS installes the Node package manager (npm) by default. This repo depends on yarn, an alternate package manager for the Node ecosystem. You can install Yarn from the command line using the following command.
+NodeJS installs the Node package manager (npm) by default. This repo depends on Yarn, an alternate package manager for the Node ecosystem. You can install Yarn from the command line using the following command.
 
-```ps1
+```powershell
 npm install -g yarn
 ```
 
-#### Java Development Kit in Windows*
+#### Java Development Kit on Windows
 
 This repo contains some Java source code that depends on an install of the JDK v11 or newer. The JDK can be installed from either:
-  * OpenJDK <https://jdk.java.net/>
-  * Oracle's JDK <https://www.oracle.com/technetwork/java/javase/downloads/index.html>
+
+- OpenJDK <https://jdk.java.net/>
+- Oracle's JDK <https://www.oracle.com/technetwork/java/javase/downloads/index.html>
 
 Alternatively, you can run [eng/scripts/InstallJdk.ps1](/eng/scripts/InstallJdk.ps1) to install a version of the JDK that will only be used in this repo.
 
-```ps1
-PS> ./eng/scripts/InstallJdk.ps1
+```powershell
+./eng/scripts/InstallJdk.ps1
 ```
 
 The build should find any JDK 11 or newer installation on the machine as long as the `JAVA_HOME` environment variable is set. Typically, your installation will do this automatically. However, if it is not set you can set the environment variable manually:
-      * Set `JAVA_HOME` to `RepoRoot/.tools/jdk/win-x64/` if you used the `InstallJdk.ps1` script.
-      * Set `JAVA_HOME` to `C:/Program Files/Java/jdk<version>/` if you installed the JDK globally.
+
+- Set `JAVA_HOME` to `RepoRoot/.tools/jdk/win-x64/` if you used the `InstallJdk.ps1` script.
+- Set `JAVA_HOME` to `C:/Program Files/Java/jdk<version>/` if you installed the JDK globally.
 
 #### Chrome
 
 This repo contains a Selenium-based tests require a version of Chrome to be installed. Download and install it from <https://www.google.com/chrome>.
 
-#### Wix (Optional)
+#### WiX (Optional)
 
-If you plan on working with the Windows installers defined in [src/Installers/Windows](../src/Installers/Windows), you will need to install the Wix toolkit from https://wixtoolset.org/releases/.
+If you plan on working with the Windows installers defined in [src/Installers/Windows](../src/Installers/Windows), you will need to install the WiX toolkit from <https://wixtoolset.org/releases/>.
 
 ### On macOS/Linux
 
-You can also build ASP.NET Core on macOS or Linux. macOS Sierra or newer is required if you're building on macOS. If you're building on Linux, your machine will need to meet the [.NET Core Linux preequisities](https://docs.microsoft.com/en-us/dotnet/core/linux-prerequisites).
+You can also build ASP.NET Core on macOS or Linux. macOS Sierra or newer is required if you're building on macOS. If you're building on Linux, your machine will need to meet the [.NET Core Linux prerequisites](https://docs.microsoft.com/dotnet/core/linux-prerequisites).
 
 > :bulb: Be sure you have least 10 GB of disk space and a good Internet connection. The build scripts will download several tools and dependencies onto your machine.
 
@@ -107,42 +109,45 @@ You can also build ASP.NET Core on macOS or Linux. macOS Sierra or newer is requ
 
 `curl` and `wget` are command line tools that can be used to download files from an HTTP server. Either utility will need to be installed in order to complete the setup. Typically, these will be included on your machine by default.
 
-If neither utility is installed, you can install curl (https://curl.haxx.se) or wget (https://www.gnu.org/software/wget).
+If neither utility is installed, you can install curl (<https://curl.haxx.se>) or wget (<https://www.gnu.org/software/wget>).
 
-##### Git
+#### Git
 
 If you've made it this far, you've already got `Git` installed. Sit back, relax, and move on to the next requirement.
 
 #### [NodeJS](https://nodejs.org)
 
-Building the repo requires version 10.14.2 or newer of Node. You can find installation executables for Node at https://nodejs.org.
+Building the repo requires version 10.14.2 or newer of Node. You can find installation executables for Node at <https://nodejs.org>.
 
 #### [Yarn](https://yarnpkg.com/)
 
-NodeJS installs the Node package manager (npm) by default. This repo depends on yarn, an alternate package manager for the Node ecosystem. You can install Yarn from the command line using the following command.
+NodeJS installs the Node package manager (npm) by default. This repo depends on Yarn, an alternate package manager for the Node ecosystem. You can install Yarn from the command line using the following command.
 
 ```bash
-$ npm install -g yarn
+npm install -g yarn
 ```
 
 #### Java Development Kit
 
 This repo contains some Java source code that depends on an install of the JDK v11 or newer. The JDK can be installed from either:
-  * OpenJDK <https://jdk.java.net/>
-  * Oracle's JDK <https://www.oracle.com/technetwork/java/javase/downloads/index.html>
+
+- OpenJDK <https://jdk.java.net/>
+- Oracle's JDK <https://www.oracle.com/technetwork/java/javase/downloads/index.html>
 
 Similar to [the instructions above for Windows](#java-development-kit-in-windows), be sure that the the `JAVA_HOME` environment variable is set to the location of your Java installation.
 
 ## Step 3: Build the repo
 
-Before opening our .sln/.slnf files in Visual Studio or VS Code, you will need to build the repo locally.
+Before opening our .sln/.slnf files in Visual Studio or VS Code, you will need to at least restore the repo locally.
 
 ### In Visual Studio
 
-To set up your project for development on Visual Studio, you'll need to execute the following command.
+To set up your project for development on Visual Studio, you'll need to execute the following command. Building
+subsets of the repo e.g. Java projects may (depending on your scenario) be necessary before building within Visual
+Studio because those projects are not listed in AspNetCore.sln.
 
-```ps1
-PS1> .\restore.cmd
+```powershell
+.\restore.cmd
 ```
 
 > :bulb: If you happen to be working on macOS or Linux, you can use the `restore.sh` command.
@@ -154,18 +159,21 @@ to open the .sln file or one of the project specific .slnf files to work on the
    > branch, we regularly update the versions of .NET Core SDK required to build the repo.
    > You will need to restart Visual Studio every time we update the .NET Core SDK.
 
-Typically, you want to focus on a single project within the monorepo. For example,
+> :bulb: Rerunning the above command or, perhaps, the quicker `.\build.cmd -noBuildNative -noBuildManaged` may be
+> necessary after switching branches, especially if the `$(DefaultNetCoreTargetFramework)` value changes.
+
+Typically, you want to focus on a single project within this large repo. For example,
 if you want to work on Blazor WebAssembly, you'll need to launch the solution file for that project by changing into the `src/Components`
 directory and executing `startvs.cmd` in that directory like so:
 
-```ps1
-PS1> cd src\Components
-PS1> .\startvs.cmd
+```powershell
+cd src\Components
+.\startvs.cmd
 ```
 
 After opening the solution in Visual Studio, you can build/rebuild using the controls in Visual Studio.
 
-> :exclamation: VS for Mac does not currently support opening .slnf files so you must use VS Code when developing on macOS. 
+> :exclamation: VS for Mac does not currently support opening .slnf files. So, you must use VS Code when developing on macOS.
 
 #### A brief interlude on solution files
 
@@ -173,7 +181,7 @@ We have a single .sln file for all of ASP.NET Core, but most people don't work w
 doesn't currently handle projects of this scale very well.
 
 Instead, we have many Solution Filter (.slnf) files which include a sub-set of projects. See the Visual Studio
-documentation [here](https://docs.microsoft.com/en-us/visualstudio/ide/filtered-solutions?view=vs-2019) for more
+documentation [here](https://docs.microsoft.com/visualstudio/ide/filtered-solutions) for more
 information about Solution Filters.
 
 These principles guide how we create and manage .slnf files:
@@ -194,9 +202,8 @@ Use these command to launch VS Code with the right settings.
 
 On Windows (requires PowerShell):
 
-```ps1
+```powershell
 # The extra dot at the beginning is required to 'dot source' this file into the right scope.
-
 . .\activate.ps1
 code .
 ```
@@ -211,15 +218,15 @@ code .
 > :bulb: Note that if you are using the "Remote-WSL" extension in VSCode, the environment is not supplied
 > to the process in WSL.  You can workaround this by explicitly setting the environment variables
 > in `~/.vscode-server/server-env-setup`.
-> See https://code.visualstudio.com/docs/remote/wsl#_advanced-environment-setup-script for details.
+> See <https://code.visualstudio.com/docs/remote/wsl#_advanced-environment-setup-script> for details.
 
-## Building on command-line
+### Building on command-line
 
 When developing in VS Code, you'll need to use the `build.cmd` or `build.sh` scripts in order to build the project. You can learn more about the command line options available, check out [the section below](using-dotnet-on-command-line-in-this-repo).
 
 On Windows:
 
-```ps1
+```powershell
 .\build.cmd
 ```
 
@@ -237,16 +244,15 @@ At this point, you will have all the dependencies installed and a code editor to
 
 The section below provides some helpful guides for using the `dotnet` CLI in the ASP.NET Core repo.
 
-## Using `dotnet` on command line in this repo
+### Using `dotnet` on command line in this repo
 
 Because we are using pre-release versions of .NET Core, you have to set a handful of environment variables
 to make the .NET Core command line tool work well. You can set these environment variables like this:
 
 On Windows (requires PowerShell):
 
-```ps1
+```powershell
 # The extra dot at the beginning is required to 'dot source' this file into the right scope.
-
 . .\activate.ps1
 ```
 
@@ -264,7 +270,7 @@ Tests are not run by default. Use the `-test` option to run tests in addition to
 
 On Windows:
 
-```ps1
+```powershell
 .\build.cmd -test
 ```
 
@@ -298,7 +304,7 @@ These scripts will build and test the projects within a specific directory. Furt
 
 Additional properties can be added as an argument in the form `/property:$name=$value`, or `/p:$name=$value` for short. For example:
 
-```ps1
+```powershell
 .\build.cmd -Configuration Release
 ```
 
@@ -310,14 +316,18 @@ Configuration            | `Debug` or `Release`. Default = `Debug`.
 TargetArchitecture       | The CPU architecture to build for (x64, x86, arm, arm64).
 TargetOsName             | The base runtime identifier to build for (win, linux, osx, linux-musl).
 
-### Use the result of your build
+### Resx files
+
+If you need to make changes to a .resx file, run `dotnet msbuild t:/Resgen <path to csproj>`. This will update the generated C#.
+
+## Step 5: Use the result of your build
 
 After building ASP.NET Core from source, you will need to install and use your local version of ASP.NET Core.
 See ["Artifacts"](./Artifacts.md) for more explanation of the different folders produced by a build.
 
 Building installers does not run as part of `build.cmd` run without parameters, so you should opt-in for building them:
 
-```ps1
+```powershell
 .\build.cmd -all -pack -arch x64
 .\build.cmd -all -pack -arch x86 -noBuildJava
 .\build.cmd -buildInstallers
@@ -325,8 +335,8 @@ Building installers does not run as part of `build.cmd` run without parameters,
 
 *Note*: Additional build steps listed above aren't necessary on Linux or macOS.
 
-* Run the installers produced in `artifacts/installers/{Debug, Release}/` for your platform.
-* Add a NuGet.Config to your project directory with the following content:
+- Run the installers produced in `artifacts/installers/{Debug, Release}/` for your platform.
+- Add a NuGet.Config to your project directory with the following content:
 
   ```xml
   <?xml version="1.0" encoding="utf-8"?>
@@ -341,7 +351,7 @@ Building installers does not run as part of `build.cmd` run without parameters,
 
   *NOTE: This NuGet.Config should be with your application unless you want nightly packages to potentially start being restored for other apps on the machine.*
 
-* Update the versions on `PackageReference` items in your .csproj project file to point to the version from your local build.
+- Update the versions on `PackageReference` items in your .csproj project file to point to the version from your local build.
 
   ```xml
   <ItemGroup>
@@ -352,55 +362,6 @@ Building installers does not run as part of `build.cmd` run without parameters,
 Some features, such as new target frameworks, may require prerelease tooling builds for Visual Studio.
 These are available in the [Visual Studio Preview](https://www.visualstudio.com/vs/preview/).
 
-## Resx files
-
-If you need to make changes to a .resx file, run `dotnet msbuild t:/Resgen <path to csproj>`. This will update the generated C#.
-
 ## Troubleshooting
 
-This section contains a troubleshooting guide for common issues you might run into while building the repo.
-
-### Common error: CS0006
-
-Opening solution filters and building may produce an error code CS0006 with a message such
-
-> Error CS0006 Metadata file 'C:\src\aspnet\AspNetCore\artifacts\bin\Microsoft.AspNetCore.Metadata\Debug\netstandard2.0\Microsoft.AspNetCore.Metadata.dll' could not be found
-
-The cause of this problem is that the solution filter you are using does not include the project that produces this .dll. This most often occurs after we have added new projects to the repo, but failed to update our .sln/slnf files to include the new project. In some cases, it is sometimes the intended behavior of the .slnf which has been crafted to only include a subset of projects.
-
-#### You can fix this in one of three ways
-
-1. Build the project on command line. In most cases, running `build.cmd` on command line solves this problem.
-2. If the project is missing from the .sln file entirely, you can use `dotnet sln add` to add it, or else right click on the solution/folder in Visual Studio and choose Add->Existing Project, and adding it.
-3. If it is present in the .sln, but not the .slnf, you can update the solution filter to include the missing project. You can either do this one by right-clicking on project in Visual Studio and choosing to load it's direct dependencies, and then saving.  Alternatively, you can hand edit the .slnf file - it's a fairly simple json format.
-
-### Common error: Unable to locate the .NET Core SDK
-
-Executing `.\restore.cmd` or `.\build.cmd` may produce these errors:
-
-> error : Unable to locate the .NET Core SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version.
-> error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.
-
-In most cases, this is because the option _Use previews of the .NET Core SDK_ in VS2019 is not checked. Start Visual Studio, go to _Tools > Options_ and check _Use previews of the .NET Core SDK_ under _Environment > Preview Features_.
-
-### Common error: HTTP Error 500.33 - ANCM Request Handler Load Failure
-
-The [ASP.NET Core Module](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module) (ANCM) for IIS is not supported when running projects in this repository.
-
-After using `startvs.cmd` to open a solution in Visual Studio, the Kestrel web host option must be used (name of the project) and not IIS Express.
-
-Example of running the `MvcSandbox` project:
-
-`.\startvs.cmd .\src\Mvc\Mvc.sln`
-
-![Web host options in Visual Studio](./vs-iis-express-aspnet-core-mvc-sandbox.jpg)
-
-### Common error: error : Unable to load the service index for &hellip;
-
-When attempting to restore servicing tags e.g. `v3.1.7`,  the NuGet.config file may contain internal feeds that are not accessible. This will result in errors such as
-
-``` text
-...\aspnetcore\.dotnet\sdk\3.1.103\NuGet.targets(123,5): error : Unable to load the service index for source https://pkgs.dev.azure.com/dnceng/_packaging/darc-int-dotnet-extensions-784b0ffa/nuget/v3/index.json. [...\Temp\1gsd3rdo.srb\restore.csproj] [...\.nuget\packages\microsoft.dotnet.arcade.sdk\1.0.0-beta.20213.4\tools\Tools.proj]
-```
-
-The `darc-int-...` feeds in NuGet.config are used only when building internally and are not needed after the tags are created. Delete all such entries in the file and retry.
+See [BuildErrors](./BuildErrors.md) for a description of common issues you might run into while building the repo.

+ 0 - 19
eng/Workarounds.targets

@@ -1,10 +1,5 @@
 <!-- Use this file to workaround issues. List the issue tracking the item to fix so we can remove the workaround when the issue is resolved. -->
 <Project>
-  <!-- Workaround while there is no 6.0 SDK available, suppress unsupported version error -->
-  <PropertyGroup>
-    <NETCoreAppMaximumVersion>6.0</NETCoreAppMaximumVersion>
-  </PropertyGroup>
-
   <ItemGroup>
     <!-- Reference base shared framework at incoming dependency flow version, not bundled sdk version. -->
     <FrameworkReference
@@ -41,20 +36,6 @@
     <PackageReference Include="Internal.AspNetCore.BuildTasks" PrivateAssets="All" Version="$(InternalAspNetCoreBuildTasksVersion)" IsImplicitlyDefined="true" />
   </ItemGroup>
 
-  <ItemGroup>
-    <!-- Workaround when there is no vNext SDK available, copy known apphost/framework reference info from 5.0 -->
-    <KnownAppHostPack
-      Include="@(KnownAppHostPack->WithMetadataValue('TargetFramework', 'netcoreapp5.0'))"
-      TargetFramework="$(KnownAppHostPackOrFrameworkReferenceTfm)"
-      Condition="@(KnownAppHostPack->Count()) != '0' AND !(@(KnownAppHostPack->AnyHaveMetadataValue('TargetFramework', '$(KnownAppHostPackOrFrameworkReferenceTfm)')))"
-      />
-    <KnownFrameworkReference
-      Include="@(KnownFrameworkReference->WithMetadataValue('TargetFramework', 'netcoreapp5.0'))"
-      TargetFramework="$(KnownAppHostPackOrFrameworkReferenceTfm)"
-      Condition="@(KnownFrameworkReference->Count()) != '0' AND !(@(KnownFrameworkReference->AnyHaveMetadataValue('TargetFramework', '$(KnownAppHostPackOrFrameworkReferenceTfm)')))"
-      />
-  </ItemGroup>
-
   <!-- Workaround for netstandard2.1 projects until we can get a preview 8 SDK containing https://github.com/dotnet/sdk/pull/3463 fix. -->
   <ItemGroup>
     <KnownFrameworkReference Update="NETStandard.Library">

+ 0 - 1
eng/tools/GenerateFiles/Directory.Build.props.in

@@ -1,7 +1,6 @@
 <Project>
   <PropertyGroup>
     <DefaultNetCoreTargetFramework>${DefaultNetCoreTargetFramework}</DefaultNetCoreTargetFramework>
-    <TargetFramework>${DefaultNetCoreTargetFramework}</TargetFramework>
     <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
   </PropertyGroup>
 </Project>

+ 67 - 18
eng/tools/GenerateFiles/Directory.Build.targets.in

@@ -2,43 +2,92 @@
   <PropertyGroup>
     <!-- Workaround while there is no SDK available that understands the TFM; suppress unsupported version errors. -->
     <NETCoreAppMaximumVersion>99.9</NETCoreAppMaximumVersion>
+
+    <UpdateAspNetCoreKnownFramework
+      Condition=" '$(UpdateAspNetCoreKnownFramework)' == '' ">true</UpdateAspNetCoreKnownFramework>
   </PropertyGroup>
 
+  <!-- Workaround when there is no vNext SDK available; copy known apphost/framework reference info from 5.0. -->
   <ItemGroup>
-    <!-- Workaround when there is no vNext SDK available; copy known apphost/framework reference info from 5.0. -->
     <KnownAppHostPack
       Include="@(KnownAppHostPack->WithMetadataValue('TargetFramework', 'netcoreapp5.0'))"
       TargetFramework="${KnownAppHostPackOrFrameworkReferenceTfm}"
-      Condition="@(KnownAppHostPack->Count()) != '0' AND !(@(KnownAppHostPack->AnyHaveMetadataValue('TargetFramework', '${KnownAppHostPackOrFrameworkReferenceTfm}')))"
-      />
+      Condition="@(KnownAppHostPack->Count()) != '0' AND
+        !(@(KnownAppHostPack->AnyHaveMetadataValue('TargetFramework', '${KnownAppHostPackOrFrameworkReferenceTfm}')))" />
     <KnownFrameworkReference
       Include="@(KnownFrameworkReference->WithMetadataValue('TargetFramework', 'netcoreapp5.0'))"
       TargetFramework="${KnownAppHostPackOrFrameworkReferenceTfm}"
-      Condition="@(KnownFrameworkReference->Count()) != '0' AND !(@(KnownFrameworkReference->AnyHaveMetadataValue('TargetFramework', '${KnownAppHostPackOrFrameworkReferenceTfm}')))"
-      />
+      Condition="@(KnownFrameworkReference->Count()) != '0' AND
+        !(@(KnownFrameworkReference->AnyHaveMetadataValue('TargetFramework', '${KnownAppHostPackOrFrameworkReferenceTfm}')))" />
   </ItemGroup>
 
   <ItemGroup>
-    <!-- Use the same NETCore shared framework as repo built against. -->
+    <!-- Use the same NETCore shared framework as repo built against except when building product code in servicing. -->
     <KnownFrameworkReference
-      Update="@(KnownFrameworkReference->WithMetadataValue('Identity', 'Microsoft.NETCore.App')->WithMetadataValue('TargetFramework', '${KnownAppHostPackOrFrameworkReferenceTfm}'))"
-      DefaultRuntimeFrameworkVersion="${MicrosoftNETCoreAppRuntimeVersion}"
-      LatestRuntimeFrameworkVersion="${MicrosoftNETCoreAppRuntimeVersion}"
-      TargetingPackVersion="${MicrosoftNETCoreAppRefVersion}" />
+        Update="@(KnownFrameworkReference->WithMetadataValue('Identity', 'Microsoft.NETCore.App')->WithMetadataValue('TargetFramework', '${KnownAppHostPackOrFrameworkReferenceTfm}'))"
+        LatestRuntimeFrameworkVersion="${MicrosoftNETCoreAppRuntimeVersion}">
+      <!--
+        Change the default shared framework and targeting pack version only when _not_ servicing. Avoid bumping
+        version used in most projects. When servicing, projects can use $(TargetLatestRuntimePatch) to explicitly
+        control whether assemblies build against default (false) or latest (true). When that property is not set, SDK
+        uses default metadata in most cases but published apps e.g. tool projects (again, property not set) use latest.
+
+        !temporary! Also check $(TargetLatestRuntimePatch) here because these metadata changes otherwise increase the
+        minimum versions, making $(TargetLatestRuntimePatch) irrelevant. This helps to avoid problems with current
+        `[assembly: AssemblyVersion(...)]` changes in dotnet/runtime assemblies and our MSBuild tasks.
+      -->
+      <DefaultRuntimeFrameworkVersion Condition=" '$(IsServicingBuild)' != 'true' AND
+          '$(TargetLatestDotNetRuntime)' != 'false' ">${MicrosoftNETCoreAppRuntimeVersion}</DefaultRuntimeFrameworkVersion>
+      <TargetingPackVersion Condition=" '$(IsServicingBuild)' != 'true' AND
+          '$(TargetLatestDotNetRuntime)' != 'false' ">${MicrosoftNETCoreAppRefVersion}</TargetingPackVersion>
+    </KnownFrameworkReference>
 
-    <!-- Use the just-built ASP.NET Core shared framework. -->
+    <!-- Use the just-built ASP.NET Core shared framework if available except when building product code in servicing. -->
     <KnownFrameworkReference
-      Update="@(KnownFrameworkReference->WithMetadataValue('Identity', 'Microsoft.AspNetCore.App')->WithMetadataValue('TargetFramework', '${KnownAppHostPackOrFrameworkReferenceTfm}'))"
-      DefaultRuntimeFrameworkVersion="${MicrosoftAspNetCoreAppRuntimeVersion}"
-      LatestRuntimeFrameworkVersion="${MicrosoftAspNetCoreAppRuntimeVersion}"
-      TargetingPackVersion="${MicrosoftAspNetCoreAppRefVersion}"
-      RuntimePackRuntimeIdentifiers="${SupportedRuntimeIdentifiers}" />
-  </ItemGroup>
+        Update="@(KnownFrameworkReference->WithMetadataValue('Identity', 'Microsoft.AspNetCore.App')->WithMetadataValue('TargetFramework', '${KnownAppHostPackOrFrameworkReferenceTfm}'))"
+        Condition=" $(UpdateAspNetCoreKnownFramework) "
+        LatestRuntimeFrameworkVersion="${MicrosoftAspNetCoreAppRuntimeVersion}"
+        RuntimePackRuntimeIdentifiers="${SupportedRuntimeIdentifiers}">
+      <DefaultRuntimeFrameworkVersion
+          Condition=" '$(IsServicingBuild)' != 'true' ">${MicrosoftAspNetCoreAppRuntimeVersion}</DefaultRuntimeFrameworkVersion>
+      <TargetingPackVersion
+          Condition=" '$(IsServicingBuild)' != 'true' ">${MicrosoftAspNetCoreAppRefVersion}</TargetingPackVersion>
+    </KnownFrameworkReference>
 
-  <ItemGroup Condition="$(BuildingTestAppsIndependently) == 'false'">
     <PackageReference Include="Microsoft.Net.Compilers.Toolset"
       Version="${MicrosoftNetCompilersToolsetVersion}"
       PrivateAssets="all"
       IsImplicitlyDefined="true" />
   </ItemGroup>
+
+  <!-- Warn if the "just-built" ASP.NET Core shared framework does not exist. -->
+  <Target Name="WarnAboutMissingSharedFramework"
+      BeforeTargets="Restore;Build;Rebuild;RunTests;Test;VSTest;Pack"
+      Condition=" $(UpdateAspNetCoreKnownFramework) ">
+    <PropertyGroup>
+      <!--
+        Property (already normalized) from Arcade SDK's RepoLayout.props. This covers all projects using the
+        Arcade SDK. Ignore $(LocalDotNetRoot) because that is set in root Directory.Build.props (where Arcade SDK
+        is imported) and therefore doesn't cover additional projects.
+      -->
+      <_DotNetRoot Condition=" '$(DotNetRoot)' != '' ">$(DotNetRoot)</_DotNetRoot>
+      <!--
+        Environment variable from eng/common/tools.ps1 scripts. This covers tests and assets that do not use the
+        Arcade SDK but are run from our build.* scripts.
+      -->
+      <_DotNetRoot Condition=" '$(_DotNetRoot)' == '' AND
+          '$(DOTNET_INSTALL_DIR)' != '' ">$([MSBuild]::NormalizeDirectory('$(DOTNET_INSTALL_DIR)'))</_DotNetRoot>
+      <!--
+        Environment variable from root activate.* and Helix runtest.* scripts. This covers tests and assets on
+        Helix agents and when run locally using 'msbuild' after activation.
+      -->
+      <_DotNetRoot Condition=" '$(_DotNetRoot)' == '' AND
+          '$(DOTNET_ROOT)' != '' ">$([MSBuild]::NormalizeDirectory('$(DOTNET_ROOT)'))</_DotNetRoot>
+    </PropertyGroup>
+
+    <Error Text="Unable to determine dotnet root location." Condition=" '$(_DotNetRoot)' == '' " />
+    <Error Text="Dotnet root location '$(_DotNetRoot)' does not exist." Condition=" !EXISTS('$(_DotNetRoot)') " />
+    <Warning Text="Requested Microsoft.AspNetCore.App v${MicrosoftAspNetCoreAppRuntimeVersion} does not exist."
+        Condition=" !EXISTS('$(_DotNetRoot)shared\Microsoft.AspNetCore.App\${MicrosoftAspNetCoreAppRuntimeVersion}') " />
+  </Target>
 </Project>

+ 2 - 1
eng/tools/GenerateFiles/GenerateFiles.csproj

@@ -1,6 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
-    <TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
+    <!-- Use fixed version instead of $(DefaultNetCoreTargetFramework) to avoid needing workarounds set up here. -->
+    <TargetFramework>net5.0</TargetFramework>
   </PropertyGroup>
 
   <!-- Update artifacts/bin/GenerateFiles/Directory.Build.* files. -->

+ 4 - 4
src/Components/WebAssembly/Sdk/integrationtests/Microsoft.NET.Sdk.BlazorWebAssembly.IntegrationTests.csproj

@@ -10,7 +10,7 @@
     <TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
     <PreserveCompilationContext>true</PreserveCompilationContext>
 
-    <!-- Tests do not work on Helix yet -->
+    <!-- Tests do not work on Helix yet. When enabled, add Publish to BeforeTargets of RestoreTestProjects. -->
     <BuildHelixPayload>false</BuildHelixPayload>
     <TestAppsRoot>$(MSBuildProjectDirectory)\..\testassets\</TestAppsRoot>
   </PropertyGroup>
@@ -32,8 +32,8 @@
     <Reference Include="Microsoft.NET.Sdk.Razor" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" />
   </ItemGroup>
 
-  <!-- Ensure shared framework and targeting packs are laid out under .dotnet/ before executing non-Helix tests. -->
-  <ItemGroup Condition=" '$(ASPNETCORE_TEST_LOG_DIR)' == '' AND '$(IsHelixJob)' != 'true' ">
+  <!-- Ensure shared framework and targeting packs are laid out under .dotnet/ before executing tests. -->
+  <ItemGroup Condition=" '$(DotNetBuildFromSource)' != 'true' ">
     <ProjectReference Include="$(RepoRoot)src\Framework\App.Ref\src\Microsoft.AspNetCore.App.Ref.csproj"
         Condition=" $(IsTargetingPackBuilding) "
         ReferenceOutputAssembly="false"
@@ -73,7 +73,7 @@
     </ItemGroup>
   </Target>
 
-  <Target Name="RestoreTestProjects" BeforeTargets="RunTests;Test;VSTest" Condition="'$(DotNetBuildFromSource)' != 'true'">
+  <Target Name="RestoreTestProjects" BeforeTargets="RunTests;Test;VSTest" Condition=" '$(DotNetBuildFromSource)' != 'true' ">
     <MSBuild Projects="..\testassets\RestoreBlazorWasmTestProjects\RestoreBlazorWasmTestProjects.csproj" Targets="Restore" />
   </Target>
 

+ 0 - 7
src/Components/WebAssembly/Sdk/testassets/Directory.Build.props

@@ -10,13 +10,6 @@
   <Import Project="$(ArtifactsBinDir)GenerateFiles\Directory.Build.props" />
 
   <PropertyGroup>
-    <!--
-      In the case that a user is building a sample directly the MicrosoftNetCompilersToolsetPackagerVersion will not be provided.
-      We'll fall back to whatever the current SDK provides in regards to Roslyn's Microsoft.Net.Compilers.Toolset.
-    -->
-    <BuildingTestAppsIndependently>false</BuildingTestAppsIndependently>
-    <BuildingTestAppsIndependently Condition="'$(MicrosoftNetCompilersToolsetVersion)' == ''">true</BuildingTestAppsIndependently>
-
     <!-- Do not resolve Reference ItemGroup since it has a different semantic meaning in Razor test apps -->
     <EnableCustomReferenceResolution>false</EnableCustomReferenceResolution>
 

+ 10 - 7
src/Framework/App.Runtime/src/Microsoft.AspNetCore.App.Runtime.csproj

@@ -176,14 +176,14 @@ This package is an internal implementation of the .NET Core SDK and is not meant
       GenerateSharedFxDepsFile;
       GenerateSharedFxVersionsFiles;
       Crossgen;
-      _ResolveSharedFrameworkContent;
       IncludeFrameworkListFile;
+      _ResolveSharedFrameworkContent;
+      _InstallFrameworkIntoLocalDotNet;
       _DownloadAndExtractDotNetRuntime;
       _BatchCopyToSharedFrameworkLayout;
       _BatchCopyToRedistLayout;
       _CreateInternalSharedFxArchive;
       _CreateRedistSharedFxArchive;
-      _InstallFrameworkIntoLocalDotNet;
     </CoreBuildDependsOn>
     <CrossGenDependsOn>
       ResolveReferences;
@@ -485,8 +485,9 @@ This package is an internal implementation of the .NET Core SDK and is not meant
 
   <!-- Required to workaround https://github.com/dotnet/core-setup/issues/4809. This copies the shared framework into the $reporoot/.dotnet folder so tests can run against the shared framework. -->
   <!-- This workaround is not needed in source build -->
-  <Target Condition="'$(DotNetBuildFromSource)' != 'true'"
-          Name="_InstallFrameworkIntoLocalDotNet"
+  <Target Name="_InstallFrameworkIntoLocalDotNet"
+          DependsOnTargets="_ResolveSharedFrameworkContent"
+          Condition="'$(DotNetBuildFromSource)' != 'true'"
           Inputs="@(SharedFxContent)"
           Outputs="@(SharedFxContent->'$(LocalInstallationOutputPath)%(FileName)%(Extension)')">
 
@@ -497,9 +498,9 @@ This package is an internal implementation of the .NET Core SDK and is not meant
   </Target>
 
   <Target Name="_CreateInternalSharedFxArchive"
+          DependsOnTargets="_BatchCopyToSharedFrameworkLayout"
           Inputs="@(SharedFxContent)"
           Outputs="$(InternalArchiveOutputPath)">
-    <Message Importance="High" Text="$(MSbuildProjectFile) -> $(InternalArchiveOutputPath)" />
     <ZipDirectory
       SourceDirectory="$(SharedFrameworkLayoutRoot)"
       DestinationFile="$(InternalArchiveOutputPath)"
@@ -509,11 +510,13 @@ This package is an internal implementation of the .NET Core SDK and is not meant
       Command="tar -czf $(InternalArchiveOutputPath) ."
       WorkingDirectory="$(SharedFrameworkLayoutRoot)"
       Condition="'$(ArchiveExtension)' == '.tar.gz'" />
+    <Message Importance="High" Text="$(MSbuildProjectFile) -> $(InternalArchiveOutputPath)" />
   </Target>
 
   <!-- Redist tarball including the dotnet-runtime is not needed in source build -->
-  <Target Condition="'$(DotNetBuildFromSource)' != 'true'"
-          Name="_CreateRedistSharedFxArchive"
+  <Target Name="_CreateRedistSharedFxArchive"
+          DependsOnTargets="_DownloadAndExtractDotNetRuntime;_BatchCopyToRedistLayout"
+          Condition="'$(DotNetBuildFromSource)' != 'true'"
           Inputs="@(SharedFxContent)"
           Outputs="$(RedistArchiveOutputPath)">
     <Message Importance="High" Text="$(MSbuildProjectFile) -> $(RedistArchiveOutputPath)" />

+ 2 - 1
src/Framework/Directory.Build.props

@@ -15,7 +15,8 @@
   <ItemGroup>
     <FrameworkListRootAttributes Include="Name" Value="$(AspNetCoreAppFrameworkBrandName)" />
     <FrameworkListRootAttributes Include="TargetFrameworkIdentifier" Value="$(NETCoreAppFrameworkIdentifier)" />
-    <FrameworkListRootAttributes Include="TargetFrameworkVersion" Value="$(DefaultNetCoreTargetFramework.Substring(3))" />
+    <FrameworkListRootAttributes Include="TargetFrameworkVersion"
+      Value="$([MSBuild]::GetTargetFrameworkVersion('$(DefaultNetCoreTargetFramework)', 2))" />
     <FrameworkListRootAttributes Include="FrameworkName" Value="$(SharedFxName)" />
   </ItemGroup>
 

+ 1 - 100
src/ProjectTemplates/BlazorTemplates.Tests/BlazorTemplates.Tests.csproj

@@ -21,7 +21,6 @@
     <!-- TestTemplateCreationFolder is the folder where the templates will be created. Will point out to $(OutputDir)$(TestTemplateCreationFolder) -->
     <TestTemplateCreationFolder>TestTemplates\</TestTemplateCreationFolder>
     <TestPackageRestorePath>$([MSBuild]::EnsureTrailingSlash('$(RepoRoot)'))obj\template-restore\</TestPackageRestorePath>
-    <TestTemplateTestsProps>TemplateTests.props</TestTemplateTestsProps>
     <TestDependsOnAspNetRuntime>true</TestDependsOnAspNetRuntime>
   </PropertyGroup>
 
@@ -42,105 +41,7 @@
     <Reference Include="Microsoft.NET.Sdk.Razor" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" />
   </ItemGroup>
 
-  <ItemGroup>
-    <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
-      <_Parameter1>DotNetEfFullPath</_Parameter1>
-      <_Parameter2>$([MSBuild]::EnsureTrailingSlash('$(NuGetPackageRoot)'))dotnet-ef/$(DotnetEfVersion)/tools/netcoreapp3.1/any/dotnet-ef.dll</_Parameter2>
-    </AssemblyAttribute>
-    <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
-      <_Parameter1>TestPackageRestorePath</_Parameter1>
-      <_Parameter2>$(TestPackageRestorePath)</_Parameter2>
-    </AssemblyAttribute>
-    <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
-      <_Parameter1>Test.DefaultTargetFramework</_Parameter1>
-      <_Parameter2>$(DefaultNetCoreTargetFramework)</_Parameter2>
-    </AssemblyAttribute>
-    <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(ContinuousIntegrationBuild)' == 'true'">
-      <_Parameter1>ContinuousIntegrationBuild</_Parameter1>
-      <_Parameter2>true</_Parameter2>
-    </AssemblyAttribute>
-  </ItemGroup>
-
-  <Target Name="PrepareForTest" BeforeTargets="GetAssemblyAttributes" Condition="$(DesignTimeBuild) != true">
-    <PropertyGroup>
-      <TestTemplateCreationFolder>$([MSBuild]::NormalizePath('$(OutputPath)$(TestTemplateCreationFolder)'))</TestTemplateCreationFolder>
-      <TestTemplateTestsProps>$(TestTemplateCreationFolder)$(TestTemplateTestsProps)</TestTemplateTestsProps>
-      <CustomTemplateHivePath>$(TestTemplateCreationFolder)\Hives\$([System.Guid]::NewGuid())\.templateengine</CustomTemplateHivePath>
-    </PropertyGroup>
-
-    <ItemGroup>
-      <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
-        <_Parameter1>ArtifactsShippingPackagesDir</_Parameter1>
-        <_Parameter2>$(ArtifactsShippingPackagesDir)</_Parameter2>
-      </AssemblyAttribute>
-
-      <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
-        <_Parameter1>ArtifactsLogDir</_Parameter1>
-        <_Parameter2>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'log'))</_Parameter2>
-      </AssemblyAttribute>
-
-      <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
-        <_Parameter1>ArtifactsNonShippingPackagesDir</_Parameter1>
-        <_Parameter2>$(ArtifactsNonShippingPackagesDir)</_Parameter2>
-      </AssemblyAttribute>
-
-      <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
-        <_Parameter1>TestTemplateCreationFolder</_Parameter1>
-        <_Parameter2>$(TestTemplateCreationFolder)</_Parameter2>
-      </AssemblyAttribute>
-      <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
-        <_Parameter1>CustomTemplateHivePath</_Parameter1>
-        <_Parameter2>$(CustomTemplateHivePath)</_Parameter2>
-      </AssemblyAttribute>
-    </ItemGroup>
-
-    <Message Importance="high" Text="Preparing environment for tests" />
-    <!-- Remove the template creation folders and the package-restore folders to ensure that when we run the tests we don't
-         get cached results and changes show up.
-    -->
-
-    <ItemGroup>
-      <_ExistingFilesFromLastRun Include="$(TestTemplateCreationFolder)**\*" />
-    </ItemGroup>
-
-    <Delete Files="@(_ExistingFilesFromLastRun)" ContinueOnError="true" />
-
-    <Removedir Directories="$(TestTemplateCreationFolder)" Condition="Exists('$(TestTemplateCreationFolder)')" ContinueOnError="true">
-      <Output TaskParameter="RemovedDirectories" ItemName="_CleanedUpDirectories" />
-    </Removedir>
-    <Removedir Directories="$(TestPackageRestorePath)" Condition="Exists('$(TestPackageRestorePath)')" ContinueOnError="true">
-      <Output TaskParameter="RemovedDirectories" ItemName="_CleanedUpDirectories" />
-    </Removedir>
-
-    <Message Importance="high" Text="Removed directory %(_CleanedUpDirectories.Identity)" />
-
-    <MakeDir Directories="$(TestTemplateCreationFolder)">
-      <Output TaskParameter="DirectoriesCreated" ItemName="_CreatedDirectories" />
-    </MakeDir>
-    <MakeDir Directories="$(TestPackageRestorePath)">
-      <Output TaskParameter="DirectoriesCreated" ItemName="_CreatedDirectories" />
-    </MakeDir>
-
-    <Message Importance="high" Text="Created directory %(_CreatedDirectories.Identity)" />
-
-    <GenerateFileFromTemplate
-      TemplateFile="$(MSBuildThisFileDirectory)Infrastructure\Directory.Build.targets.in"
-      Properties="TemplateTestsPropsPath=$(TestTemplateTestsProps)"
-      OutputPath="$(TestTemplateCreationFolder)Directory.Build.targets" />
-
-    <GenerateFileFromTemplate
-      TemplateFile="$(MSBuildThisFileDirectory)Infrastructure\Directory.Build.props.in"
-      Properties="RepoRoot=$(RepoRoot);DefaultNetCoreTargetFramework=$(DefaultNetCoreTargetFramework)"
-      OutputPath="$(TestTemplateCreationFolder)Directory.Build.props" />
-
-    <!-- Workaround https://github.com/dotnet/core-setup/issues/6420 - there is no MSBuild setting for rollforward yet -->
-    <Copy SourceFiles="$(MSBuildThisFileDirectory)Infrastructure\runtimeconfig.norollforward.json" DestinationFolder="$(TestTemplateCreationFolder)" UseHardLinksIfPossible="true" />
-
-    <Delete Files="$(TestTemplateTestsProps)" />
-
-  </Target>
-
   <!-- Shared testing infrastructure for running E2E tests using selenium -->
   <Import Project="$(SharedSourceRoot)E2ETesting\E2ETesting.targets" />
-
+  <Import Project="..\TestInfrastructure\PrepareForTest.targets" />
 </Project>

+ 0 - 4
src/ProjectTemplates/BlazorTemplates.Tests/Directory.Build.targets

@@ -1,4 +0,0 @@
-<Project>
-  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, Directory.Build.targets))\Directory.Build.targets" />
-  <Import Project="$(MSBuildThisFileDirectory)Infrastructure\GenerateTestProps.targets" />
-</Project>

+ 0 - 8
src/ProjectTemplates/BlazorTemplates.Tests/Infrastructure/Directory.Build.props.in

@@ -1,8 +0,0 @@
-<Project>
-<!-- This file gets copied above the template test projects so that we disconnect the templates from the rest of the repository -->
-  <PropertyGroup>
-    <TargetFramework>${DefaultNetCoreTargetFramework}</TargetFramework>
-  </PropertyGroup>
-  <Import Project="${RepoRoot}src\Components\WebAssembly\Sdk\src\build\${DefaultNetCoreTargetFramework}\Microsoft.NET.Sdk.BlazorWebAssembly.props" Condition="'$(UsingMicrosoftNETSdkBlazorWebAssembly)' == 'true'" />
-
-</Project>

+ 0 - 3
src/ProjectTemplates/BlazorTemplates.Tests/Infrastructure/Directory.Build.targets.in

@@ -1,3 +0,0 @@
-<Project>
-  <Import Project="${TemplateTestsPropsPath}" />
-</Project>

+ 0 - 30
src/ProjectTemplates/BlazorTemplates.Tests/Infrastructure/GenerateTestProps.targets

@@ -1,30 +0,0 @@
-<Project>
-  <Target Name="GenerateTestProps"
-      BeforeTargets="CoreCompile"
-      DependsOnTargets="PrepareForTest"
-      Condition="$(DesignTimeBuild) != true">
-    <PropertyGroup>
-      <PropsProperties>
-        RestoreAdditionalProjectSources=$([MSBuild]::Escape("$(RestoreAdditionalProjectSources);$(ArtifactsShippingPackagesDir);$(ArtifactsNonShippingPackagesDir)"));
-        MicrosoftNetCompilersToolsetVersion=$(MicrosoftNetCompilersToolsetVersion);
-        MicrosoftNETCoreAppRuntimeVersion=$(MicrosoftNETCoreAppRuntimeVersion);
-        MicrosoftNETCoreAppRefVersion=$(MicrosoftNETCoreAppRefVersion);
-        MicrosoftNETCorePlatformsVersion=$(MicrosoftNETCorePlatformsVersion);
-        MicrosoftNETSdkRazorVersion=$(MicrosoftNETSdkRazorVersion);
-        MicrosoftAspNetCoreAppRefVersion=$(TargetingPackVersion);
-        MicrosoftAspNetCoreAppRuntimeVersion=$(SharedFxVersion);
-        SupportedRuntimeIdentifiers=$(SupportedRuntimeIdentifiers.Trim());
-        DefaultNetCoreTargetFramework=$(DefaultNetCoreTargetFramework);
-        KnownAppHostPackOrFrameworkReferenceTfm=$(KnownAppHostPackOrFrameworkReferenceTfm);
-        RepoRoot=$(RepoRoot);
-        Configuration=$(Configuration);
-        ArtifactsBinDir=$(ArtifactsBinDir);
-      </PropsProperties>
-    </PropertyGroup>
-
-    <GenerateFileFromTemplate
-      TemplateFile="$(MSBuildThisFileDirectory)\TemplateTests.props.in"
-      Properties="$(PropsProperties)"
-      OutputPath="$(TestTemplateTestsProps)" />
-  </Target>
-</Project>

+ 0 - 58
src/ProjectTemplates/BlazorTemplates.Tests/Infrastructure/TemplateTests.props.in

@@ -1,58 +0,0 @@
-<Project>
-  <PropertyGroup>
-    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
-    <RestoreAdditionalProjectSources>${RestoreAdditionalProjectSources}</RestoreAdditionalProjectSources>
-
-    <!-- This sets an option which prevents the tests from rolling forward into a newer shared framework. -->
-    <UserRuntimeConfig>$(MSBuildThisFileDirectory)runtimeconfig.norollforward.json</UserRuntimeConfig>
-    <!-- Workaround while there is no 6.0 SDK available, suppress unsupported version error -->
-    <NETCoreAppMaximumVersion>6.0</NETCoreAppMaximumVersion>
-  </PropertyGroup>
-
-  <ItemGroup>
-    <KnownFrameworkReference
-      Update="Microsoft.NETCore.App"
-      DefaultRuntimeFrameworkVersion="${MicrosoftNETCoreAppRuntimeVersion}"
-      LatestRuntimeFrameworkVersion="${MicrosoftNETCoreAppRuntimeVersion}"
-      TargetingPackVersion="${MicrosoftNETCoreAppRefVersion}" />
-
-    <KnownFrameworkReference
-      Update="Microsoft.AspNetCore.App"
-      DefaultRuntimeFrameworkVersion="${MicrosoftAspNetCoreAppRuntimeVersion}"
-      LatestRuntimeFrameworkVersion="${MicrosoftAspNetCoreAppRuntimeVersion}"
-      TargetingPackVersion="${MicrosoftAspNetCoreAppRefVersion}"
-      RuntimePackRuntimeIdentifiers="${SupportedRuntimeIdentifiers}" />
-  </ItemGroup>
-
-  <ItemGroup>
-    <!-- Workaround when there is no vNext SDK available, copy known apphost/framework reference info from 5.0 -->
-    <KnownAppHostPack
-      Include="@(KnownAppHostPack->WithMetadataValue('TargetFramework', 'netcoreapp5.0'))"
-      TargetFramework="${KnownAppHostPackOrFrameworkReferenceTfm}"
-      Condition="@(KnownAppHostPack->Count()) != '0' AND !(@(KnownAppHostPack->AnyHaveMetadataValue('TargetFramework', '${KnownAppHostPackOrFrameworkReferenceTfm}')))"
-      />
-    <KnownFrameworkReference
-      Include="@(KnownFrameworkReference->WithMetadataValue('TargetFramework', 'netcoreapp5.0'))"
-      TargetFramework="${KnownAppHostPackOrFrameworkReferenceTfm}"
-      Condition="@(KnownFrameworkReference->Count()) != '0' AND !(@(KnownFrameworkReference->AnyHaveMetadataValue('TargetFramework', '${KnownAppHostPackOrFrameworkReferenceTfm}')))"
-      />
-  </ItemGroup>
-
-  <ItemGroup>
-    <PackageReference Include="Microsoft.Net.Compilers.Toolset"
-      Version="${MicrosoftNetCompilersToolsetVersion}"
-      PrivateAssets="all"
-      IsImplicitlyDefined="true" />
-  </ItemGroup>
-
-  <!--
-    Use the Razor SDK as a project reference. The version of the .NET Core SDK we build with often contains a version of the Razor SDK
-    several versions older than latest. To avoid a cyclical dependency, this package reference is added to override the bundled version.
-    Since this is a project reference, we must explicitly import the props file and also specify the output location of the SDK directory.
-  -->
-  <PropertyGroup>
-    <RazorSdkDirectoryRoot>${ArtifactsBinDir}Microsoft.NET.Sdk.Razor\${Configuration}\sdk-output\</RazorSdkDirectoryRoot>
-    <BlazorWebAssemblySdkDirectoryRoot>${ArtifactsBinDir}Microsoft.NET.Sdk.BlazorWebAssembly\${Configuration}\sdk-output\</BlazorWebAssemblySdkDirectoryRoot>
-  </PropertyGroup>
-  <Import Project="${RepoRoot}src\Razor\Microsoft.NET.Sdk.Razor\src\build\netstandard2.0\Microsoft.NET.Sdk.Razor.props" Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true' OR '$(RazorSdkCurrentVersionProps)' != ''" />
-</Project>

+ 12 - 0
src/ProjectTemplates/TestInfrastructure/Directory.Build.props.in

@@ -0,0 +1,12 @@
+<Project>
+  <!-- This file gets copied above the template test projects so that we disconnect the templates from the rest of the repository. -->
+  <PropertyGroup>
+    <RepoRoot>${RepoRoot}</RepoRoot>
+    <ArtifactsBinDir>${ArtifactsBinDir}</ArtifactsBinDir>
+  </PropertyGroup>
+
+  <Import Project="${ArtifactsBinDir}GenerateFiles\Directory.Build.props" />
+
+  <Import Project="${RepoRoot}src\Components\WebAssembly\Sdk\src\build\$(DefaultNetCoreTargetFramework)\Microsoft.NET.Sdk.BlazorWebAssembly.props"
+      Condition="'$(UsingMicrosoftNETSdkBlazorWebAssembly)' == 'true'" />
+</Project>

+ 22 - 0
src/ProjectTemplates/TestInfrastructure/Directory.Build.targets.in

@@ -0,0 +1,22 @@
+<Project>
+  <Import Project="$(ArtifactsBinDir)GenerateFiles\Directory.Build.targets" />
+
+  <PropertyGroup>
+    <RestoreAdditionalProjectSources>${RestoreAdditionalProjectSources}</RestoreAdditionalProjectSources>
+    <!-- This sets an option which prevents the tests from rolling forward into a newer shared framework. -->
+    <UserRuntimeConfig>$(MSBuildThisFileDirectory)runtimeconfig.norollforward.json</UserRuntimeConfig>
+  </PropertyGroup>
+
+  <!--
+    The version of the .NET Core SDK we build with often contains a version of the Razor SDK several versions older
+    than latest. We reference the project (see CSharp.Common.props) to ensure it's built before projects that use it.
+    Since this is a project reference, we must explicitly import the props file and also specify the output location
+    of the SDK directory.
+  -->
+  <PropertyGroup>
+    <RazorSdkDirectoryRoot>$(ArtifactsBinDir)Microsoft.NET.Sdk.Razor\${Configuration}\sdk-output\</RazorSdkDirectoryRoot>
+    <BlazorWebAssemblySdkDirectoryRoot>$(ArtifactsBinDir)Microsoft.NET.Sdk.BlazorWebAssembly\${Configuration}\sdk-output\</BlazorWebAssemblySdkDirectoryRoot>
+  </PropertyGroup>
+  <Import Project="$(RepoRoot)src\Razor\Microsoft.NET.Sdk.Razor\src\build\netstandard2.0\Microsoft.NET.Sdk.Razor.props"
+      Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true' OR '$(RazorSdkCurrentVersionProps)' != ''" />
+</Project>

+ 98 - 0
src/ProjectTemplates/TestInfrastructure/PrepareForTest.targets

@@ -0,0 +1,98 @@
+<Project>
+  <ItemGroup>
+    <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
+      <_Parameter1>DotNetEfFullPath</_Parameter1>
+      <_Parameter2>$([MSBuild]::EnsureTrailingSlash('$(NuGetPackageRoot)'))dotnet-ef/$(DotnetEfVersion)/tools/netcoreapp3.1/any/dotnet-ef.dll</_Parameter2>
+    </AssemblyAttribute>
+    <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
+      <_Parameter1>TestPackageRestorePath</_Parameter1>
+      <_Parameter2>$(TestPackageRestorePath)</_Parameter2>
+    </AssemblyAttribute>
+    <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
+      <_Parameter1>Test.DefaultTargetFramework</_Parameter1>
+      <_Parameter2>$(DefaultNetCoreTargetFramework)</_Parameter2>
+    </AssemblyAttribute>
+    <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(ContinuousIntegrationBuild)' == 'true'">
+      <_Parameter1>ContinuousIntegrationBuild</_Parameter1>
+      <_Parameter2>true</_Parameter2>
+    </AssemblyAttribute>
+  </ItemGroup>
+
+  <Target Name="PrepareForTest" BeforeTargets="GetAssemblyAttributes" Condition="$(DesignTimeBuild) != true">
+    <PropertyGroup>
+      <TestTemplateCreationFolder>$([MSBuild]::NormalizePath('$(OutputPath)$(TestTemplateCreationFolder)'))</TestTemplateCreationFolder>
+      <CustomTemplateHivePath>$(TestTemplateCreationFolder)\Hives\$([System.Guid]::NewGuid())\.templateengine</CustomTemplateHivePath>
+    </PropertyGroup>
+
+    <ItemGroup>
+      <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
+        <_Parameter1>ArtifactsShippingPackagesDir</_Parameter1>
+        <_Parameter2>$(ArtifactsShippingPackagesDir)</_Parameter2>
+      </AssemblyAttribute>
+
+      <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
+        <_Parameter1>ArtifactsLogDir</_Parameter1>
+        <_Parameter2>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'log'))</_Parameter2>
+      </AssemblyAttribute>
+
+      <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
+        <_Parameter1>ArtifactsNonShippingPackagesDir</_Parameter1>
+        <_Parameter2>$(ArtifactsNonShippingPackagesDir)</_Parameter2>
+      </AssemblyAttribute>
+
+      <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
+        <_Parameter1>TestTemplateCreationFolder</_Parameter1>
+        <_Parameter2>$(TestTemplateCreationFolder)</_Parameter2>
+      </AssemblyAttribute>
+      <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
+        <_Parameter1>CustomTemplateHivePath</_Parameter1>
+        <_Parameter2>$(CustomTemplateHivePath)</_Parameter2>
+      </AssemblyAttribute>
+    </ItemGroup>
+
+    <Message Importance="high" Text="Preparing environment for tests" />
+    <!-- Remove the template creation folders and the package-restore folders to ensure that when we run the tests we don't
+         get cached results and changes show up.
+    -->
+
+    <ItemGroup>
+      <_ExistingFilesFromLastRun Include="$(TestTemplateCreationFolder)**\*" />
+    </ItemGroup>
+
+    <Delete Files="@(_ExistingFilesFromLastRun)" ContinueOnError="true" />
+
+    <Removedir Directories="$(TestTemplateCreationFolder)" Condition="Exists('$(TestTemplateCreationFolder)')" ContinueOnError="true">
+      <Output TaskParameter="RemovedDirectories" ItemName="_CleanedUpDirectories" />
+    </Removedir>
+    <Removedir Directories="$(TestPackageRestorePath)" Condition="Exists('$(TestPackageRestorePath)')" ContinueOnError="true">
+      <Output TaskParameter="RemovedDirectories" ItemName="_CleanedUpDirectories" />
+    </Removedir>
+
+    <Message Importance="high" Text="Removed directory %(_CleanedUpDirectories.Identity)" />
+
+    <MakeDir Directories="$(TestTemplateCreationFolder)">
+      <Output TaskParameter="DirectoriesCreated" ItemName="_CreatedDirectories" />
+    </MakeDir>
+    <MakeDir Directories="$(TestPackageRestorePath)">
+      <Output TaskParameter="DirectoriesCreated" ItemName="_CreatedDirectories" />
+    </MakeDir>
+
+    <Message Importance="high" Text="Created directory %(_CreatedDirectories.Identity)" />
+
+    <GenerateFileFromTemplate
+      TemplateFile="$(MSBuildThisFileDirectory)..\TestInfrastructure\Directory.Build.targets.in"
+      Properties="Configuration=$(Configuration);
+          RestoreAdditionalProjectSources=$([MSBuild]::Escape('$(RestoreAdditionalProjectSources);$(ArtifactsShippingPackagesDir);$(ArtifactsNonShippingPackagesDir)'))"
+      OutputPath="$(TestTemplateCreationFolder)Directory.Build.targets" />
+
+    <GenerateFileFromTemplate
+      TemplateFile="$(MSBuildThisFileDirectory)..\TestInfrastructure\Directory.Build.props.in"
+      Properties="RepoRoot=$(RepoRoot);ArtifactsBinDir=$(ArtifactsBinDir)"
+      OutputPath="$(TestTemplateCreationFolder)Directory.Build.props" />
+
+    <!-- Workaround https://github.com/dotnet/core-setup/issues/6420 - there is no MSBuild setting for rollforward yet -->
+    <Copy SourceFiles="$(MSBuildThisFileDirectory)..\TestInfrastructure\runtimeconfig.norollforward.json"
+      DestinationFolder="$(TestTemplateCreationFolder)"
+      UseHardLinksIfPossible="true" />
+  </Target>
+</Project>

+ 0 - 0
src/ProjectTemplates/BlazorTemplates.Tests/Infrastructure/runtimeconfig.norollforward.json → src/ProjectTemplates/TestInfrastructure/runtimeconfig.norollforward.json


+ 0 - 4
src/ProjectTemplates/test/Directory.Build.targets

@@ -1,4 +0,0 @@
-<Project>
-  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, Directory.Build.targets))\Directory.Build.targets" />
-  <Import Project="$(MSBuildThisFileDirectory)Infrastructure\GenerateTestProps.targets" />
-</Project>

+ 0 - 6
src/ProjectTemplates/test/Infrastructure/Directory.Build.props.in

@@ -1,6 +0,0 @@
-<Project>
-<!-- This file gets copied above the template test projects so that we disconnect the templates from the rest of the repository -->
-  <PropertyGroup>
-    <TargetFramework>${DefaultNetCoreTargetFramework}</TargetFramework>
-  </PropertyGroup>
-</Project>

+ 0 - 3
src/ProjectTemplates/test/Infrastructure/Directory.Build.targets.in

@@ -1,3 +0,0 @@
-<Project>
-  <Import Project="${TemplateTestsPropsPath}" />
-</Project>

+ 0 - 30
src/ProjectTemplates/test/Infrastructure/GenerateTestProps.targets

@@ -1,30 +0,0 @@
-<Project>
-  <Target Name="GenerateTestProps"
-      BeforeTargets="CoreCompile"
-      DependsOnTargets="PrepareForTest"
-      Condition="$(DesignTimeBuild) != true">
-    <PropertyGroup>
-      <PropsProperties>
-        RestoreAdditionalProjectSources=$([MSBuild]::Escape("$(RestoreAdditionalProjectSources);$(ArtifactsShippingPackagesDir);$(ArtifactsNonShippingPackagesDir)"));
-        MicrosoftNetCompilersToolsetVersion=$(MicrosoftNetCompilersToolsetVersion);
-        MicrosoftNETCoreAppRuntimeVersion=$(MicrosoftNETCoreAppRuntimeVersion);
-        MicrosoftNETCoreAppRefVersion=$(MicrosoftNETCoreAppRefVersion);
-        MicrosoftNETCorePlatformsVersion=$(MicrosoftNETCorePlatformsVersion);
-        MicrosoftNETSdkRazorVersion=$(MicrosoftNETSdkRazorVersion);
-        MicrosoftAspNetCoreAppRefVersion=$(TargetingPackVersion);
-        MicrosoftAspNetCoreAppRuntimeVersion=$(SharedFxVersion);
-        SupportedRuntimeIdentifiers=$(SupportedRuntimeIdentifiers.Trim());
-        DefaultNetCoreTargetFramework=$(DefaultNetCoreTargetFramework);
-        KnownAppHostPackOrFrameworkReferenceTfm=$(KnownAppHostPackOrFrameworkReferenceTfm);
-        RepoRoot=$(RepoRoot);
-        Configuration=$(Configuration);
-        ArtifactsBinDir=$(ArtifactsBinDir);
-      </PropsProperties>
-    </PropertyGroup>
-
-    <GenerateFileFromTemplate
-      TemplateFile="$(MSBuildThisFileDirectory)\TemplateTests.props.in"
-      Properties="$(PropsProperties)"
-      OutputPath="$(TestTemplateTestsProps)" />
-  </Target>
-</Project>

+ 0 - 57
src/ProjectTemplates/test/Infrastructure/TemplateTests.props.in

@@ -1,57 +0,0 @@
-<Project>
-  <PropertyGroup>
-    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
-    <RestoreAdditionalProjectSources>${RestoreAdditionalProjectSources}</RestoreAdditionalProjectSources>
-    <!-- This sets an option which prevents the tests from rolling forward into a newer shared framework. -->
-    <UserRuntimeConfig>$(MSBuildThisFileDirectory)runtimeconfig.norollforward.json</UserRuntimeConfig>
-    <!-- Workaround while there is no 6.0 SDK available, suppress unsupported version error -->
-    <NETCoreAppMaximumVersion>6.0</NETCoreAppMaximumVersion>
-  </PropertyGroup>
-
-  <ItemGroup>
-    <KnownFrameworkReference
-      Update="Microsoft.NETCore.App"
-      DefaultRuntimeFrameworkVersion="${MicrosoftNETCoreAppRuntimeVersion}"
-      LatestRuntimeFrameworkVersion="${MicrosoftNETCoreAppRuntimeVersion}"
-      TargetingPackVersion="${MicrosoftNETCoreAppRefVersion}" />
-
-    <KnownFrameworkReference
-      Update="Microsoft.AspNetCore.App"
-      DefaultRuntimeFrameworkVersion="${MicrosoftAspNetCoreAppRuntimeVersion}"
-      LatestRuntimeFrameworkVersion="${MicrosoftAspNetCoreAppRuntimeVersion}"
-      TargetingPackVersion="${MicrosoftAspNetCoreAppRefVersion}"
-      RuntimePackRuntimeIdentifiers="${SupportedRuntimeIdentifiers}" />
-  </ItemGroup>
-
-  <ItemGroup>
-    <!-- Workaround when there is no vNext SDK available, copy known apphost/framework reference info from 5.0 -->
-    <KnownAppHostPack
-      Include="@(KnownAppHostPack->WithMetadataValue('TargetFramework', 'netcoreapp5.0'))"
-      TargetFramework="${KnownAppHostPackOrFrameworkReferenceTfm}"
-      Condition="@(KnownAppHostPack->Count()) != '0' AND !(@(KnownAppHostPack->AnyHaveMetadataValue('TargetFramework', '${KnownAppHostPackOrFrameworkReferenceTfm}')))"
-      />
-    <KnownFrameworkReference
-      Include="@(KnownFrameworkReference->WithMetadataValue('TargetFramework', 'netcoreapp5.0'))"
-      TargetFramework="${KnownAppHostPackOrFrameworkReferenceTfm}"
-      Condition="@(KnownFrameworkReference->Count()) != '0' AND !(@(KnownFrameworkReference->AnyHaveMetadataValue('TargetFramework', '${KnownAppHostPackOrFrameworkReferenceTfm}')))"
-      />
-  </ItemGroup>
-
-  <ItemGroup>
-    <PackageReference Include="Microsoft.Net.Compilers.Toolset"
-      Version="${MicrosoftNetCompilersToolsetVersion}"
-      PrivateAssets="all"
-      IsImplicitlyDefined="true" />
-  </ItemGroup>
-
-  <!--
-    The version of the .NET Core SDK we build with often contains a version of the Razor SDK several versions older than latest.
-    We reference the project to ensure it's built before the other projects that use it. Since this is a project reference, we
-    must explicitly import the props file and also specify the output location of the SDK directory.
-  -->
-  <PropertyGroup>
-    <RazorSdkDirectoryRoot>${ArtifactsBinDir}Microsoft.NET.Sdk.Razor\${Configuration}\sdk-output\</RazorSdkDirectoryRoot>
-  </PropertyGroup>
-  <Import Project="${RepoRoot}src\Razor\Microsoft.NET.Sdk.Razor\src\build\netstandard2.0\Microsoft.NET.Sdk.Razor.props"  Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true' OR '$(RazorSdkCurrentVersionProps)' != ''" />
-  <Import Project="${RepoRoot}src\Components\WebAssembly\Sdk\src\build\$(DefaultNetCoreTargetFramework)\Microsoft.NET.Sdk.BlazorWebAssembly.props"  Condition="'$(UsingMicrosoftNETSdkBlazorWebAssembly)' == 'true'" />
-</Project>

+ 0 - 3
src/ProjectTemplates/test/Infrastructure/runtimeconfig.norollforward.json

@@ -1,3 +0,0 @@
-{
-  "rollForward": "Disable"
-}

+ 1 - 100
src/ProjectTemplates/test/ProjectTemplates.Tests.csproj

@@ -19,7 +19,6 @@
     <!-- TestTemplateCreationFolder is the folder where the templates will be created. Will point out to $(OutputDir)$(TestTemplateCreationFolder) -->
     <TestTemplateCreationFolder>TestTemplates\</TestTemplateCreationFolder>
     <TestPackageRestorePath>$([MSBuild]::EnsureTrailingSlash('$(RepoRoot)'))obj\template-restore\</TestPackageRestorePath>
-    <TestTemplateTestsProps>TemplateTests.props</TestTemplateTestsProps>
     <TestDependsOnAspNetRuntime>true</TestDependsOnAspNetRuntime>
   </PropertyGroup>
 
@@ -60,105 +59,7 @@
     <PreserveExistingLogsInOutput Condition="'$(PreserveExistingLogsInOutput)' == ''">false</PreserveExistingLogsInOutput>
   </PropertyGroup>
 
-  <ItemGroup>
-    <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
-      <_Parameter1>DotNetEfFullPath</_Parameter1>
-      <_Parameter2>$([MSBuild]::EnsureTrailingSlash('$(NuGetPackageRoot)'))dotnet-ef/$(DotnetEfVersion)/tools/netcoreapp3.1/any/dotnet-ef.dll</_Parameter2>
-    </AssemblyAttribute>
-    <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
-      <_Parameter1>TestPackageRestorePath</_Parameter1>
-      <_Parameter2>$(TestPackageRestorePath)</_Parameter2>
-    </AssemblyAttribute>
-    <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
-      <_Parameter1>Test.DefaultTargetFramework</_Parameter1>
-      <_Parameter2>$(DefaultNetCoreTargetFramework)</_Parameter2>
-    </AssemblyAttribute>
-    <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(ContinuousIntegrationBuild)' == 'true'">
-      <_Parameter1>ContinuousIntegrationBuild</_Parameter1>
-      <_Parameter2>true</_Parameter2>
-    </AssemblyAttribute>
-  </ItemGroup>
-
-  <Target Name="PrepareForTest" BeforeTargets="GetAssemblyAttributes" Condition="$(DesignTimeBuild) != true">
-    <PropertyGroup>
-      <TestTemplateCreationFolder>$([MSBuild]::NormalizePath('$(OutputPath)$(TestTemplateCreationFolder)'))</TestTemplateCreationFolder>
-      <TestTemplateTestsProps>$(TestTemplateCreationFolder)$(TestTemplateTestsProps)</TestTemplateTestsProps>
-      <CustomTemplateHivePath>$(TestTemplateCreationFolder)\Hives\$([System.Guid]::NewGuid())\.templateengine</CustomTemplateHivePath>
-    </PropertyGroup>
-
-    <ItemGroup>
-      <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
-        <_Parameter1>ArtifactsShippingPackagesDir</_Parameter1>
-        <_Parameter2>$(ArtifactsShippingPackagesDir)</_Parameter2>
-      </AssemblyAttribute>
-
-      <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
-        <_Parameter1>ArtifactsLogDir</_Parameter1>
-        <_Parameter2>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'log'))</_Parameter2>
-      </AssemblyAttribute>
-
-      <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
-        <_Parameter1>ArtifactsNonShippingPackagesDir</_Parameter1>
-        <_Parameter2>$(ArtifactsNonShippingPackagesDir)</_Parameter2>
-      </AssemblyAttribute>
-
-      <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
-        <_Parameter1>TestTemplateCreationFolder</_Parameter1>
-        <_Parameter2>$(TestTemplateCreationFolder)</_Parameter2>
-      </AssemblyAttribute>
-      <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
-        <_Parameter1>CustomTemplateHivePath</_Parameter1>
-        <_Parameter2>$(CustomTemplateHivePath)</_Parameter2>
-      </AssemblyAttribute>
-    </ItemGroup>
-
-    <Message Importance="high" Text="Preparing environment for tests" />
-    <!-- Remove the template creation folders and the package-restore folders to ensure that when we run the tests we don't
-         get cached results and changes show up.
-    -->
-
-    <ItemGroup>
-      <_ExistingFilesFromLastRun Include="$(TestTemplateCreationFolder)**\*" />
-    </ItemGroup>
-
-    <Delete Files="@(_ExistingFilesFromLastRun)" ContinueOnError="true" />
-
-    <Removedir Directories="$(TestTemplateCreationFolder)" Condition="Exists('$(TestTemplateCreationFolder)')" ContinueOnError="true">
-      <Output TaskParameter="RemovedDirectories" ItemName="_CleanedUpDirectories" />
-    </Removedir>
-    <Removedir Directories="$(TestPackageRestorePath)" Condition="Exists('$(TestPackageRestorePath)')" ContinueOnError="true">
-      <Output TaskParameter="RemovedDirectories" ItemName="_CleanedUpDirectories" />
-    </Removedir>
-
-    <Message Importance="high" Text="Removed directory %(_CleanedUpDirectories.Identity)" />
-
-    <MakeDir Directories="$(TestTemplateCreationFolder)">
-      <Output TaskParameter="DirectoriesCreated" ItemName="_CreatedDirectories" />
-    </MakeDir>
-    <MakeDir Directories="$(TestPackageRestorePath)">
-      <Output TaskParameter="DirectoriesCreated" ItemName="_CreatedDirectories" />
-    </MakeDir>
-
-    <Message Importance="high" Text="Created directory %(_CreatedDirectories.Identity)" />
-
-    <GenerateFileFromTemplate
-      TemplateFile="$(MSBuildThisFileDirectory)Infrastructure\Directory.Build.targets.in"
-      Properties="TemplateTestsPropsPath=$(TestTemplateTestsProps)"
-      OutputPath="$(TestTemplateCreationFolder)Directory.Build.targets" />
-
-    <GenerateFileFromTemplate
-      TemplateFile="$(MSBuildThisFileDirectory)Infrastructure\Directory.Build.props.in"
-      Properties="RepoRoot=$(RepoRoot);DefaultNetCoreTargetFramework=$(DefaultNetCoreTargetFramework)"
-      OutputPath="$(TestTemplateCreationFolder)Directory.Build.props" />
-
-    <!-- Workaround https://github.com/dotnet/core-setup/issues/6420 - there is no MSBuild setting for rollforward yet -->
-    <Copy SourceFiles="$(MSBuildThisFileDirectory)Infrastructure\runtimeconfig.norollforward.json" DestinationFolder="$(TestTemplateCreationFolder)" UseHardLinksIfPossible="true" />
-
-    <Delete Files="$(TestTemplateTestsProps)" />
-
-  </Target>
-
   <!-- Shared testing infrastructure for running E2E tests using selenium -->
   <Import Project="$(SharedSourceRoot)E2ETesting\E2ETesting.targets" />
-
+  <Import Project="..\TestInfrastructure\PrepareForTest.targets" />
 </Project>

+ 17 - 5
src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/Microsoft.NET.Sdk.Razor.IntegrationTests.csproj

@@ -11,7 +11,7 @@
     <PreserveCompilationContext>true</PreserveCompilationContext>
     <DefineConstants Condition="'$(PreserveWorkingDirectory)'=='true'">$(DefineConstants);PRESERVE_WORKING_DIRECTORY</DefineConstants>
 
-    <!-- Tests do not work on Helix yet -->
+    <!-- Tests do not work on Helix yet. When enabled, add Publish to BeforeTargets of RestoreTestProjects. -->
     <BuildHelixPayload>false</BuildHelixPayload>
     <TestAppsRoot>$(MSBuildProjectDirectory)\..\..\test\testassets\</TestAppsRoot>
   </PropertyGroup>
@@ -33,6 +33,18 @@
     <Reference Include="Microsoft.NET.Sdk.Razor" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" />
   </ItemGroup>
 
+  <!-- Ensure shared framework and targeting packs are laid out under .dotnet/ before executing tests. -->
+  <ItemGroup Condition=" '$(DotNetBuildFromSource)' != 'true' ">
+    <ProjectReference Include="$(RepoRoot)src\Framework\App.Ref\src\Microsoft.AspNetCore.App.Ref.csproj"
+        Condition=" $(IsTargetingPackBuilding) "
+        ReferenceOutputAssembly="false"
+        SkipGetTargetFrameworkProperties="true" />
+    <ProjectReference Include="$(RepoRoot)src\Framework\App.Runtime\src\Microsoft.AspNetCore.App.Runtime.csproj"
+        Condition=" !$(IsTargetingPackBuilding) "
+        ReferenceOutputAssembly="false"
+        SkipGetTargetFrameworkProperties="true" />
+  </ItemGroup>
+
   <Target Name="GenerateTestData" BeforeTargets="GetAssemblyAttributes">
     <Exec Condition="'$(OS)' == 'Windows_NT'" Command="&quot;$(NuGetPackageRoot)vswhere\$(VSWhereVersion)\tools\vswhere.exe&quot; -latest -prerelease -property installationPath -requires Microsoft.Component.MSBuild" ConsoleToMsBuild="true" StandardErrorImportance="high">
       <Output TaskParameter="ConsoleOutput" PropertyName="_VSInstallDir" />
@@ -54,10 +66,10 @@
     </ItemGroup>
   </Target>
 
-  <Target Name="RestoreTestProjects" BeforeTargets="Restore;Build" Condition="'$(DotNetBuildFromSource)' != 'true'">
-    <MSBuild Projects="..\..\test\testassets\RestoreTestProjects\RestoreTestProjects.csproj" Targets="Restore" Properties="MicrosoftNetCompilersToolsetVersion=$(MicrosoftNetCompilersToolsetVersion);RepoRoot=$(RepoRoot)" />
-    <MSBuild Projects="..\..\test\testassets\PackageLibraryDirectDependency\PackageLibraryDirectDependency.csproj" Targets="Restore" Properties="MicrosoftNetCompilersToolsetVersion=$(MicrosoftNetCompilersToolsetVersion);RepoRoot=$(RepoRoot)" />
-    <MSBuild Projects="..\..\test\testassets\PackageLibraryTransitiveDependency\PackageLibraryTransitiveDependency.csproj" Targets="Restore" Properties="MicrosoftNetCompilersToolsetVersion=$(MicrosoftNetCompilersToolsetVersion);RepoRoot=$(RepoRoot)" />
+  <Target Name="RestoreTestProjects" BeforeTargets="RunTests;Test;VSTest" Condition=" '$(DotNetBuildFromSource)' != 'true' ">
+    <MSBuild Projects="..\..\test\testassets\RestoreTestProjects\RestoreTestProjects.csproj" Targets="Restore" Properties="RepoRoot=$(RepoRoot)" />
+    <MSBuild Projects="..\..\test\testassets\PackageLibraryDirectDependency\PackageLibraryDirectDependency.csproj" Targets="Restore" Properties="RepoRoot=$(RepoRoot)" />
+    <MSBuild Projects="..\..\test\testassets\PackageLibraryTransitiveDependency\PackageLibraryTransitiveDependency.csproj" Targets="Restore" Properties="RepoRoot=$(RepoRoot)" />
   </Target>
 
   <Target Name="EnsureLogFolder" AfterTargets="Build">

+ 10 - 15
src/Razor/test/testassets/Directory.Build.props

@@ -2,21 +2,17 @@
   <Import Project="Before.Directory.Build.props" Condition="Exists('Before.Directory.Build.props')" />
 
   <PropertyGroup>
-    <!--
-      In the case that a user is building a sample directly the MicrosoftNetCompilersToolsetPackagerVersion will not be provided.
-      We'll fall back to whatever the current SDK provides in regards to Roslyn's Microsoft.Net.Compilers.Toolset.
-    -->
-    <BuildingTestAppsIndependently>false</BuildingTestAppsIndependently>
-    <BuildingTestAppsIndependently Condition="'$(MicrosoftNetCompilersToolsetVersion)' == ''">true</BuildingTestAppsIndependently>
-
     <!-- Do not resolve Reference ItemGroup since it has a different semantic meaning in Razor test apps -->
     <EnableCustomReferenceResolution>false</EnableCustomReferenceResolution>
 
     <DefaultNetCoreTargetFramework>net6.0</DefaultNetCoreTargetFramework>
 
-    <RepoRoot Condition="'$(BuildingTestAppsIndependently)' == 'true' AND '$(RepoRoot)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, 'global.json'))\</RepoRoot>
+    <RepoRoot Condition=" '$(RepoRoot)' == '' ">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, 'global.json'))\</RepoRoot>
     <RazorSdkArtifactsDirectory>$(RepoRoot)artifacts\bin\Microsoft.NET.Sdk.Razor\</RazorSdkArtifactsDirectory>
     <BlazorWebAssemblyJSPath>$(MSBuildThisFileDirectory)blazor.webassembly.js</BlazorWebAssemblyJSPath>
+
+    <!-- Build these test projects against the incoming Microsoft.NETCore.App framework. -->
+    <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
   </PropertyGroup>
 
   <Import Project="$(RepoRoot)eng\Versions.props" />
@@ -41,14 +37,13 @@
     <!-- Have the SDK treat the MvcShim as an MVC assembly -->
     <_MvcAssemblyName Include="Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib" />
   </ItemGroup>
-  <ItemGroup Condition="$(BuildingTestAppsIndependently) == 'false'">
-    <PackageReference Include="Microsoft.Net.Compilers.Toolset"
-        Version="$(MicrosoftNetCompilersToolsetVersion)"
-        PrivateAssets="all"
-        IsImplicitlyDefined="true" />
-  </ItemGroup>
+
+  <Import Project="$(RepoRoot)artifacts\bin\GenerateFiles\Directory.Build.props" Condition=" Exists('$(RepoRoot)artifacts\bin\GenerateFiles\Directory.Build.props') " />
+  <PropertyGroup>
+    <!-- Some tests expect assets to build successfully despite warnings. Override GenerateFiles setting. -->
+    <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
+  </PropertyGroup>
 
   <Import Project="$(RepoRoot)src\Razor\Microsoft.NET.Sdk.Razor\src\build\netstandard2.0\Microsoft.NET.Sdk.Razor.props" />
   <Import Project="After.Directory.Build.props" Condition="Exists('After.Directory.Build.props')" />
-
 </Project>

+ 1 - 20
src/Razor/test/testassets/Directory.Build.targets

@@ -1,23 +1,4 @@
 <Project>
   <Import Project="RazorTest.Introspection.targets" />
-
-  <PropertyGroup>
-    <RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == '$(DefaultNetCoreTargetFramework)' ">$(MicrosoftNETCoreAppRuntimeVersion)</RuntimeFrameworkVersion>
-    <!-- aspnet/BuildTools#662 Don't police what version of NetCoreApp we use -->
-    <NETCoreAppMaximumVersion>99.9</NETCoreAppMaximumVersion>
-  </PropertyGroup>
-
-  <ItemGroup>
-    <!-- Workaround when there is no vNext SDK available, copy known apphost/framework reference info from 5.0 -->
-    <KnownAppHostPack
-      Include="@(KnownAppHostPack->WithMetadataValue('TargetFramework', 'netcoreapp5.0'))"
-      TargetFramework="$(DefaultNetCoreTargetFramework)"
-      Condition="@(KnownAppHostPack->Count()) != '0' AND !(@(KnownAppHostPack->AnyHaveMetadataValue('TargetFramework', '$(DefaultNetCoreTargetFramework)')))"
-      />
-    <KnownFrameworkReference
-      Include="@(KnownFrameworkReference->WithMetadataValue('TargetFramework', 'netcoreapp5.0'))"
-      TargetFramework="$(DefaultNetCoreTargetFramework)"
-      Condition="@(KnownFrameworkReference->Count()) != '0' AND !(@(KnownFrameworkReference->AnyHaveMetadataValue('TargetFramework', '$(DefaultNetCoreTargetFramework)')))"
-      />
-  </ItemGroup>
+  <Import Project="$(RepoRoot)artifacts\bin\GenerateFiles\Directory.Build.targets" Condition=" Exists('$(RepoRoot)artifacts\bin\GenerateFiles\Directory.Build.targets') " />
 </Project>