Skip to content

Commit

Permalink
Further centralize shared Fx and TFM transition workarounds (dotnet#2…
Browse files Browse the repository at this point in the history
…7473)

* 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 dotnet#27653
  - dotnet#27653 (review)

Co-authored-by: Safia Abdalla <safia@microsoft.com>
  • Loading branch information
dougbu and captainsafia authored Dec 3, 2020
1 parent da3e434 commit 5fd1db2
Show file tree
Hide file tree
Showing 32 changed files with 399 additions and 646 deletions.
5 changes: 2 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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. -->
Expand Down Expand Up @@ -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" />
Expand Down
33 changes: 10 additions & 23 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -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)' != '' ">
Expand All @@ -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'" />
Expand Down
87 changes: 75 additions & 12 deletions docs/BuildErrors.md
Original file line number Diff line number Diff line change
@@ -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"
```
Loading

0 comments on commit 5fd1db2

Please sign in to comment.