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

有帮助吗?

解决方案

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.

其他提示

You can add referenced libraries to the output folder of start up project only:

1) Right click on starting project, "Add", "Existing Item". Or [Shift]+[Alt]+[A] combination in VS2010 with defaults.

2) Change type selector to "All files (*)", find and select your library.

3) Change "Add" selector to "Add As Link" and press it.

4) Select a link just added to a project, and in Properties window set "Copy to Output Directory" to "Copy always". Now, each time you building the solution, this library will be copied to the output folder of your startup project.

5) If you want to restrict copying this dll to the output of project that uses it, right-click on reference in that project, and in Properties window set "Copy Local" to false.

Implications:

The only place where your referenced dll's will appear will be your start-up project's output directory.

Disadvantages:

If you'll change your start-up project, you'll need to add all the links to it again.

Start-up project directory in Solution Explorer becomes messy.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top