c# - .Net Core 应用程序中缺少 NativeCallableAttribute

标签 c# .net .net-core coreclr

我找到了 NativeCallableAttribute 的实现在 github 上的 coreclr 存储库中。它看起来像是 2 年前添加的,您可以找到单元测试显示它的工作方式与 Unmanaged exports for .Net Framework 一样。 .

我创建了一个新的 .Net 核心 2.0 项目,System.Runtime.InteropServices 命名空间中没有 NativeCallableAttribute。我必须添加一些 nuget 包才能使用此类吗?我试过 nuget 包 System.Runtime.InteropServices 但仍然缺少该属性。

最佳答案

NativeCallableAttribute 驻留在 System.Private.CoreLib 程序集中。只需从您的项目中引用它并为 System.Runtime.InteropServices 命名空间添加 using 指令。

更新:

Where do I get System.Private.CoreLib? Cannot find it on nuget and AddReference dialog in VisualStudio does not have it for my .Net Core project.

我已经使用 ReSharper 添加了程序集引用。您可以通过将以下部分添加到您的 csproj 文件来执行相同的操作:

<ItemGroup>
  <Reference Include="System.Private.CoreLib">
    <HintPath>C:\Program Files\dotnet\shared\Microsoft.NETCore.App\1.0.5\System.Private.CoreLib.dll</HintPath>
  </Reference>
</ItemGroup>

关于c# - .Net Core 应用程序中缺少 NativeCallableAttribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47676065/

相关文章:

c# - 在 .NET Core 类库中使用 Windows 窗体 - .NET Core 控件库

c# - 附加属性不触发 IMultiValueConverter

c# - 如何将数组对象列出来

C# HttpWebRequest Post 方法表单中的许多参数

c# - 由于超时已到.net core,执行 DbCommand 失败

c# - EF Core 为标识列插入显式值

c# - ReSharper 表示此表达式始终为真。为什么?

c# - 在属性(property)中回归自己

.net - 是否有通用 CIL 代码将任何类型实例转换为字符串?

c# - 使用 C# 从 2 个表更新数据库