The following PS script replaces gacutil /i on machines that don't have .NET SDK installed. No need to disable UAC either, just run Powershell as administrator:

BEGIN { 
$ErrorActionPreference = "Stop" 

if ( $null -eq ([AppDomain]::CurrentDomain.GetAssemblies() |? { $_.FullName -eq "System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" }) ) { 
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") | Out-Null 
} 
$publish = New-Object System.EnterpriseServices.Internal.Publish 
} 
PROCESS { 

$assembly = $null 

if ( $_ -is [string] ) { 
$assembly = $_ 
} elseif ( $_ -is [System.IO.FileInfo] ) { 
$assembly = $_.FullName 
} else { 
throw ("The object type '{0}' is not supported." -f $_.GetType().FullName) 
} 

if ( -not (Test-Path $assembly -type Leaf) ) { 
throw "The assembly '$assembly' does not exist." 
} 

if ( [System.Reflection.Assembly]::LoadFile( $assembly ).GetName().GetPublicKey().Length -eq 0 ) { 
throw "The assembly '$assembly' must be strongly signed." 
} 

Write-Output "Installing: $assembly" 

$publish.GacInstall( $assembly ) 
}
Sample
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") > null
$assembly = ([System.IO.FileInfo]"c:\deployment\myDLL.dll")
$publish = New-Object System.EnterpriseServices.Internal.Publish 
$publish.GacInstall($assembly)

Last edited Mar 15, 2012 at 4:47 PM by xsolon, version 11

Comments

epranav Feb 24, 2012 at 5:38 PM 
Any usage examples?