Skip to content

Commit 5fd1db2

Browse files
dougbucaptainsafia
andauthored
Further centralize shared Fx and TFM transition workarounds (dotnet#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 dotnet#27653 - dotnet#27653 (review) Co-authored-by: Safia Abdalla <safia@microsoft.com>
1 parent da3e434 commit 5fd1db2

32 files changed

+399
-646
lines changed

Diff for: Directory.Build.props

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
$(MSBuildProjectName.EndsWith('.Test')) OR
2222
$(MSBuildProjectName.EndsWith('.FunctionalTest')) ) ">true</IsUnitTestProject>
2323
<IsTestAssetProject Condition=" $(RepoRelativeProjectDir.Contains('testassets')) ">true</IsTestAssetProject>
24-
<IsSampleProject Condition=" $(RepoRelativeProjectDir.Contains('sample')) OR
25-
$(RepoRelativeProjectDir.Contains('Sample')) ">true</IsSampleProject>
24+
<IsSampleProject Condition=" $(RepoRelativeProjectDir.ToUpperInvariant().Contains('SAMPLE')) ">true</IsSampleProject>
2625
<IsAnalyzersProject Condition="$(MSBuildProjectName.EndsWith('.Analyzers'))">true</IsAnalyzersProject>
2726
<IsShipping Condition=" '$(IsSampleProject)' == 'true' OR
2827
'$(IsTestAssetProject)' == 'true' OR
@@ -101,7 +100,6 @@
101100

102101
<!-- Warnings and errors -->
103102
<PropertyGroup>
104-
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
105103
<!-- For local builds, don't make missing XML docs a fatal build error, but still surface so we have visibility into undocumented APIs. -->
106104
<WarningsNotAsErrors Condition=" '$(ContinuousIntegrationBuild)' != 'true' ">$(WarningsNotAsErrors);CS1591</WarningsNotAsErrors>
107105
<!-- For CI builds, ensure API docs are available. -->
@@ -216,6 +214,7 @@
216214
</PropertyGroup>
217215

218216
<Import Project="eng\Workarounds.props" />
217+
<Import Project="artifacts\bin\GenerateFiles\Directory.Build.props" Condition=" '$(MSBuildProjectName)' != 'GenerateFiles' " />
219218
<Import Project="eng\Dependencies.props" />
220219
<Import Project="eng\ProjectReferences.props" />
221220
<Import Project="eng\SharedFramework.Local.props" />

Diff for: Directory.Build.targets

+10-23
Original file line numberDiff line numberDiff line change
@@ -151,34 +151,20 @@
151151

152152
<PropertyGroup>
153153
<KnownAppHostPackOrFrameworkReferenceTfm>$(DefaultNetCoreTargetFramework)</KnownAppHostPackOrFrameworkReferenceTfm>
154-
<KnownAppHostPackOrFrameworkReferenceTfm Condition=" '$(TargetFrameworkIdentifier)' == '$(NETCoreAppFrameworkIdentifier)' AND
155-
$([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '5.0')) ">netcoreapp$(TargetFrameworkVersion.TrimStart('vV'))</KnownAppHostPackOrFrameworkReferenceTfm>
154+
<_DefaultTargetFrameworkIdentifier>$([MSBuild]::GetTargetFrameworkIdentifier('$(DefaultNetCoreTargetFramework)'))</_DefaultTargetFrameworkIdentifier>
155+
<_DefaultTargetFrameworkVersionNoV>$([MSBuild]::GetTargetFrameworkVersion('$(DefaultNetCoreTargetFramework)', 2))</_DefaultTargetFrameworkVersionNoV>
156+
<KnownAppHostPackOrFrameworkReferenceTfm Condition=" '$(_DefaultTargetFrameworkIdentifier)' == '$(NETCoreAppFrameworkIdentifier)' AND
157+
$([MSBuild]::VersionGreaterThanOrEquals('$(_DefaultTargetFrameworkVersionNoV)', '5.0')) ">netcoreapp$(_DefaultTargetFrameworkVersionNoV)</KnownAppHostPackOrFrameworkReferenceTfm>
158+
159+
<!-- Do not update the Microsoft.AspNetCore.App KnownFrameworkReference item unless requested. -->
160+
<UpdateAspNetCoreKnownFramework>false</UpdateAspNetCoreKnownFramework>
161+
<UpdateAspNetCoreKnownFramework Condition=" '$(UseAspNetCoreSharedRuntime)' == 'true' AND
162+
'$(DoNotApplyWorkaroundsToMicrosoftAspNetCoreApp)' != 'true' ">true</UpdateAspNetCoreKnownFramework>
156163
</PropertyGroup>
157164

158165
<ItemGroup>
159-
<KnownFrameworkReference Update="Microsoft.NETCore.App">
160-
<!-- Always update the 'latest version', whether the repo is servicing or not. -->
161-
<LatestRuntimeFrameworkVersion Condition="'%(TargetFramework)' == '$(KnownAppHostPackOrFrameworkReferenceTfm)'">$(MicrosoftNETCoreAppRuntimeVersion)</LatestRuntimeFrameworkVersion>
162-
<!-- Only update the default runtime version for preview builds. -->
163-
<DefaultRuntimeFrameworkVersion Condition="'%(TargetFramework)' == '$(KnownAppHostPackOrFrameworkReferenceTfm)' and '$(IsServicingBuild)' != 'true'">$(MicrosoftNETCoreAppRuntimeVersion)</DefaultRuntimeFrameworkVersion>
164-
<!-- Only update the targeting pack version for preview builds. -->
165-
<TargetingPackVersion Condition="'%(TargetFramework)' == '$(KnownAppHostPackOrFrameworkReferenceTfm)' and '$(IsServicingBuild)' != 'true'">$(MicrosoftNETCoreAppRefVersion)</TargetingPackVersion>
166-
</KnownFrameworkReference>
167-
168166
<KnownFrameworkReference Condition="'$(UseAspNetCoreSharedRuntime)' != 'true'" Remove="Microsoft.AspNetCore.App" />
169167
<KnownFrameworkReference Remove="Microsoft.WindowsDesktop.App" />
170-
171-
<KnownFrameworkReference Condition="'$(UseAspNetCoreSharedRuntime)' == 'true' AND '$(DoNotApplyWorkaroundsToMicrosoftAspNetCoreApp)' != 'true'" Update="Microsoft.AspNetCore.App">
172-
<LatestRuntimeFrameworkVersion>$(SharedFxVersion)</LatestRuntimeFrameworkVersion>
173-
<DefaultRuntimeFrameworkVersion Condition="'$(IsServicingBuild)' != 'true'">$(SharedFxVersion)</DefaultRuntimeFrameworkVersion>
174-
<TargetingPackVersion Condition="'$(IsServicingBuild)' != 'true'">$(TargetingPackVersion)</TargetingPackVersion>
175-
</KnownFrameworkReference>
176-
177-
<!-- Track compiler separately from Arcade.-->
178-
<PackageReference Include="Microsoft.Net.Compilers.Toolset"
179-
Version="$(MicrosoftNetCompilersToolsetVersion)"
180-
PrivateAssets="all"
181-
IsImplicitlyDefined="true" />
182168
</ItemGroup>
183169

184170
<PropertyGroup Condition=" '$(CopySymbolsToArtifacts)' == 'true' AND '$(TargetFramework)' != '' ">
@@ -195,6 +181,7 @@
195181
</Target>
196182

197183
<Import Project="eng\Workarounds.targets" />
184+
<Import Project="artifacts\bin\GenerateFiles\Directory.Build.targets" Condition=" '$(MSBuildProjectName)' != 'GenerateFiles' " />
198185
<Import Project="eng\targets\ResolveIisReferences.targets" Condition=" '$(MSBuildProjectExtension)' != '.vcxproj' " />
199186
<Import Project="eng\targets\Cpp.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.vcxproj'" />
200187
<Import Project="eng\targets\CSharp.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.csproj'" />

Diff for: docs/BuildErrors.md

+75-12
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,96 @@
1-
Build Errors
2-
------------
1+
# Build Errors
32

43
This document is for common build errors and how to resolve them.
54

6-
### Warning BUILD001
5+
## Warning BUILD001
76

8-
> warning BUILD001: Package references changed since the last release...
7+
> warning BUILD001: Reference to '&hellip;' was removed since the last stable release of this package. &hellip;
98
109
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
11-
in a previous release of this assembly. See <./ReferenceResolution.md> for how to suppress.
10+
in a previous release of this assembly. See [ReferenceResolution](./ReferenceResolution.md) for how to suppress.
1211

13-
### Error BUILD002
12+
## Error BUILD002
1413

15-
> error BUILD002: Package references changed since the last release...
14+
> error BUILD002: Package references changed since the last release&hellip;
1615
17-
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.
16+
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.
1817

19-
### Error BUILD003
18+
## Error BUILD003
2019

2120
> error BUILD003: Multiple project files named 'Banana.csproj' exist. Project files should have a unique name to avoid conflicts in build output.
2221
23-
This repo uses a common output directory (artifacts/bin/$(ProjectName) and artifacts/obj/$(ProjectName)). To avoid confllicts in build output, each
22+
This repo uses a common output directory (artifacts/bin/$(ProjectName) and artifacts/obj/$(ProjectName)). To avoid conflicts in build output, each
2423
project file should have a unique name.
2524

26-
### Error MSB4236 / Unable to locate the .NET Core SDK
27-
25+
## Error CS0006
26+
27+
Opening solution filters and building may produce an error code CS0006 with a message such as
28+
29+
> Error CS0006 Metadata file '&hellip;\AspNetCore\artifacts\bin\Microsoft.AspNetCore.Metadata\Debug\netstandard2.0\Microsoft.AspNetCore.Metadata.dll' could not be found
30+
31+
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.
32+
33+
### You can fix this in one of three ways
34+
35+
1. Build the project on command line. In most cases, running `build.cmd` on command line solves this problem.
36+
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.
37+
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.
38+
39+
## Error MSB4019: The imported project "&hellip;\artifacts\bin\GenerateFiles\Directory.Build.props" was not found
40+
41+
You have likely attempted to use `dotnet` to build a project in the repo without first generating the required files.
42+
Prior to building without `.\build.cmd` or `./build.sh` at least the following **must** be executed:
43+
44+
```powershell
45+
.\build.cmd -noBuildNative -noBuildManaged
46+
```
47+
48+
or
49+
50+
```bash
51+
./build.sh --no-build-managed
52+
```
53+
54+
## Error MSB4236: Unable to locate the .NET Core SDK
55+
2856
Executing `.\restore.cmd` or `.\build.cmd` may produce these errors:
2957

3058
> 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.
3159
> error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.
3260
3361
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_.
62+
63+
## Error: HTTP Error 500.33 - ANCM Request Handler Load Failure
64+
65+
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.
66+
67+
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.
68+
69+
Example of running the `MvcSandbox` project:
70+
71+
`.\startvs.cmd .\src\Mvc\Mvc.sln`
72+
73+
![Web host options in Visual Studio](./vs-iis-express-aspnet-core-mvc-sandbox.jpg)
74+
75+
## Error: Unable to load the service index for &hellip;
76+
77+
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
78+
79+
> &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]
80+
81+
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.
82+
83+
## Warning: Requested Microsoft.AspNetCore.App v&hellip; does not exist
84+
85+
You have likely attempted to build projects or execute tests which require the just-build Microsoft.AspNetCore.App
86+
shared framework. Execute the following to ensure that exists within the `$(DOTNET_ROOT)` folder:
87+
88+
```powershell
89+
.\build.cmd -projects src\Framework\App.Runtime\src\Microsoft.AspNetCore.App.Runtime.csproj
90+
```
91+
92+
or
93+
94+
```bash
95+
./build.sh --projects "$PWD/src/Framework/App.Runtime/src/Microsoft.AspNetCore.App.Runtime.csproj"
96+
```

0 commit comments

Comments
 (0)