views:

38

answers:

2

Simple question: In Visual Studio, how can I see whether an assembly is referenced from the GAC or whether the reference is simply referenced through the ('normal') file system?

I thought I'd be able to deduct this by looking at the .csproj file but maybe not. Here's an outtake from my .csproj-file:

<Reference Include="MoreLinq, Version=1.0.11522.0, Culture=neutral, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\lib\MoreLinq.dll</HintPath>
</Reference>
<Reference Include="Oracle.DataAccess, Version=9.2.0.401, Culture=neutral, PublicKeyToken=89b483f429c47342">
  <SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />

I know that Oracle.DataAccess and System is referenced from the GAC and MoreLing (thanks Jon!) is referenced through the file system. The only difference I can see is that MoreLinq has a HintPath value. Is that what distinguishes a GAC reference from a file reference? In any case I can't see this in VS

Since this has a big impact on how assemblies are loaded, I would assume this information would be easy to get to, but I may be wrong?

+1  A: 

I think that you can't know this for sure without running the program. If the 'Copy local' property of the reference is set to False, it shows that the DLL comes from the GAC. But remember that the GAC has priority over the rest of the file system (including the current directory).

At run-time, you can be sure through the Debug / Windows / Modules window, where you can see the exact path of the loaded DLL.

Timores
You're right, files referenced through the GAC have Copy Local=false and files referenced through the file system have Copy Local=true. But this attribute is editable, so I can't be 100% certain.I don't seem to have a Modules windows in my VS2010, could it have been moved or called something else? Also, I would prefer to have clear information at compile time. But thanks for the tips!
martinnjensen
I think you must be in debug mode to have the Debug / Windows / Modules menu item visible.What @Benjol wrote is correct: the run-time will use what it finds, independently of the compile process (but with the correct version number of course)
Timores
+1  A: 

I'm not an expert, but as I understand it, the difference between the two references that you show in the question is only for build time. At runtime, the system will use whatever dlls it finds - starting in the GAC, then looking in the same folder as your executable. This means that you can't determine at design or compile time which it will be when the program is actually run.

(By the way, AFAIK Visual Studio doesn't compile anything using dlls from the GAC. This can sometimes cause confusion because what you see at design/build time (local dlls) doesn't correspond to what may be in the GAC at runtime).

Benjol