情景:用c#wpf写DALSA线扫相机的项目,生成时不报错,运行到DALSA相关的代码就报错找不到dll(DALSA的技术支持没给到任何支持 )
一.根据框架选择dll
- 如果是.net framework框架(比如说.net480),就选择
Teledyne DALSA\Sapera\Components\NET\Bin\DALSA.SaperaLT.SapClassBasic.dll
- 如果是.net core框架(比如说.net6.0),就选择
Teledyne DALSA\Sapera\Components\NET\Bin\DALSA.SaperaLT.SapClassBasic.Core.dll
- 注意,这两个框架的dll不能用反了,否则要报dll无法加载的错误。
二. 如果对一个项目,要生成两个不同框架的版本,要引用两个dll怎么办?
1.用记事本打开你用到DALSA DLL的项目的csproj
2.让该项目支持两个框架:
xml
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>net6.0-windows;net48</TargetFrameworks>
<UseWPF>true</UseWPF>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
3.让不同框架下用不同的dll:
xml
<ItemGroup Condition=" '$(TargetFramework)' == 'net48' ">
<Reference Include="DALSA.SaperaLT.SapClassBasic">
<HintPath>E:\Software\Teledyne DALSA\Sapera\Components\NET\Bin\DALSA.SaperaLT.SapClassBasic.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0-windows' ">
<Reference Include="DALSA.SaperaLT.SapClassBasic.Core">
<HintPath>E:\Software\Teledyne DALSA\Sapera\Components\NET\Bin\DALSA.SaperaLT.SapClassBasic.Core.dll</HintPath>
</Reference>
</ItemGroup>
三.还是报错的其他原因
查看启动项目的FodyWeavers.xml
,排除 DALSA.SaperaLT.SapClassBasic.Core 和 DALSA.SaperaLT.SapClassBasic 两个程序集,不将它们嵌入到主程序集中。
xml
<Costura IncludeRuntimeReferences='false' >
<ExcludeAssemblies>
DALSA.SaperaLT.SapClassBasic.Core
DALSA.SaperaLT.SapClassBasic
</ExcludeAssemblies>
</Costura>