Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在PowerShell 5.1中加载引用EFCore的程序集?_C#_Powershell_Entity Framework Core_Assembly Binding Redirect - Fatal编程技术网

C# 如何在PowerShell 5.1中加载引用EFCore的程序集?

C# 如何在PowerShell 5.1中加载引用EFCore的程序集?,c#,powershell,entity-framework-core,assembly-binding-redirect,C#,Powershell,Entity Framework Core,Assembly Binding Redirect,我正在开发一个C#解决方案,它使用实体框架核心作为持久层。我正在构建的一个项目是二进制PowerShell模块(用C#编写),它引用了我的持久层项目 在PowerShell窗口中编译和测试模块时,第一次尝试运行引用EFCore的任何代码时,我收到以下错误: System.IO.FileNotFoundException:无法加载文件或程序集 'System.ComponentModel.Annotations,版本=4.2.0.0,区域性=中性, PublicKeyToken=b03f5f7f1

我正在开发一个C#解决方案,它使用实体框架核心作为持久层。我正在构建的一个项目是二进制PowerShell模块(用C#编写),它引用了我的持久层项目

在PowerShell窗口中编译和测试模块时,第一次尝试运行引用EFCore的任何代码时,我收到以下错误:

System.IO.FileNotFoundException:无法加载文件或程序集 'System.ComponentModel.Annotations,版本=4.2.0.0,区域性=中性, PublicKeyToken=b03f5f7f11d50a3a'或其依赖项之一。这个 系统找不到指定的文件

有两个项目-持久性和PowerShell。两者都是.NET标准2.0项目,PowerShell项目引用持久性项目。还有一些NuGet依赖项(包括持久性项目中的EFCore依赖项)。这两个项目都使用新的
PackageReference
格式

在此之前,我曾将PowerShell项目创建为.NET Framework 4.7.2,并遇到了相同的问题。我尝试的故障排除步骤之一是将项目重新创建为.NET标准2.0项目

我尝试过的另一个故障排除步骤是添加NuGet包
System.ComponentModel.Annotations
。由于EFCore的依赖性,Visual Studio不允许我安装比4.5.0版本旧的版本,但我确实尝试在持久性和PowerShell项目中安装了4.5.0版本

我正在工作站上使用Windows PowerShell 5.1和.NET Framework 4.7.2。我知道PowerShell 6为.NET标准提供了更好的支持,但不幸的是,由于其他依赖关系,迁移到PowerShell 6不是此项目的选项

我已经看到了几个与EF Core和.NET标准相关的错误消息和程序集示例:

不幸的是,这些线程中建议的大多数解决方案都描述了在app.config文件中设置程序集绑定重定向。由于我正在构建PowerShell模块,而不是编译的可执行文件,因此我没有可用的app.config文件来设置此重定向

我可以在代码中设置绑定重定向以指向正确版本的
System.ComponentModel.Annotations.dll

是否有其他方法可以让Windows PowerShell为EFCore功能加载正确版本的程序集