有没有办法强制使用DLL版本?

有没有办法强制使用特定的DLL版本? 从app.config?

(backstory)我们正在使用SQL Compact 3.5,并且由于商业原因(我知道)暂时不能转移到SQL Compact 3.5 SP1。 我们的构建目录中有System.Data.SqlServerCe和所有非托管dll,但如果安装了SP1,则应用程序会加载并使用SP1托管dll(并且通过扩展,我也假设非托管dll)。

pre-sp1 dll的版本号是3.5.0.0,sp1版本是3.5.1.0

我已将System.Data.SqlServerCe的引用设置为CopyLocal = true且Specific Version = true,但它仍然使用SP1版本,即使pre-sp1版本位于我们的构建目录中(假设它使用的是GAC)。 我尝试添加GAC的引用,以及手动进入文件系统并直接引用dll。

(只是为了说清楚,客户端正在为需要它的其他软件安装Service Pack,但即使安装了Service Pack,我们仍然需要运行pre-sp1版本)

有没有办法强制.net使用我们在构建目录中的那个?

更新:

我在app配置中添加了一个覆盖,就像这个问题一样 ,但是运行程序集绑定日志查看器给了我:

LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Projects\ConsoleApplication11\bin\Debug\ConsoleApplication11.exe.Config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config. LOG: Redirect found in application configuration file: 3.5.0.0 redirected to 3.5.0.0. LOG: Publisher policy file is found at C:\Windows\assembly\GAC_MSIL\policy.3.5.System.Data.SqlServerCe\3.5.0.0__89845dcd8080cc91\publisher.config. LOG: Publisher policy file redirect is found: 3.5.0.0 redirected to 3.5.1.0. LOG: ProcessorArchitecture is locked to MSIL. LOG: Post-policy reference: System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL LOG: Found assembly by looking in the GAC. LOG: Binding succeeds. Returns assembly from C:\Windows\assembly\GAC_MSIL\System.Data.SqlServerCe\3.5.1.0__89845dcd8080cc91\System.Data.SqlServerCe.dll. LOG: Assembly is loaded in default load context. 

看起来GAC中3.5.1程序集的配置正在覆盖它。 有什么办法从我的app.config强制解决问题?

我找到了解决方案。 看看Henk的答案( 这里 )中的链接以及融合日志的输出,似乎3.5 SP1安装程序安装了一个强制加载sp1 dll的发布者策略文件,即使在请求pre-sp1 dll时也是如此。

将它放在app.config中会告诉.net忽略发布者策略,并最终使用3.5.0.0版本:

            

听起来你在项目中引用了3.5.1.0版本。 我会尝试删除3.5.1.0的引用,如果它在项目的引用下列出,然后直接引用你想要使用的3.5.0.0 dll。 但是,如果服务器已经升级到SP1,则不建议将旧dll作为目标(尽管Service Pack仍然应该从API的角度保持向后兼容性)。