Thursday, October 9, 2008

Global Assembly Cache Directory Structure and Backup

Whenever .NET framework install on PC. There is one specific directory created called Global Assembly Cache.It contains all assemblies that available to all application on machine.

To open global assembly cache go to run and type assembly or if your sysroot in C drive then go for c:\windows\assembly.


It is a special directory so it look like this. By default it store data in directory structure.Please look at following image.


To Copy global assembly cache you can use following code in C# 2.0.

static void Main(string[] args)
            string assemblyfolderpath = "d:\\windows\\assembly";
            string copypath = "c:\\newtest123";
            DirectoryInfo dir = new DirectoryInfo(assemblyfolderpath);

        static void ReadDir(DirectoryInfo dir,string copypath)
            if (dir != null)
              FileInfo[] infos =  dir.GetFiles();
              for (int i = 0; i < infos.Length; i++)
                  infos[i].CopyTo(copypath + "/" + infos[i].Name);
              DirectoryInfo[] dirs = dir.GetDirectories();
              for (int i = 0; i < dirs.Length; i++)
                  Directory.CreateDirectory(copypath + "/" + dirs[i].Name);
                  ReadDir(dirs[i],copypath +"/"+ dirs[i].Name);

This is the way by which you can create copy of Assembly.

No comments: