Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find location of standard .NET assemblies?

For a little C# compiler, I need to find the paths of the standard .NET assemblies like System.dll, System.Xml.dll and pretty much all the assmeblies listed under the ".NET" tab in the "Add Reference" window in Visual Studio (2010).
I would use the absolute paths but I have a feeling that this can break in exceptional cases.

like image 620
Vercas Avatar asked Jun 08 '11 15:06

Vercas


People also ask

Where are .NET assemblies located?

NET applications. Assemblies are loaded out of the application folder or a special private bin folder (like ASP.NET applications) and it all works as you would expect.

Where are assemblies stored C#?

Static assemblies are stored on a disk in portable executable (PE) files. Static assemblies can include interfaces, classes, and resources like bitmaps, JPEG files, and other resource files. You can also create dynamic assemblies, which are run directly from memory and aren't saved to disk before execution.

Where .NET shared assemblies are installed?

Component assemblies are typically stored in the C:\WINNT\Assembly folder. Only install an assembly in the global assembly cache when you need to share the assembly.

Where are .NET framework dlls stored?

The complete path is usually 'C:\Windows\Microsoft.NET\Framework. Each of the installed . NET versions will have its own folder.


3 Answers

These are all stored in the GAC at %WINDIR%\assembly, which you can view in Windows Explorer.

The actual dlls can be found in subfolders of the GAC, GAC_32, and GAC_MSIL folders, seemingly dependent on their version. On my machine I have three additional NativeImages folders that also appear to contain GAC'd dlls.

Windows Explorer won't allow you to browse these folders directly (as far as I can tell), but you can get there via the command prompt.

The full path for a dll in the GAC is

%WINDIR%\assembly\GACFOLDER\FILENAME\VERSION__PUBLICKEYTOKEN\FILENAME.dll

e.g. On my machine different versions of System.Xml.dll can be found in C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089 C:\WINDOWS\assembly\GAC\System.Xml\1.0.5000.0__b77a5c561934e089 C:\WINDOWS\assembly\NativeImages1_v1.1.4322\System.Xml\1.0.5000.0__b77a5c561934e089_2775eea1 C:\WINDOWS\assembly\NativeImages1_v1.1.4322\System.Xml\1.0.5000.0__b77a5c561934e089_4c5fbb92

like image 174
Richard Ev Avatar answered Oct 25 '22 02:10

Richard Ev


When compiling, you can use the reference assemblies under %ProgramFiles(x86)%\Reference Assemblies\Microsoft\Framework\.NETFramework

Also see the registry keys under (HKEY_LOCAL_MACHINE|HKEY_CURRENT_USER)\SOFTWARE\Microsoft\.NETFramework and (HKEY_LOCAL_MACHINE|HKEY_CURRENT_USER)\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders, as documented by KB306149.

The GAC is intended more for run-time use.

like image 36
Stephen Cleary Avatar answered Oct 25 '22 01:10

Stephen Cleary


Most are in the GAC, which is where I believe you are instructed to look with your own compiler. The document that helped with compilers, etc., was found under the .NET Framework in older versions, under the tools developer folder.

I would not be totally adverse to "hardcoding" the folder, per se, but you will be locked to a specific version. I am not suggesting this is the right way, but the location of .NET is not likely to change and most likely your compiler is stuck in a specific version. If you go this route ... To be safe on various machines, you should use %WINDIR% to determine where windows is installed (try cd %WINDIR% in a command prompt if you have never used this and want to see what the variable does). Academic exercise over.

One thing to note is some of what you are attempting may be served better by examining the "compiler as a service" direction MS is heading in vNext (?). This idea/feature is already present in Mono (open source .NET).

like image 36
Gregory A Beamer Avatar answered Oct 25 '22 03:10

Gregory A Beamer