.Net Core应用程序中缺少NativeCallableAttribute

gho*_*ord 1 .net c# .net-core coreclr

我在github上的coreclr存储库中找到了NativeCallableAttribute的实现。它看起来像是2年前添加的,并且您可以找到显示它与.Net Framework的非托管导出一样的单元测试。

我创建了一个新的.Net core 2.0项目NativeCallableAttributeSystem.Runtime.InteropServices名称空间中没有任何内容。是否需要添加一些nuget包才能使用此类?我试过nuget包,System.Runtime.InteropServices但仍然缺少属性。

Cod*_*ler 5

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

更新:

在哪里可以获得System.Private.CoreLib?在nuget上找不到它,并且Visual Studio中的.Net Core项目没有它。

我在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>
Run Code Online (Sandbox Code Playgroud)