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

Gar*_*eth 5 .net c#

有没有办法强制使用特定的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使用我们在构建目录中的那个?

更新:

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

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

看起来GAC中3.5.1程序集的配置正在覆盖它.从我的app.config强制问题的任何方式?

Gar*_*eth 5

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

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

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" />
                <publisherPolicy apply="no"/>
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)