NET 5 error when adding migration on Entity Framework Core NET 5 error when adding migration on Entity Framework Core docker docker

NET 5 error when adding migration on Entity Framework Core


After doing some research, it seems that there is a problem with projects with docker integration and the EF Core tooling.

I have downloaded your code and this is the content of your Directory.Build.props

<Project>  <PropertyGroup>    <DefaultItemExcludes>$(DefaultItemExcludes);$(MSBuildProjectDirectory)/obj/**/*</DefaultItemExcludes>    <DefaultItemExcludes>$(DefaultItemExcludes);$(MSBuildProjectDirectory)/bin/**/*</DefaultItemExcludes>  </PropertyGroup>  <PropertyGroup Condition="'$(DOTNET_RUNNING_IN_CONTAINER)' == 'true'">    <BaseIntermediateOutputPath>$(MSBuildProjectDirectory)/obj/container/</BaseIntermediateOutputPath>    <BaseOutputPath>$(MSBuildProjectDirectory)/bin/container/</BaseOutputPath>  </PropertyGroup>  <PropertyGroup Condition="'$(DOTNET_RUNNING_IN_CONTAINER)' != 'true'">    <BaseIntermediateOutputPath>$(MSBuildProjectDirectory)/obj/local/</BaseIntermediateOutputPath>    <BaseOutputPath>$(MSBuildProjectDirectory)/bin/local/</BaseOutputPath>  </PropertyGroup></Project>

According to @bricelam in this issue the root of the problem lies here:

Changing BaseIntermediateOutputPath from its default when not running inside acontainer breaks the EF Core tooling experience (*)

Since your BaseIntermediateOutputPath was changed from its default to obj/local when running outside the docker container, what you need to do is let the EF Core CLI know where to find that folder. You can accomplish that by using the --msbuildprojectextensionspath parameter. In your case, it would like like this (as suggested here):

dotnet ef migrations add NewMigration --msbuildprojectextensionspath obj/local

If you are still unable to make it work, you could follow the discussion in this other issue. In there, it was suggested that another possible fix is to change a bit your Directory.Build.props and *.csproj files so that the latter looks like the following:

<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>