We have created the hello.exe assembly in our previous article and installed it into Global Assembly Cache (GAC). Let’s look at where in GAC this assembly is installed.
As we discussed in our previous article(s), GAC is the location where shared assemblies will be placed. Where this GAC is located? For the .Net version prior to 4.0, run time use, C:\Windows\assembly as the GAC. From version 4.0, it is C:\Windows\Microsoft.NET\assembly.
Let’s open GAC, and see what it contains. At the command prompt type the following command to go to GAC.
cd c:\Windows\Microsoft.NET\assembly
If .NET version 4.0 or higher is installed, type the above command. Otherwise, type the below command:
cd c:\Windows\assembly
Usually, these folders contain the following structure:
+ GAC + GAC_32 + GAC_64 + GAC_MSIL + NativeImages_vx.x.xxxxx_32 + NativeImages_vx.x.xxxxx_64
- The GAC folder is for backward compatibility with older versions of .Net (1.0 and 1.1).
- GAC_32 and GAC_64 folders are for assemblies for 32-bit and 64-bit platforms respectively.
- GAC_MSIL folder contains the assemblies which are developed with pure .Net code.
- NativeImages_vx.x.xxxxx_32 and NativeImages_vx.x.xxxxx_64 folders contain assemblies compiled to native code for 32-bit and 64-bit platforms. Where vx.x.xxxxx is the run-time version number.
Let’s check in to GAC where our hello.exe file exists. Type the following command at the command prompt.
gacutil /l hello
This command will list the assembly information. It returns:
c:\Visual Studio Projects 2012>gacutil /l hello Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.17929 Copyright (c) Microsoft Corporation. All rights reserved. The Global Assembly Cache contains the following assemblies: hello, Version=0.0.0.0, Culture=neutral, PublicKeyToken=f5d51cce1ddbf0b7, proc essorArchitecture=MSIL Number of items = 1
Observe the result that, GAC contains hello assembly of version=0.0.0.0. We have installed .Net 4.x in our system. So, our hello assembly would be in the “c:\Windows\Microsoft.NET\assembly” folder. Open this folder in the command prompt. As we developed our hello assembly using pure .Net code; so, our assembly must be in the GAC_MSIL folder. Open the GAC_MSIL folder and check for the hello folder. Once you find open the hello folder, you will find the below folder structure.
- hello - v4.0_0.0.0.0__f5d51cce1ddbf0b7 . hello.exe
hello.exe found in the “GAC_MSIL\hello\v4.0_0.0.0.0__f5d51cce1ddbf0b7” folder. This is the place gacutil installed our assembly into GAC.
Let’s closely look at folder name “v4.0_0.0.0.0__f5d51cce1ddbf0b7”.
- v4.0 is the .Net run-time version we used to create the assembly.
- 0.0.0.0 is our hello assembly’s version number. Because we are not set any version number for our assembly. So, it’s showing 0.0.0.0 as our assembly’s version.
- f5d51cce1ddbf0b7 is the public key token. Do you remember we generated a key pair and added it to our assembly? This is the public key token we generated using the Strong Name Tool (sn.exe).
But why does it generate folder structure under hello assembly? This is one of the advantages of an assembly. Assemblies support multiple versions and we can deploy multiple versions side-by-side. Each assembly will store in the respective version-based folder. Because of this, it eliminates versioning problems, we normally face with normal DLLs.
We will discuss assembly versioning in our next article.
2 thoughts on “.Net – Assemblies – gacutil”