How to operate with multiple assembly versions in private folders using config?

对着背影说爱祢 提交于 2019-12-07 07:46:15

问题


I have a scenario where I have multiple versions of the same assembly that I need to store in the application private folders, in a structure like this:

.\My.dll          // latest version, say 1.1.3.0
.\v1.1.1\My.dll   // version 1.1.1.0
.\v1.1.2\My.dll   // version 1.1.2.0

My problem is that the .Net runtime, when asked for one of the older versions, always finds the latest version and then fails due to build number mismatch before trying to probe for a better match.

The assemblies are strong named and I'm using this configuration in my app.config:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="My" 
                publicKeyToken="xxxxxxxx" culture="netural" />

                <bindingRedirect oldVersion="1.0.0.0-1.1.1.0" 
                    newVersion="1.1.1.0" />
                <bindingRedirect oldVersion="1.1.3.0-1.1.65535.65535" 
                    newVersion="1.1.3.0" />

                <codeBase version="1.1.1.0" href="v1.1.1\My.dll" />
                <codeBase version="1.1.2.0" href="v1.1.2\My.dll" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>

Hopefully there is something I have missed here. I know this can be solved in code by listening for the AppDomain.AssemblyResolve event but I would love to see a pure config solution.

Update: So I found the bug, which is as Kent assumed, a typo. culture="netural" should be culture="neutral". That said, without the typo, resolving works great when using codeBase elements that point to each version. The probing element does not seem to work in this scenario.


回答1:


Without seeing the entire solution, I can only assume you have a typo somewhere. I just tried this for myself and - with the help of fuslogvw, I was able to get it working.

I have three versions of the assembly and the consuming application references an older version than that in its output directory. The CLR finds the redirects and codeBase entry and loads the correct (older) version.

I can email you my solution if you provide an email address.

Kent




回答2:


Can you use a probepath? we use this to force uncontrolled (e.g. third party resolvers - such as MSTest) to look for assemblies where we need them to be.

<?xml version ="1.0"?>
<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <probing privatePath="v1.1.1;v1.1.2;"/>
        </assemblyBinding>
    </runtime>
</configuration>

See here for more info



来源:https://stackoverflow.com/questions/638310/how-to-operate-with-multiple-assembly-versions-in-private-folders-using-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!