How to manage version dependencies in a C#/.NET Pr

2019-04-23 13:51发布

问题:

Suppose you have Project A, and this has various dll dependencies, but the tree looks something like this:

Project A 
    => Project B
        => Project C
    => Project D
        => Project C
    => Project E
        => Project C, v2

Is there a way to use Project E since it relies on a newer version of Project C (dll) even though the rest of the project is using an older version of that same library?

If there is not a way, or one that would cause much gnashing of teeth, is there a forward thinking solution to preventing this from happening on future projects?

回答1:

From a longer term solution, not sure if this will work in your environment, but we have multiple dependent projects (from frameworks to dependent systems) that we reference. We use subversion and use externals to reference the libary/source folders so that all the dependent projects reference the same version.

We also have some projects where we bring in dependent libraries that might have used an older version when it was compiled than the newer and backwards compatible shared library that the main referencing application has included, in which case we use the multiple version solution that uses the config entry.

We actually have our build process stamp in something like (where _BUILD_VERSION_ is replaced by the build process with the current build number):

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Company.DependentAssembly" publicKeyToken="8510b56c219df72e"/>
            <bindingRedirect oldVersion="1.0.0.0-99.0.0.0" newVersion="_BUILD_VERSION_"/>
        </dependentAssembly>

The same article also has a way of referencing multiple version copies of the same assemblies in a project.