Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet ef migrations fails with Directory.Build.props #23691

Closed
eddieparker opened this issue Dec 15, 2020 · 6 comments
Closed

dotnet ef migrations fails with Directory.Build.props #23691

eddieparker opened this issue Dec 15, 2020 · 6 comments
Assignees
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported

Comments

@eddieparker
Copy link

Using the attached zip file, I can't get dotnet ef migrations add InitialCreate to work with the given Directory.Build.props. I've tried various incantations of --msbuildprojectextensionspath and they all yield the following error:

D:\dev\personal\csharpsandbox\csharpsandbox.csproj : 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.

If you delete the Directory.Build.props file the sample builds fine however.

Include provider and version information

EF Core version: 5.0.1
Database provider: Sqlite
Target framework: .netcore 3.1
Operating system: Windows
IDE: VS2019 16.8.3

EFMigrateTest.zip

@ajcvickers
Copy link
Member

@eddieparker Thanks for reporting this; we will investigate in the new year.

@huoyaoyuan
Copy link
Member

If the obj path was changed by Directory.Build.props:
For 5.0.0, it required --msbuildprojectextensionspath option for me. For 5.0.1, it ignores the path and gemerates the targets file in obj (works silently).

@eddieparker
Copy link
Author

If the obj path was changed by Directory.Build.props:
For 5.0.0, it required --msbuildprojectextensionspath option for me. For 5.0.1, it ignores the path and gemerates the targets file in obj (works silently).

Can I ask what you set the --msbuildprojectextensionpath to? Using the above zip file I've tried:

dotnet ef migrations add InitialCreate --msbuildprojectextensionspath _intermediate_/Debug/csharpsandbox and I still end up with:

D:\dev\personal\csharpsandbox\csharpsandbox.csproj : 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.

@huoyaoyuan
Copy link
Member

I haven't downloaded your zip, but seems that you didn't set the base of relative path. For me it was ..\..\Artifact\obj\ProjectName\Debug\. Here..\.. navigates from the project path to the root path.

@bricelam
Copy link
Contributor

bricelam commented Jan 5, 2021

Here is the correct way to configure MSBuildProjectExtensionsPath in your project:

<Project> <!-- Note: No Sdk="" here. -->

  <PropertyGroup>
     <!-- Don't use $(Configuration) since it isn't set yet. -->
    <MSBuildProjectExtensionsPath>$(MSBuildProjectDirectory)\_intermediate_\</MSBuildProjectExtensionsPath>
  </PropertyGroup>

  <!-- MSBuildProjectExtensionsPath must be set before this gets imported. Directory.Build.props is too late. -->
  <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

  <!-- (Project content goes here) -->

  <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

</Project>

Then you can use the option on the command line:

dotnet ef migrations add InitialCreate --msbuildprojectextensionspath _intermediate_

Trying to set it anywhere else will result in very unexpected behavior that you'll probably need to use a tool like MSBuild Log Viewer to understand why it's not working.

@bricelam
Copy link
Contributor

bricelam commented Jan 5, 2021

As @huoyaoyuan found, the easiest thing to do is to not touch MSBuildProjectExtensionsPath and just use the defaults.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported
Projects
None yet
Development

No branches or pull requests

4 participants