dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.76k stars 3.18k forks source link

The `dotnet ef dbcontext scaffold` command does not print all expected logs #26384

Closed 0xced closed 2 years ago

0xced commented 3 years ago

This is a regression from EF Core 5.

With .NET 5 / EF Core 5

.config/dotnet-tools.json

{
  "version": 1,
  "isRoot": true,
  "tools": {
    "dotnet-ef": {
      "version": "5.0.11",
      "commands": [
        "dotnet-ef"
      ]
    }
  }
}

ef5scaffold.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.11" PrivateAssets="all" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.11" />
  </ItemGroup>

</Project>

global.json

{
  "sdk": {
    "version": "5.0.402"
  }
}
$ dotnet --version
5.0.402
$ dotnet ef --version
Entity Framework Core .NET Command-line Tools
5.0.11

Running dotnet ef dbcontext scaffold --verbose --no-onconfiguring "Server=sqlprosample.database.windows.net;Database=sqlprosample;User=sqlproro;Password=nh{Zd?*8ZU@Y}Bb#" Microsoft.EntityFrameworkCore.SqlServer prints many verbose logs. This is the expected behaviour.

Using assembly 'ef5scaffold'.
Using startup assembly 'ef5scaffold'.
Using application base '~/Projects/Experiments/ef5scaffold/bin/Debug/net5.0'.
Using working directory '~/Projects/Experiments/ef5scaffold'.
Using root namespace 'ef5scaffold'.
Using project directory '~/Projects/Experiments/ef5scaffold/'.
Remaining arguments: .
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding design-time services referenced by assembly 'ef5scaffold'...
Finding design-time services referenced by assembly 'ef5scaffold'...
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly 'ef5scaffold'...
No design-time services were found.
Found default schema 'dbo'.
Found type alias with name: sys.sysname which maps to underlying data type nvarchar(128).
Found table with name: dbo.BuildVersion.
Found table with name: dbo.ErrorLog.
Found table with name: dbo.towns.
Found table with name: SalesLT.Address.
Found table with name: SalesLT.Customer.
Found table with name: SalesLT.CustomerAddress.
Found table with name: SalesLT.Product.
Found table with name: SalesLT.ProductCategory.
Found table with name: SalesLT.ProductDescription.
Found table with name: SalesLT.ProductModel.
Found table with name: SalesLT.ProductModelProductDescription.
Found table with name: SalesLT.SalesOrderDetail.
Found table with name: SalesLT.SalesOrderHeader.
Found table with name: SalesLT.vGetAllCategories.
Found table with name: SalesLT.vProductAndDescription.
Found table with name: SalesLT.vProductModelCatalogDescription.
Found column with table: dbo.BuildVersion, column name: SystemInformationID, ordinal: 1, data type: sys.tinyint, maximum length: 1, precision: 3, scale: 0, nullable: False, identity: True, default value: (null), computed value: (null), computed value is stored: False
Found column with table: dbo.BuildVersion, column name: Database Version, ordinal: 2, data type: sys.nvarchar, maximum length: 50, precision: 0, scale: 0, nullable: False, identity: False, default value: (null), computed value: (null), computed value is stored: False
Found column with table: dbo.BuildVersion, column name: VersionDate, ordinal: 3, data type: sys.datetime, maximum length: 8, precision: 23, scale: 3, nullable: False, identity: False, default value: (null), computed value: (null), computed value is stored: False
Found column with table: dbo.BuildVersion, column name: ModifiedDate, ordinal: 4, data type: sys.datetime, maximum length: 8, precision: 23, scale: 3, nullable: False, identity: False, default value: (null), computed value: (null), computed value is stored: False
[…]

With .NET 6 / EF Core 6

.config/dotnet-tools.json

{
  "version": 1,
  "isRoot": true,
  "tools": {
    "dotnet-ef": {
      "version": "6.0.0-rc.2.21480.5",
      "commands": [
        "dotnet-ef"
      ]
    }
  }
}

ef6scaffold.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0-rc.2.21480.5" PrivateAssets="all" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0-rc.2.21480.5" />
  </ItemGroup>

</Project>

global.json

{
  "sdk": {
    "version": "6.0.100-rc.2.21505.57"
  }
}
$ dotnet --version
6.0.100-rc.2.21505.57
$ dotnet ef --version
Entity Framework Core .NET Command-line Tools
6.0.0-rc.2.21480.5

Running the same command dotnet ef dbcontext scaffold --verbose --no-onconfiguring "Server=sqlprosample.database.windows.net;Database=sqlprosample;User=sqlproro;Password=nh{Zd?*8ZU@Y}Bb#" Microsoft.EntityFrameworkCore.SqlServer does not print verbose logs anymore. Here is the full output:

Using assembly 'ef6scaffold'.
Using startup assembly 'ef6scaffold'.
Using application base '~/Projects/Experiments/ef6scaffold/bin/Debug/net6.0'.
Using working directory '~/Projects/Experiments/ef6scaffold'.
Using root namespace 'ef6scaffold'.
Using project directory '~/Projects/Experiments/ef6scaffold/'.
Remaining arguments: .
Finding design-time services referenced by assembly 'ef6scaffold'...
Finding design-time services referenced by assembly 'ef6scaffold'...
No referenced design-time services were found.
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding IDesignTimeServices implementations in assembly 'ef6scaffold'...
No design-time services were found.

All the Found default schema, Found table, Found column with table, Found primary key with name are not printed anymore at all.

Also, scaffolding on this particular database should produce warnings (see #25729 and #25748) but they are not printed at all, regardless of the --verbose option. It looks like the many different logging/diagnostics/reporter components at play during scaffolding are not properly hooked together.

ajcvickers commented 3 years ago

/cc @bricelam

bricelam commented 3 years ago

Possibly related to the design-time services changes...

ajcvickers commented 3 years ago

Note for triage: cofirmed this still repros with the latest daily build. Does look like it is due to service scoping changes, but haven't been able to pinpoint the issue.

ajcvickers commented 2 years ago

FYI for those impacted by this issue: EF Core 6.0.1 is now available from NuGet.