我找到了 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/