1+ # windowsgac::gacassembly - use to manage asseblies in the .NET Framework Global Assembly Cache
2+ #
3+ # @author Nick Adcock
4+ #
5+ # @param [present, absent] ensure
6+ #
7+ # @param [String] assemblypath
8+ #
9+ # @example Ensure $assembly installed into the GAC
10+ # class { $assembly: }
11+ #
12+ # @example Ensure $assembly not in the GAC
13+ # class { $assembly:
14+ # ensure => absent
15+ # }
16+
117define windowsgac::gacassembly (
218 $assemblypath = $name,
3- $ensure ,
19+ $ensure = present ,
420) {
521 $exists_script = sprintf('
622 $full_name = [System.Reflection.AssemblyName]::GetAssemblyName("%s").FullName
1026 $get_enterprise_services_script = '
1127 [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
1228 $publish = New-Object System.EnterpriseServices.Internal.Publish'
13-
29+
1430 if $ensure == present {
1531 $command = sprintf('
1632 %s; $publish.GacInstall("%s")
1733 ' , $get_enterprise_services_script , $assemblypath )
18-
19- exec { "GacInstall($assemblypath)" :
34+
35+ exec { "GacInstall(${ assemblypath} )" :
2036 provider => powershell,
21- command => $command ,
22- onlyif => " try { $exists_script ; exit 1 } catch { exit 0 }"
23- }
37+ command => $command ,
38+ onlyif => " try { ${ exists_script} ; exit 1 } catch { exit 0 }" ,
39+ }
2440 }
2541 else {
2642 $command = sprintf('
2743 %s; $publish.GacRemove("%s")
2844 ' , $get_enterprise_services_script , $assemblypath )
29-
30- exec { "GacRemove($assemblypath)" :
45+
46+ exec { "GacRemove(${ assemblypath} )" :
3147 provider => powershell,
32- command => $command ,
33- onlyif => $ exists_script
34- }
48+ command => $command ,
49+ onlyif => " try { ${ exists_script} ; exit 0 } catch { exit 1 } " ,
50+ }
3551 }
3652}
0 commit comments