Skip to content

CLI Tools: Error when MSBuildProjectExtensionsPath doesn't exist #8816

@karabaja4

Description

@karabaja4

Hello, I have trouble scaffolding an existing Sqlite database model when a separate netstandard1.6 class library is used as a DataLayer project and BaseIntermediateOutputPath is set to a different obj/ folder with --msbuildprojectextensionspath, as per example below:


Directory structure:

out/
  project.DataLayer/
    bin/
    obj/
  project.WebApp/
    bin/
    obj/
src/
  project.DataLayer/
    project.DataLayer.csproj
  project.WebApp/
    project.WebApp.csproj

projects.DataLayer.csproj

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

  <PropertyGroup>

    <TargetFramework>netstandard1.6</TargetFramework>

    <BaseOutputPath>../../out/$(AssemblyName)/bin</BaseOutputPath>
    <BaseIntermediateOutputPath>../../out/$(AssemblyName)/obj</BaseIntermediateOutputPath>

  </PropertyGroup>

  <ItemGroup>

    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="1.1.2" />
    
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Design" Version="1.1.2" />
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" />
    
  </ItemGroup>

</Project>

project.WebApp.csproj

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

  <PropertyGroup>
  
    <TargetFramework>netcoreapp1.1</TargetFramework>

    <BaseOutputPath>../../out/$(AssemblyName)/bin</BaseOutputPath>
    <BaseIntermediateOutputPath>../../out/$(AssemblyName)/obj</BaseIntermediateOutputPath>

  </PropertyGroup>

  <ItemGroup>
        *snip, irrelevant packages*
       <ProjectReference Include="..\project.Business\project.Business.csproj" /> // has reference to project.DataLayer
  </ItemGroup>

</Project>

For the below commands I am positioned in project.DataLayer folder and I ran dotnet restore and dotnet build on all projects.

When I try to scaffold the database from /src/project.DataLayer with --msbuildprojectextensionspath pointing to /out/project.DataLayer/obj/:

dotnet ef dbcontext scaffold "Datasource=database.db" Microsoft.EntityFrameworkCore.Sqlite --context "AppDbContext" --data-annotations --force --msbuildprojectextensionspath "C:\projects\out\project.DataLayer\obj" --project "C:\projects\src\project.DataLayer\project.DataLayer.csproj" --output-dir "C:\projects\src\project.DataLayer\Models\" --startup-project "C:\projects\src\project.WebApp\project.WebApp.csproj"

C:\projects\src\project.DataLayer\project.DataLayer.csproj : error MSB4057: The target "GetEFProjectMetadata" does not exist in the project.
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.

I get this error, but, if I remove BaseOutputPath and BaseIntermediateOutputPath from both csprojs (then the bin/ and obj/ folders are created in the /src/project.DataLayer folder after dotnet restore and dotnet build) and execute the following command from that folder:

dotnet ef dbcontext scaffold "Datasource=database.db" Microsoft.EntityFrameworkCore.Sqlite --context "AppDbContext" --data-annotations --force --output-dir  "C:\projects\src\project.DataLayer\Models" --startup-project "C:\projects\src\project.WebApp\project.WebApp.csproj"

Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:12.48

then the command is executed successfully and the model is created.

Please note that Scaffold-DbContext works in VS2017 Package Manager Console when I pick project.DataLayer and execute scaffolding with the same configuration (/bin and /obj in separate directory).

EF Core version: 1.1.2
Database Provider: Microsoft.EntityFrameworkCore.Sqlite
Operating system: Windows 10
IDE: Visual Studio Code / CLI Tools

Metadata

Metadata

Assignees

Labels

good first issueThis issue should be relatively straightforward to fix.help wantedThis issue involves technologies where we are not experts. Expert help would be appreciated.

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions