Monday, March 07, 2011

How to deploy DLL’s into GAC using batch (.bat) file

How to deploy DLL’s into GAC using batch (.bat) file:

Global Assembly Cache Tool (Gacutil.exe):
The Global Assembly Cache tool allows you to view and manipulate the contents of the global assembly cache and download cache.




gacutil [options] [assemblyName assemblyPath assemblyListFile]

The Gacutil is a tool used by developers to install versioned assemblies into the system Global Assembly Cache (GAC) to become part of the assemblies that are available for all applications at runtime.

Parameter:

assemblyName:The name of an assembly. You can supply either a partially specified assembly name such as myAssembly or a fully specified assembly name such as myAssembly, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0038abc9deabfle5.

assemblyPath:The name of a file that contains an assembly manifest.

assemblyListFile:The path to an ANSI text file that lists assemblies to install or uninstall. To use a text file to install assemblies, specify the path to each assembly on a separate line in the file. The tool interprets relative paths, relative to the location of the assemblyListFile. To use a text file to uninstall assemblies, specify the fully qualified assembly name for each assembly on a separate line in the file. See the assemblyListFile contents examples later in this topic.


Option:

/cdl :Deletes the contents of the download cache.

/f :Specify this option with the /i or /il options to force an assembly to reinstall. If an assembly with the same name already exists in the global assembly cache, the tool overwrites it.

/h[elp] :Displays command syntax and options for the tool.

/i assemblyPath :Installs an assembly into the global assembly cache.

/if assemblyPath :Installs an assembly into the global assembly cache. If an assembly with the same name already exists in the global assembly cache, the tool overwrites it.
Specifying this option is equivalent to specifying the /i and /f options together.

/il assemblyListFile :Installs one or more assemblies specified in assemblyListFile into the global assembly cache.

/ir assemblyPath :Installs an assembly into the global assembly cache and adds a reference to count the assembly. You must specify the assemblyPath, scheme, id, and description parameters with this option. For a description of the valid values you can specify for these parameters, see the /r option. Specifying this option is equivalent to specifying the /i and /r options together.

/l [assemblyName] :Lists the contents of the global assembly cache. If you specify the assemblyName parameter, the tool lists only the assemblies matching that name.

/ldl :Lists the contents of the downloaded files cache.

/lr [assemblyName] :Lists all assemblies and their corresponding reference counts. If you specify the assemblyName parameter, the tool lists only the assemblies matching that name and their corresponding reference counts.

/nologo :Suppresses the Microsoft startup banner display.

/r [assemblyName assemblyPath] :Specifies a traced reference to an assembly or assemblies to install or uninstall. Specify this option with the /i, /il, /u, or /ul options.
To install an assembly, specify the assemblyPath, scheme, id, and description parameters with this option. To uninstall an assembly, specify the assemblyName, scheme, id, and description parameters.
To remove a reference to an assembly, you must specify the same scheme, id, and description parameters that were specified with the /i and /r (or /ir) options when the assembly was installed. If you are uninstalling an assembly, the tool also removes the assembly from the global assembly cache if it is the last reference to remove and if Windows Installer has no outstanding references to the assembly.

/silent :Suppresses the display of all output.

/u assemblyName :Uninstalls an assembly from the global assembly cache.

/uf assemblyName :Forces a specified assembly to uninstall by removing all references to the assembly. Specifying this option is equivalent to specifying the /u and /f options together.
Note :You cannot use this option to remove an assembly that was installed using Microsoft Windows Installer. If you attempt this operation, the tool displays an error message.

/ul assemblyListFile :Uninstalls one or more assemblies specified in assemblyListFile from the global assembly cache.

/u[ngen] assemblyName :Uninstalls a specified assembly from the global assembly cache. If the specified assembly has existing reference counts, the tool displays the reference counts and does not remove the assembly from the global assembly cache.
Note: In the .NET Framework version 2.0, /ungen is not supported. Instead, use the uninstall command of the Native Image Generator (Ngen.exe).
In the .NET Framework versions 1.0 and 1.1, specifying /ungen causes Gacutil.exe to remove the assembly from the native image cache. This cache stores the native images for assemblies that have been created using the Native Image Generator (Ngen.exe).

/ur assemblyName :Uninstalls a reference to a specified assembly from the global assembly cache. To remove a reference to an assembly, you must specify the same scheme, id, and description parameters that were specified with the /i and /r (or /ir) options when the assembly was installed. For a description of the valid values you can specify for these parameters, see the /r option. Specifying this option is equivalent to specifying the /u and /r options together.

/? :Displays command syntax and options for the tool.


Problem: How to deploy DLL’s into GAC using batch (.bat) file
Resolution:
There are 2 ways to deploy DLL’s into GAC using batch (.bat) file:
1. Using ul & il option of Gacutil.exe in batch file:
For example, we need to un-install some Microsoft.Practices.EnterpriseLibrary.Common,Version=3.1.0.0 dll from GAC and need to install some Microsoft.Practices.EnterpriseLibrary.Common,Version= 5.0.414.0 into GAC. For this I created a text files which contain the details of DLL’s which we need to un-install and install:

i. UnInstallAssemblyList.txt:


Microsoft.Practices.EnterpriseLibrary.Common,Version=3.1.0.0,Culture=Neutral,PublicKeyToken=b03f5f7f11d50a3a
Microsoft.Practices.EnterpriseLibrary.Data,Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling,Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging,Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging,Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Microsoft.Practices.EnterpriseLibrary.Security.Cryptography,Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a



ii. InstallAssemblyList.txt:


Microsoft.Practices.EnterpriseLibrary.Common,Version=5.0.414.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Microsoft.Practices.EnterpriseLibrary.Data,Version=5.0.414.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling,Version=5.0.414.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging,Version=5.0.414.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Microsoft.Practices.EnterpriseLibrary.Logging,Version=5.0.414.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Microsoft.Practices.EnterpriseLibrary.Security.Cryptography,Version=5.0.414.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a



iii. InstallMicrosoftEnterpriseLibrary.bat:



@echo off
setlocal
Echo Un-Installing dll from GAC
%GACUTIL% /ul UnInstallAssemblyList.txt
Echo Installing dll in GAC
%GACUTIL% /il InstallAssemblyList.txt



For running InstallMicrosoftEnterpriseLibrary.bat:
Set the environment variables for
1. GACUTIL
Navigate to folder where InstallMicrosoftEnterpriseLibrary.bat stored and execute the following scripts:

1. InstallMicrosoftEnterpriseLibrary.bat

2. Using uf & i option of Gacutil.exe in batch file:

For example, we need to un-install some Microsoft.Practices.EnterpriseLibrary.Common,Version=3.1.0.0 dll from GAC and need to install some Microsoft.Practices.EnterpriseLibrary.Common,Version= 5.0.414.0 into GAC. For this I created a batch file called InstallMicrosoftEnterpriseLibrary.bat:



@echo off
setlocal
Echo Un-Installing dll from GAC
%GACUTIL% /uf "Microsoft.Practices.EnterpriseLibrary.Common,Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
%GACUTIL% /uf "Microsoft.Practices.EnterpriseLibrary.Data,Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
%GACUTIL% /uf "Microsoft.Practices.EnterpriseLibrary.ExceptionHandling,Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
%GACUTIL% /uf "Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging,Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
%GACUTIL% /uf "Microsoft.Practices.EnterpriseLibrary.Logging,Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
%GACUTIL% /uf "Microsoft.Practices.EnterpriseLibrary.Security.Cryptography,Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

Echo Installing dll in GAC
%GACUTIL% /i "Microsoft.Practices.EnterpriseLibrary.Common.dll"
%GACUTIL% /i "Microsoft.Practices.EnterpriseLibrary.Data.dll"
%GACUTIL% /i "Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll"
%GACUTIL% /i "Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll"
%GACUTIL% /i "Microsoft.Practices.EnterpriseLibrary.Logging.dll"
%GACUTIL% /i "Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll"

For running InstallMicrosoftEnterpriseLibrary.bat:
Set the environment variables for
1. GACUTIL
Navigate to folder where InstallMicrosoftEnterpriseLibrary.bat stored and execute the following scripts:
1. InstallMicrosoftEnterpriseLibrary.bat


Reference: MSDN
Share:

0 comments:

About Me

My photo
Based in Bangalore, INDIA, Amit is a MCC. He has an MCA from the U.P.T.U., INDIA and holds Microsoft certifications including SharePoint 2007/2010/2013. He is an contributor to MSDN and http://amitkumarmca04.blogspot.com/. Amit have experience in SharePoint,ASP.Net with C#, Classic ASP, VB,Macros,HTML,JavaScript,JSON,BootStrap and AngularJS.

Followers

Labels