我有两个项目.第一个是Windows窗体应用程序项目,第二个是类库项目.Сlass库项目与FANN合作.Windows窗体是启动项目.
我应该让Fann.Net.dll和fanndoubleMT.dll与FANN一起使用.我下载了这些库并将它们放在一个位于解决方案根目录下的文件夹lib中.
我将Fann.Net.dll作为外部dll添加到类库项目中.我编译了这个项目.我收到一条错误,上面写着"无法加载DLL'fanndoubleMT.dll'.我通过将fanndoubleMT.dll添加到文件夹Windows_Forms_Application\bin\Debug来修复此错误.
我认为这是一个可怕的解决方案,因为我使用git,每次你需要将dll转移到新工作区的这个文件夹.
真诚的,丹尼斯.
lia*_*ang 35
你可以试试这个:
您可以将本机dll添加为链接项,并使用" 如果更新则复制 ".
本机dll的问题在于,有时您会根据项目的配置(调试/发布或平台)使用不同的dll.
您可以编辑项目的.csproj并有条件地链接本机dll:
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|Win32' ">
<Content Include="..\..\..\..\..\bin\Win32\Release\fanndoubleMT.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|Win32' ">
<Content Include="..\..\..\..\..\bin\Win32\Debug\fanndoubleMT_d.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<Content Include="..\..\..\..\..\bin\x64\Debug\fanndoubleMT_d.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<Content Include="..\..\..\..\..\bin\x64\Release\fanndoubleMT.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
请注意,复制选项设置为PreserveNewest,这意味着"如果更新则复制".
以上liang写的解决方案只适用于扁平化的项目结构!您可能希望将解决方案中的所有 DLL 组织到一个名为“Dependencies”的文件夹中。但请注意,文件是相对于解决方案资源管理器中的项目结构复制的。(使用 Visual Studio 2015 测试)
现在您应该具有以下解决方案资源管理器结构:
Your Project
- class1.cs
- Dependencies\Fann.Net.dll
- Dependencies\fanndoubleMT.dll
Run Code Online (Sandbox Code Playgroud)
添加后期构建步骤:
xcopy "$(TargetDir)\Dependencies" "$(TargetDir)" /s /e /h /Y
Run Code Online (Sandbox Code Playgroud)
这种将文件添加到项目和创建后期构建步骤相结合的解决方案具有以下优点:
小智 5
您不能"添加引用"到非托管dll.一种解决方案是在Windows窗体项目中添加Post Build Event.类似于:xcopy ..\lib\fanndoubleMT.dll $(TargetPath)post build事件也可以执行.cmd或.bat文件
您仍然需要对托管程序集的引用'Fann.Net.dll'
| 归档时间: |
|
| 查看次数: |
41475 次 |
| 最近记录: |