Skip to content

Simplified output path (UseArtifactsOutput) isn't friendly with ef migrations #30725

@virzak

Description

@virzak

File a bug

When using simplified output path adding a migration results in:

Include your code

Run the following

Set up project

dotnet new classlib -o UseArtifactsOutput -f net8.0 --no-restore
cd UseArtifactsOutput
echo "<Project><PropertyGroup><UseArtifactsOutput>true</UseArtifactsOutput></PropertyGroup></Project>" > Directory.Build.props
dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 8.0.0-preview.3.23174.2
dotnet add package Microsoft.EntityFrameworkCore.Design --version 8.0.0-preview.3.23174.2
dotnet build

Notice that obj directory doesn't exist.

Create DbContext.cs with:

using Microsoft.EntityFrameworkCore;

public class MyDbContext : Microsoft.EntityFrameworkCore.DbContext
{
  public MyDbContext(DbContextOptions<MyDbContext> options) : base(options) { }
}

public class TemporaryDbContextFactory : Microsoft.EntityFrameworkCore.Design.IDesignTimeDbContextFactory<MyDbContext>
{
  // remove static if EF stops working
  public static MyDbContext Create()
  {
    var builder = new DbContextOptionsBuilder<MyDbContext>();
    var connection = @"Data Source=(localdb)\mssqlserverlocaldb;Initial Catalog=UseArtifactsOutput";
    builder.UseSqlServer(connection, opt => opt.CommandTimeout(500));
    var vwContext = new MyDbContext(builder.Options);
    return vwContext;
  }

  public MyDbContext CreateDbContext(string[] args) => Create();
}

This won't work

dotnet ef migrations add First

but this will, though unfriendly

dotnet ef migrations add First --msbuildprojectextensionspath .artifacts/obj/UseArtifactsOutput

Include verbose output

The error when not including msbuildprojectextensionspath is:

error MSB4057: The target "GetEFProjectMetadata" does not exist in the project.
Unable to retrieve project metadata. Ensure it's an SDK-style project. If you're using a custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option.

Include provider and version information

EF Core version: 8.0.0-preview.3.23174.2
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: 8.0.0-preview.3

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions