Search code examples
dllgac

Share DLLs between projects


I have multiple projects in my solution. Each project references other projects. The dlls are quite big and I don't want them to be included in the bin of every project that references it.

What are my options? Ideally I'd like to place them in one location and reference that without needing to include them in my bin folder for each project. The only location I can think of is the GAC. Are there any ideas/suggestions on how you have gotten around this?

Is it possible to use probing paths? Anyone used this before/point me to a tutorial?

I've tried probing paths, get an error when running the application, is this not set up correctly? I've placed my dlls I wish to load from this path in the C:\Projects\myProject\bin folder. And set copy to false in the reference

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <probing privatePath="C:\Projects\myProject\bin"/>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
  </dependentAssembly>
</assemblyBinding>

Thanks


Solution

  • I guess what you prefer, is turning off CopyLocal when referencing assemblies in Visual Studio

    The steps could be:

    1. Open Solution Explorer
    2. Right click at the reference item (project or assembly)
    3. Select Properties in the context menu.
    4. Set CopyLocal to False (default is true)

    Then the references won't be copied to your project\bin\debug or etc.

    UPDATE

    You still need to copy your dependency to the same folder, or GAC, or probing paths to run your application.

    That is how .Net resolve the assemblies references.

    You may refer to How the Runtime Locates Assemblies.

    UPDATE 1

    MSDN Specifying an Assembly's Location

    Using the <probing> Element The runtime locates assemblies that do not have a code base by probing. For more information about probing, see How the Runtime Locates Assemblies. You can use the element in the application configuration file to specify subdirectories the runtime should search when locating an assembly. The following example shows how to specify directories the runtime should search.

    <configuration>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
           <probing privatePath="bin;bin2\subbin;bin3"/>
        </assemblyBinding>
      </runtime>
    </configuration>
    

    The privatePath attribute contains the directories that the runtime should search for assemblies. If the application is located at C:\Program Files\MyApp, the runtime will look for assemblies that do not specify a code base in C:\Program Files\MyApp\Bin, C:\Program Files\MyApp\Bin2\Subbin, and C:\Program Files\MyApp\Bin3. The directories specified in privatePath must be subdirectories of the application base directory.