4

Okay, I asked this question the other day, and it was closed due to my vagueness. I'll try to be more specific. In a project, say C# (using Visual Studio), I add a reference to a dll (right-click References->Add Reference), and the location of said dll is in C:\Blah\Foo. Now, if I move the exe that is built over to another machine, will the location of the dll need to be with the exe, or will it need to be in C:\Blah\Foo? Thank you.

Community
  • 1
  • 1
PiousVenom
  • 6,888
  • 11
  • 47
  • 86

5 Answers5

7

When you add a reference in the way you've described it is copied to the output folder (same as the exe file). Look in the properties of the reference (F4) and you will see an option called "Copy Local", if this is set to true then the DLL will be copied to the same output folder as the EXE file.

Copy Local Setting

So when you deploy your application to another machine you will need to copy the exe and all it's referenced DLLs to the deployment location. Windows will search for DLLs in a number of locations, the first of which is the same folder as the EXE file.

Antony Scott
  • 21,690
  • 12
  • 62
  • 94
2

Typically, you'll just put the assemblies in the same folder as the application, which causes it to be in the default probing path, and get found (for most applications), but there are many other options depending on the type of application. When you define your reference, there is the option to "Copy Local" - which causes the assembly to be copied to the application's output folder. If you leave this set to True, the assembly (DLL) will be with the .exe, and typically "just work."

The full process the runtime uses is covered on MSDN in How the Runtime Locates Assemblies. In particular, the topic titled Locating the Assembly through Codebases or Probing covers how the assemblies are located in detail, which depends on a lot of factors.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
1

The DLL should be with exe file. Have a look on this link to see where .NET serach for DLL In what order are locations searched to load referenced DLLs?

Community
  • 1
  • 1
Simon Edström
  • 6,461
  • 7
  • 32
  • 52
1

The dll could either be installed in the GAC or be present with the EXE in the same directory.

EDIT: The above mentioned are only just a couple of locations to resolve references.

swiftgp
  • 997
  • 1
  • 9
  • 17
  • 2
    Argh!! Not the GAC, please not the GAC! – Antony Scott Sep 17 '12 at 18:05
  • 1
    +1. This is correct and almost complete answer, irrespective if GAC is good or bad location or DLL. – Alexei Levenkov Sep 17 '12 at 18:07
  • @AlexeiLevenkov It's actually not complete, though - it doesn't account for ``, private probing paths, COM interop, etc. There's actually a lot of complexity depending on the type of application and the configuration used here. – Reed Copsey Sep 17 '12 at 18:11
  • @ReedCopsey, I know and tried to say it by "almost complete"... Should be +1 for ok answer, +2 for correct one, +3 for Reed/Jon's answer :) – Alexei Levenkov Sep 17 '12 at 18:22
0

When you add reference, you add path on your csproj on this assembly, dont you must just ensure that you can reference this dll.

When you deploy, it's another question, because your dll is copied on your Bin directory.

If you deploy you check your path of assembly in your csproj, and ensure that you deploy your assembly

Nota : check CopyLocal Property of your refrence

2 Other solution :

You can use GAC Global Assembly Cache in order to share your assemblies

Tools : Gacutil.exe in order to set assembly

Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51