I have a C# / ASP.NET MVC project using Entity Framework 6. When I am deploying database migrations by running
Update-Database -Verbose
in the Package Manager Console in Visual Studio, everything works.
With the -Verbose flag, this is the (slightly redacted) command that is displayed in the console and that I assume is what is actually executed:
{package dir}\EntityFramework.6.5.1\tools\net45\any\ef6.exe
database update --verbose --no-color --prefix-output --assembly {assembly dll}
--project-dir {project dir} --language C# --data-dir {data dir}
--root-namespace <namespace> --config {config dir/Web.config}
When I run that exact same command (via copy/paste) in a PowerShell console (i.e., NOT within the Package Manager Console in Visual Studio), I get assembly binding redirect errors.
info: System.IO.FileLoadException: Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
In my config files, I have these assembly binding redirects:
<dependentAssembly>
<assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
</dependentAssembly>
It seems like ef6.exe is not respecting my assembly binding redirects when run outside the Package Manager Console.
Do you have any ideas on why the same ef6.exe command fails to load the assembly when run from a PowerShell console, but works fine in the Package Manager Console in Visual Studio? What context is established in the Package Manager Console that doesn't exist in a PowerShell console?
System.ComponentModel.Annotationsassembly isn't available in a regular Windows PowerShell session (built on .NET Framework), but it is in a PowerShell (Core) 7 session (built on .NET (Core)).