2017-03-27 62 views
2

でます。gacutilなしPowerShellは、エラーメッセージの下の下PowerShellを使用して、DLLのGACを登録することができませんまたはWindows Server 2012

PS C:\Users\Administrator\Desktop> .\Register_dll.cmd 

C:\Users\Administrator\Desktop>[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=1.0.0.0, 
Culture=neutral, PublicKeyToken=7f48c3199e5dff41") 
The filename, directory name, or volume label syntax is incorrect. 

C:\Users\Administrator\Desktop>$publish = New-Object System.EnterpriseServices.Internal.Publish 
'$publish' is not recognized as an internal or external command, 
operable program or batch file. 

C:\Users\Administrator\Desktop>$publish.GacInstall("C:\Users\Administrator\Desktop\Mydll.dll") 
'$publish.GacInstall' is not recognized as an internal or external command, 
operable program or batch file. 

私は管理者としてPowerShellで走っているバッチファイルでを投げ続け、なぜあなたはすべての、私を助けることができるしてください私はバージョンとpublictokenを確認しました。私はここで問題ではないと思う。

[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7f48c3199e5dff41")    
$publish = New-Object System.EnterpriseServices.Internal.Publish 
$publish.GacInstall("C:\Users\Administrator\Desktop\MyDll.dll") 
+0

コマンドバッチスクリプトでpowershell構文を使用しようとしています。 Powershellスクリプトは '.ps1'拡張子を使います。 –

+0

助けていただきありがとうございます。私はPowershellを新しくしています – user1421582

答えて

1

スクリプトは.ps1として保存する必要があります。現在は.cmdという拡張子があります。これにより、PowerShellは古いコマンドシェルを呼び出して実行し、PowerShellコマンドを認識しません。

0

解決策は自分で見つけました。

まず、マークとしてPowerShellスクリプトであるため、ファイル拡張子を.PS1として実行する必要があります。

次に、以下のコマンドを実行してDLLを正常に登録します。

[Reflection.Assembly]::LoadWithPartialName("System.EnterpriseServices") | Out-Null 
[System.EnterpriseServices.Internal.Publish] $publish = new-object System.EnterpriseServices.Internal.Publish 
$publish.GacInstall("MYdllFile.dll") 
0

GACアセンブリをリモートでインストールできるようにしておきました。モジュール(.psm1)またはスクリプトとしてこのスクリプトを保存します(.ps1という)、それをインポートし、インストール-GACAssemblyを実行します。

Set-Variable GAC_VS2015_ASSEMBLY_REGKEY -option ReadOnly -value "HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319\AssemblyFoldersEx" 

[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") | Out-Null 

function Install-GACAssembly { 
    [CmdletBinding()] 
    param(
     [Parameter(Mandatory = $true)] 
     [ValidateNotNull()] 
     [ValidateScript({ Test-Path $_ -PathType Container })] 
     [string] $AssemblyDir, 

     [Parameter()] 
     [switch] $DevMode, 

     [Parameter()] 
     [string] $DevRegKeyName, 

     [Parameter()] 
     [switch] $uninstall 
    ) 
    $ErrorActionPreference = "Stop" 

    if($DevMode -and [string]::IsNullOrWhiteSpace($DevRegKeyName)) { 
     throw "If `$DevMode is true, a unique folder name must be specified in `$DevRegKeyName i.e. 'MyClient'" 
    } 
    if($DevMode) { 
     New-Item -Path $GAC_VS2015_ASSEMBLY_REGKEY -Name $DevRegKeyName -Value $AssemblyDir -Force | Out-Null 
    } 

    $installText = "$(if ($uninstall) { "un" })install" 
    Write-Verbose "Searching '$AssemblyDir' for GAC .dll files to $installText" 

    $publisher = New-Object System.EnterpriseServices.Internal.Publish    

    $assemblies = Get-ChildItem $AssemblyDir -Filter "*.dll" 
    Write-Verbose @" 
Found $($assemblies.Count) .dll files: 
$($assemblies.FullName) 
"@ 

    $assemblies | % { 
     if(!$uninstall) { 
      Write-Verbose " Installing $($_.FullName) into the GAC" 
      $output = $publisher.GacInstall($_.FullName) 
     } else { 
      Write-Verbose " Removing $($_.FullName) from the GAC" 
      $output = $publisher.GacRemove($_.FullName) 
     } 
    } 

    Write-Verbose "GAC $installText finished" 
    Write-Verbose "====================================" 
} 

あなたがモジュールを作成する場合(.psm1)あなたにそれをインポートする必要がありますPowerShellスクリプト/セッションImport-Moduleを使用して:

PS D:\> Import-Module -Name "D:\Path-to-module\ModuleFileName.psm1" -Force 
Install-GACAssembly -AssemblyDir "D:\Path-to-your-assembly\assembly-name.dll" 

また、アンインストールするためにそれを使用することができます:

PS D:\> Import-Module -Name "D:\Path-to-module\ModuleFileName.psm1" -Force 
Install-GACAssembly -AssemblyDir "D:\Path-to-your-assembly\assembly-name.dll" -uninstall 

あなたはどちらかのコマンドに-Verboseフラグを使用して冗長な出力を見ることができます。

+0

dllファイルパスを提供することで上記のスクリプトpowershellをどのように実行できますか? – user1421582

+0

私はすでにあなたにその例を与えました。 – Spikeh

関連する問題