在没有gacutil的情况下将多个dll文件部署到gac中

时间:2014-07-25 07:28:03

标签: c# dll gac

所以,问题是我有几个C#dll需要在几台机器上部署到gac中。这些没有拥有 gacutil ,我宁愿保持这种方式。如何轻松部署这些文件,比如运行exe文件或批处理文件?为gac部署创建可执行文件是否可能/好主意?如何做到这一点?

聚苯乙烯。我只有ms visual studio express

2 个答案:

答案 0 :(得分:3)

PowerShell是你的朋友:

function Gac-Util
{
    param (
        [parameter(Mandatory = $true)][string] $assembly
    )

    try
    {
        $Error.Clear()

        [Reflection.Assembly]::LoadWithPartialName("System.EnterpriseServices") | Out-Null
        [System.EnterpriseServices.Internal.Publish] $publish = New-Object System.EnterpriseServices.Internal.Publish

        if (!(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" }

        $publish.GacInstall($assembly)

        Write-Host "`t`t$($MyInvocation.InvocationName): Assembly $assembly gacced"
    }

    catch
    {
        Write-Host "`t`t$($MyInvocation.InvocationName): $_"
    }
}

答案 1 :(得分:1)

您的解决方案位于程序集System.EnterpriseServices.Internal

在那里已经回答:C# how to register assembly in the GAC without GacUtil?