在不受管理的C#.NET库项目中使用NuGet库

问题描述

我正在为名为BIM Vision的软件创建插件。他们有一个围绕C API的包装器,因此我正在使用UnmanagedExports来用包装器对我的非托管DLL进行很好的编译。

问题是我在项目中根本无法使用NuGet库。它们可以很好地编译,但是在我的代码调用任何函数会使软件崩溃。

所有库都与我自己的DLL一起编译在各自独立的DLL中。该软件只能加载我的DLL(因为其他DLL缺少与BIMVision对话的代码

如何使软件找到丢失的DLL?我应该把它们放在哪里?

我的.csproj看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<Project Toolsversion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsversion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsversion)\Microsoft.Common.props')" />
    <PropertyGroup>
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <Platform Condition=" '$(Platform)' == '' ">Anycpu</Platform>
        <ProjectGuid>{362E40F4-4A37-48B3-A7A5-93E5535A9B22}</ProjectGuid>
        <OutputType>Library</OutputType>
        <AppDesignerFolder>Properties</AppDesignerFolder>
        <RootNamespace>ExcelLink</RootNamespace>
        <AssemblyName>ExcelLink</AssemblyName>
        <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
        <FileAlignment>512</FileAlignment>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|Anycpu' ">
        <DebugSymbols>true</DebugSymbols>
        <DebugType>full</DebugType>
        <Optimize>false</Optimize>
        <OutputPath>C:\Users\Daniel\Documents\SAMT\BIMVISION SDK\bim_vision_exe\plugins</OutputPath>
        <DefineConstants>DEBUG;TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
        <PlatformTarget>x86</PlatformTarget>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|Anycpu' ">
        <DebugType>pdbonly</DebugType>
        <Optimize>true</Optimize>
        <OutputPath>..\..\..\bim_vision_exe\plugins\</OutputPath>
        <DefineConstants>TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
        <PlatformTarget>x86</PlatformTarget>
    </PropertyGroup>
    <ItemGroup>
        <Reference Include="PresentationCore" />
        <Reference Include="System" />
        <Reference Include="System.configuration" />
        <Reference Include="System.Core" />
        <Reference Include="System.Drawing" />
        <Reference Include="System.Security" />
        <Reference Include="System.Xml.Linq" />
        <Reference Include="System.Data.DataSetExtensions" />
        <Reference Include="Microsoft.CSharp" />
        <Reference Include="System.Data" />
        <Reference Include="System.Xml" />
    </ItemGroup>
    <ItemGroup>
        <Compile Include="C:\Users\Daniel\Documents\SAMT\BIMVISION SDK\sdk .NET\BIMVision.cs">
            <Link>BIMVision.cs</Link>
        </Compile>
        <Compile Include="ExcelLink.cs" />
        <Compile Include="Properties\AssemblyInfo.cs" />
    </ItemGroup>
    <ItemGroup>
        <packagereference Include="EPPlus" Version="4.5.3.3" />
        <packagereference Include="UnmanagedExports" Version="1.2.7" />
        <packagereference Include="ZetaIpc" Version="1.0.0.9" />
    </ItemGroup>
    <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    <Import Project="C:\Users\Daniel\Documents\SAMT\BIMVISION SDK\exmaples .NET\vs_2013\packages\UnmanagedExports.1.2.7\tools/RGiesecke.DllExport.targets" Condition="Exists('C:\Users\Daniel\Documents\SAMT\BIMVISION SDK\exmaples .NET\vs_2013\packages\UnmanagedExports.1.2.7\tools/RGiesecke.DllExport.targets')" />
</Project>

设法使用调试器从软件中获取真正的异常:

Exception thrown at 0x75AA9962 in bim_vision.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x0019C458.

解决方法

按如下所示使用GACUTIL在GAC中安装库DLL即可解决此问题。

gacutil /i [path.dll]

由于System.Buffers软件包的版本不匹配,它仍然没有运行;我安装了正确的版本,并且可以正常工作。