views:

99

answers:

1

In Visual Studio, you can require that an assembly reference match a specific version of the assembly. Is it possible (maybe by directly editing the csproj or vbproj file in a text editor) to reference a range of versions.

My specific example is I want to reference version 2.5.x of nUnit in my test projects at work. People run different versions of nUnit, and anything in version 2.5.x of nUnit should suffice for running our unit tests.

+2  A: 

In your compile settings, I don't believe so.

You can however, configure your app to redirect assembly load requests. Have a look at Assembly Binding Redirection. You can configure load requests for a specific versions (or range of versions) to be redirected to something different at runtime.

This example is slightly modified from MSDN:

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="myAssembly"
                              publicKeyToken="32ab4ba45e0a69a1"
                              culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-99.99.99.99"
                             newVersion="2.0.0.0"/>
         </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

Set the name, publicKeyToken and newVersion attributes correctly, and you should be good to go.

Nader Shirazie