dapper - .NET 标准 2.0 项目无法加载 Dapper 1.50.5

标签 dapper .net-standard-2.0

我刚刚开始使用 .NET 标准。在一个概念验证项目中,我尝试使用 Dapper 作为我的 ORM。在.NET Standard 2.0类库项目中,我添加了Dapper 1.50.5 Nuget包。但是,该程序集不会在运行时加载。 我收到此错误:

System.IO.FileNotFoundException   HResult=0x80070002
Message=Could not load file or assembly 'Dapper, Version=1.50.5.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
The system cannot find the file specified.

我的 .csproj 的完整内容:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Dapper" Version="1.50.5" />
    <PackageReference Include="Npgsql" Version="4.0.4" />
    <PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
    <PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
    <PackageReference Include="System.Reflection.TypeExtensions" Version="4.5.1" />
    <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
    <PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.1" />
  </ItemGroup>
</Project>

所以,你看我已经安装了依赖项和依赖项的依赖项。

我还应该做什么?

最佳答案

.NETStandard 程序集已添加为对我的 WPF 项目的引用。我需要对 WPF 项目的 .csproj 进行更改。

https://github.com/dotnet/sdk/issues/901中提到的解决方案修复它。

步骤:

  1. 在记事本中编辑核心 .csproj 文件。
  2. 在其中找到的每行中添加以下两行。

    <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    
  3. 清理并重建您的解决方案。

Yes... I used Notepad.

关于dapper - .NET 标准 2.0 项目无法加载 Dapper 1.50.5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53714664/

相关文章:

c# - 为什么这个小巧的查询返回 null?

c# - 使用存储过程进行多重映射的 Dapper

c# - 为什么 AutogenerateBindingRedirects 不适用于 Visual Studio 2017 中的 Web.config

ado.net - 如何使用 Dapper 获取 SqlDataReader?

c# - 不使用匿名对象时 Dapper 动态参数抛出 SQLException "must define scalar variable"

dapper - Dapper 的简单内连接结果?

asp.net-core-2.1 - 找不到 AddCommandLine .netcore 2.1

c# - 当 .NET 462 项目引用时,.NET Standard 2.0 dll 的 transient 依赖项在 bin 中丢失

visual-studio-2017 - .net 4.7.2 库引用标准 2.0 NuGetPackage 不起作用

c# - 为什么 .NET Standard 2.0 完全支持 Span,即使 MS 将其列为不支持?