Unable to retrieve project metadata. Ensure it's an MSBuild-based .NET Core project
Asked Answered
C

7

24

I've been researching a lot online but did not find a proper solution. I was trying to use Entity Framework Core with MySQL by using database-first scaffold method to mapping table model while always received this error when applied the command

Unable to retrieve project metadata. Ensure it's an MSBuild-based .NET Core project. If you're using custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option.

This is the command I am using to scaffold the database model:

Scaffold-DbContext "server=localhost;port=3306;user=root;password=1234;database=world" "Pomelo.EntityFrameworkCore.MySql" -OutputDir .\Models -f

And this is my .Net Core project setting:

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.1" />
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.0.1" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.1" />
  </ItemGroup>
Cursory answered 4/6, 2018 at 2:40 Comment(3)
did you find a solution?Flotage
any news on this?Livvi
To all future people having this issue. If you set the startup project, remember to take into account the folder. I was getting the same error because I specified "../Api.csproj" when it should have been "../Api/Api.csproj"Notification
T
5

For EF Core 3

I think the powershell command has gone away for EF Core 3 so I'm using dotnet ef dbcontext scaffold

With this command, if you're converting a Scaffold-DbContext script the project name (parameter --project) needs to have .csproj on the end - it can't just the extensionless name.

Tarp answered 23/10, 2019 at 22:27 Comment(2)
In my case I lost 3 days in this ridiculous problem.Booma
I was getting the error trying to run the command dotnet-ef migrations add First --project DotNetCoreTest. Adding the extension .csproj with the project name resolved the issueAulos
K
3

I got this error trying to add a new migration on the command line with dotnet ef migrations add NewMigration.

The solution for me was indeed to append --msbuildprojectextentionspath obj/local.

Koenraad answered 29/11, 2019 at 15:15 Comment(1)
This worked for me as well because I was using the following to change the build properties: <Project> <PropertyGroup Condition="'$(DOTNET_RUNNING_IN_CONTAINER)' != 'true'"> <BaseIntermediateOutputPath>$(MSBuildProjectDirectory)/obj/local/</BaseIntermediateOutputPath> <BaseOutputPath>$(MSBuildProjectDirectory)/bin/local/</BaseOutputPath> </PropertyGroup> </Project>Habsburg
I
2

For my case this error was solved by downloading latest dotnet-sdk-2.2.107-win-x64

for VS2017 and then dropping and updating database through cmd:

dotnet ef database drop --force --context <<dbcontext>> -s <<startup project directory>> -p <<project directory>>


dotnet ef database update --context <<dbcontext>> -s <<startup project directory>> -p <<project directory>>
Intort answered 13/6, 2019 at 11:16 Comment(0)
B
1

Here goes the definitively solution for this problem.

I work with Rider Ide constructing a Web Api, using Net core 3 with Pomelo.MySql

I have tree layers defining my application:

Test.Domain - Class Library defining my models Test.Infra.DataAccess - Class library defining my DbContext Test.Service.RestApi - Net Core Api Project, where I define the AppContext in Startup file. Like This:

public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContextPool<AerjDbContext>(
            options => options.UseMySql(Configuration.GetConnectionString("MySqlConnectionString"),
                mysqlOptions => mysqlOptions.ServerVersion(new Version(8,0,19), ServerType.MySql)
                    .EnableRetryOnFailure()
            ));
    }

This is quite normal, the magic occurs here:

Initiate migrations:

dotnet ef migrations add InitialCreate --startup-project "../<Here the name of the project where startup file was configured>"

It'll create the migrations

then we have to update database with sabe command structure;

dotnet ef database update --startup-project "../<Here the name of the project where startup file was configured>"
Booma answered 25/5, 2020 at 5:20 Comment(1)
what type of project did you use for the one defining your DbContext? and which project folder did you run 'dotnet ef migrations add InitialCreate'?Monetmoneta
T
0

enter image description here

I have tried different solutions to solve this error. Did following change in .csproj file.

enter image description here

Solved this issue for .Net Core by edit .csproj file and removed Import tag and then run ef command again in command line.

Tripartite answered 20/9, 2019 at 8:47 Comment(0)
C
0

EF migrations with .NETCore 2.2 can be smoke-tested using migrations list:

dotnet ef migrations list --startup-project <app-startup-project-dir> --project <dal-project-dir> --context App.DAL.ApplicationDbContext

--context must point to the fully qualified name of the DbContext class that you want to manipulate.

Canaigre answered 8/12, 2020 at 13:27 Comment(0)
T
-5

Add this parameter to the end of your scaffold command "--msbuildprojectextensionspath".

Takara answered 24/9, 2018 at 23:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.