Red Gate forums :: View topic - Installing assemblies in GAC
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation

Deployment Manager PowerShell Scripts forum

Installing assemblies in GAC

Search in Deployment Manager PowerShell Scripts forum
Post new topic   Reply to topic
Jump to:  
Author Message
chirayu



Joined: 17 Sep 2012
Posts: 58

PostPosted: Thu Aug 29, 2013 8:20 pm    Post subject: Installing assemblies in GAC Reply with quote

This script installs assemblies in Global Assembly Cache (GAC).This script uses gacutil.exe, so it needs to be present on the target machine of deployment. Microsoft does not recommend using gacutil.exe to install on production machines, so this script should NOT be used on production target machines. Read this to learn more about GAC and different ways of installing assemblies.

Brief notes on how to use this script:
  • Add 'assemblyPath' variable in Deployment Manager UI and set it to the assembly you want to install in GAC. For example, 'c:\bar\foo.dll' if you would like to install foo.dll
  • By default, it looks for gacutil.exe in Program Files (%programFiles%) directory, however, you can set 'gacutilPath' variable to configure the search directory. If several gacutil.exe are found, it chooses the first one in the list. Which version of gacutil should I use?

Advanced usage:
Modify the script to use /r switch of gacutil.exe to specify trace references of the assembly. The reason for doing this is here.

Code:

# Inputs (REQUIRED)
# $assemblyPath- Full path of the dll to install in GAC. For example, c:\some\path\foo.dll

# Inputs (OPTIONAL)
# $gacutilSearchPath- The path to gacutil.exe, for instance, 'c:\foo\', if gacutil.exe is located at 'c:\foo\gacutil.exe'.

# throw error if $assemblyPath not set
if ($assemblyPath -eq $null) {
   throw "'assemblyPath' variable must be set on Deployment Manager variables page for this project. It is used to specify the full path of the dll to install in GAC."
}

if ($gacutilSearchPath -eq $null) {
   Write-Host "Optional variable, 'gacutilSearchPath', not set on Deployment Manager variables page for this project. It should be used to specify the path to gacutil.exe."
   
   $gacutilSearchPath = $env:programfiles
   Write-Host "Searching '$gacutilSearchPath' for gacutil.exe..."
   # try to find gacutil.exe
   $gacutilPaths = Get-ChildItem -Filter gacutil.exe -Path $gacutilSearchPath -Recurse  -ErrorAction 'silentlycontinue'
   
   # throw error if gacutil not found
   if ($gacutilPaths -eq $null) {
      throw "gacutil.exe not found in '$gacutilSearchPath'"
   }
   
   Write-Host "Found gacutil.exe in the following locations:"
   $gacutilPaths | foreach { $_.DirectoryName.ToString() | Write-Host }
}

$gacutilExe = ($gacutilPaths | Select -first 1 ).DirectoryName + "\gacutil.exe"
Write-Host "Using '$gacutilExe' to install assembly, '$assemblyPath' in GAC"

# install assembly using gacutil
& $gacutilExe -i $assemblyPath | Write-Host


_________________
Chirayu Shishodiya
Software Engineer - Deployment Manager
Red Gate
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group