Skip to content

dotnet ef migrations fail when using custom output paths and separate project/startup-projects #23853

@chris-garrett

Description

@chris-garrett

dotnet ef migrations fail when using custom output paths and separate project/startup-projects

Hi folks,

I'm trying to get my projects setup in docker and I'm running into this error:

error MSB4057: The target "GetEFProjectMetadata" does not exist in the project.

I used Brice's suggestion here #23691 (comment) and it works but only when everything is in a single project.

Other issues that are similar but I'm either missing a step or this is broken.
#23691
#12220

Example repo

I have a repo with 4 scenarios here: https://github.com/chris-garrett/EfTools. I removed docker for the time being since this is reproducible without it.

  1. d180df5 Everything in one project with no modifications to output paths: Works
  2. 7f0c9b3 Everything in one project with modifications to output paths ([obj|bin]/containers): Works
  3. 1fb088e Separate projects for contexts / migration tool with no modifications to output paths: Works
  4. 5c264bc Separate projects for contexts / migration tool with modifications to output paths ([obj|bin]/containers): Does not work

Steps

# nuke any bin/obj folders
$ ./tools-nuke.sh

# create the migration
$ ./tool-create-migration.sh InitialMigration

# run the migration and verify its working
$ ./tool-migrate.sh

Verbose output

$ ./tool-create-migration.sh InitialMigration
Using project './EfTools.Data.csproj'.
Using startup project '../EfTools.Migrations/EfTools.Migrations.csproj'.
Writing 'obj/container/EfTools.Data.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=/tmp/tmpm1K4cl.tmp /verbosity:quiet /nologo ./EfTools.Data.csproj
Writing 'obj/container/EfTools.Migrations.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=/tmp/tmpKnaJFl.tmp /verbosity:quiet /nologo ../EfTools.Migrations/EfTools.Migrations.csproj                                                                                                                     
/mnt/nvme0/projects/dotnet/eftools/EfTools.Migrations/EfTools.Migrations.csproj : error MSB4057: The target "GetEFProjectMetadata" does not exist in the project.                                                                                                                           
Microsoft.EntityFrameworkCore.Tools.CommandException: 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.                     
   at Microsoft.EntityFrameworkCore.Tools.Project.FromFile(String file, String buildExtensionsDir, String framework, String configuration, String runtime)                                                                                                                                  
   at Microsoft.EntityFrameworkCore.Tools.RootCommand.Execute(String[] _)                                                                     
   at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0.<Configure>b__0(String[] args)                            
   at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)                                                          
   at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)                                                                         
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. 

Provider and version information

EF Core version: 5.0.1
Database provider: Microsoft.EntityFrameworkCore.Sqlite
Target framework: .NET 5.0.101
Operating system: Ubuntu 20.04.1 LTS
IDE: command line

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions