Skip to content

Improve generation and use of ref/ projects #17311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 56 commits into from
Dec 11, 2019
Merged

Conversation

dougbu
Copy link
Contributor

@dougbu dougbu commented Nov 21, 2019

This PR is a fairly large cleanup of our 'release/3.0' work to at least get implementation assemblies built against ref/ assemblies. It has the following aims:

  • remove workarounds to the extent possible
  • where the above isn't possible, centralize workarounds (for simplicity and to remove redundancy)
  • avoid overloading the compiler with an extreme list of referenced assemblies
  • eliminate as much complexity as possible in the relevant infrastructure

Stretch goals include:

  • limit bloat of the ref/ assemblies
  • improve ref/ project generation bootstrapping (speedup, avoid unexpected errors)

@dougbu
Copy link
Contributor Author

dougbu commented Nov 21, 2019

This PR is incomplete. Please see Build.log (containing ~560 errors) and Build.unique.log (containing the ~190 unique errors).

In addition, the src\Identity\Extensions.Stores\ref\Microsoft.Extensions.Identity.Stores.Manual.cs file is empty. Just waiting to find what types we're using.

@dougbu
Copy link
Contributor Author

dougbu commented Nov 22, 2019

Steps to handle the internal members that test, sample and perf code is complaining about:

  1. find the relevant *.cs file on disk
  2. navigate to the containing src/ folder
  3. dotnet msbuild /t:GenerateReferenceSource /p:AdditionalGenApiCmdOptions="--all"
  4. cp ..\ref\*.netcoreapp3.0.cs ..\ref\save.cs
  5. cp ..\ref\*.netcoreapp3.0.cs ..\ref\{project}.Manual.cs # if file doesn't exist yet
  6. dotnet msbuild /t:GenerateReferenceSource # easy to forget! (don't forget)
  7. if the *.Manual.cs file didn't exist, pare it down to the missing members
    • otherwise, find the missing members and copy them into the existing *.Manual.cs file
  8. remove almost all private members and associated attributes
    • replace __dummy* fields in structs with those from implementation type
      • GenAPI sometimes doesn't generate fields correctly, even if public
      • copying the actual fields also ensures sizeof(...) works properly and doesn't hurt anything
      • leave __dummy and __dummyPrimitive fields alone only if implementation struct has no fields
    • leave private constructors calling a base constructor
    • remove [AsyncStateMachine] attributes; they almost always refer to private classes
  9. dotnet msbuild ..\test\ # to see what is still missing in the ref/ project you're changing

Suggest splitting up by ref/ project area to avoid both working on ProjectA because it contains missing members at opposite ends of the alphabet.

FYI I grabbed the warnings-only log using "/flp:v=quiet;logfile=.\artifacts\log\Debug\Build.log" on the build command line.

@dougbu
Copy link
Contributor Author

dougbu commented Nov 22, 2019

Most urgent thing is to test building (and executing) variants of e.g. src\SignalR\samples\ClientSample outside the AspNetCore repo i.e. with the 3.0.1 targeting pack / SDK and all @(Reference) items turned into @(PackageReference) items. If there be dragons, may need something drastic like building more of Extensions and all of EF Core against ref/ assemblies. (Yes, the second would be very strange given EF Core packages target .NET Standard. Worst case, the projects would need to be multi-targeted.) I'm of course hoping no problems arise and we can paper over the issues with a few additional direct references on Extensions packages.

I suggest changing Extensions very slightly to build Microsoft.Extensions.Logging.Testing and maybe one or two other internal packages against ref/ assemblies.

@dougbu dougbu changed the base branch from dougbu/update.baselines to release/3.0 November 22, 2019 06:28
@dougbu
Copy link
Contributor Author

dougbu commented Nov 22, 2019

First 4 commits have already been merged -- in #17245. Visible because I changed the base branch to 'release/3.0' and GitHub hasn't noticed those changes are already there.

@dougbu dougbu force-pushed the dougbu/ref.references.II branch from 16f6c6d to e0ca7fa Compare November 22, 2019 06:38
@dougbu
Copy link
Contributor Author

dougbu commented Nov 22, 2019

Changed my mind and rebased the branch. See you all in a few days.

@Pilchie Pilchie added the area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework label Nov 22, 2019
@JunTaoLuo JunTaoLuo added this to the 3.0.2 milestone Nov 22, 2019
@dougbu dougbu force-pushed the dougbu/ref.references.II branch from a9db76d to 7d97608 Compare December 7, 2019 03:29
@dougbu
Copy link
Contributor Author

dougbu commented Dec 7, 2019

Rebased to pick up a few more fixes e.g. @wtgodbe's cafb50c and 89aae45

- restrict when `$(HasReferenceAssembly)` is `true` by default
- add warnings when `$(IsAspNetCoreApp)` or `$(HasReferenceAssembly)` have unexpected values
- associated implementation projects no longer have `$(HasReferenceAssembly)` set to `true`
@dougbu
Copy link
Contributor Author

dougbu commented Dec 7, 2019

Bit more about handling private members: The main reasons __dummy, __dummyPrimitive and similar private fields exist in what GenAPI generates are covered in https://blog.paranoidcoding.com/2016/02/15/are-private-members-api-surface.html

So, the private member handling I described above is correct but involves more copying than absolutely required. Because sizeof(...) is usually evaluated at runtime, copying all of a struct's private fields isn't always mandatory. But, it is mandatory to check the real (implementation) type, to copy public and internal fields, and to copy everything when [StructLayout] is specified on the real type i.e. might as well copy the fields over.

Note: Any [StructLayout] on the real type means the fields must be copied over w/ their offsets or (if LayoutKind.Sequential) in the correct order.

- see dotnet/arcade#4488
- generation for these members leads to NREs
- Identity/Core
- Identity/Extensions.Core
- Mvc/Mvc.ViewFeatures
@wtgodbe
Copy link
Member

wtgodbe commented Dec 9, 2019

The only remaining non-CS1705 is:

F:\workspace_work\1\s\src\Components\Web.JS\Microsoft.AspNetCore.Components.Web.JS.npmproj : error MSB4057: The target "GetTargetPath" does not exist in the project.

Plus a couple NU5128 warnings:

F:\workspace_work\1\s.dotnet\sdk\3.0.101\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): warning NU5128: Some target frameworks declared in the dependencies group of the nuspec and the lib/ref folder do not have exact matches in the other location. Consult the list of actions below: [F:\workspace_work\1\s\src\Servers\IIS\AspNetCoreModuleV2\Symbols\Microsoft.AspNetCore.ANCMSymbols.csproj]
F:\workspace_work\1\s.dotnet\sdk\3.0.101\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): warning NU5128: - Add lib or ref assemblies for the netcoreapp3.0 target framework [F:\workspace_work\1\s\src\Servers\IIS\AspNetCoreModuleV2\Symbols\Microsoft.AspNetCore.ANCMSymbols.csproj]
F:\workspace_work\1\s.dotnet\sdk\3.0.101\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): warning NU5128: Some target frameworks declared in the dependencies group of the nuspec and the lib/ref folder do not have exact matches in the other location. Consult the list of actions below: [F:\workspace_work\1\s\src\Analyzers\shared\FeatureDetection\Microsoft.AspNetCore.Analyzers.FeatureDetection.Sources.csproj]
F:\workspace_work\1\s.dotnet\sdk\3.0.101\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): warning NU5128: - Add lib or ref assemblies for the netstandard1.0 target framework [F:\workspace_work\1\s\src\Analyzers\shared\FeatureDetection\Microsoft.AspNetCore.Analyzers.FeatureDetection.Sources.csproj]

Source build is fixed now!

John Luo and others added 6 commits December 10, 2019 16:08
- add direct references to some test and sample projects to make intent clear i.e. address CS1705 root cause
  - these projects must use implementation assemblies for those direct references
  - requirement also applies to anything depending on them e.g. functional tests
  - for simplicity, use `$(CompileUsingReferenceAssemblies)` instead of targeted `@(Reference)` metadata
- leads to ~40 projects that do not themselves add ref/ metadata
  - this is _not_ transitive i.e. it applies only to projects that override `$(CompileUsingReferenceAssemblies)`
@dougbu dougbu force-pushed the dougbu/ref.references.II branch from cfbcf2e to 76363d1 Compare December 11, 2019 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants