简体   繁体   中英

C# how to register assembly in the GAC without GacUtil?

I need to register an assembly in the GAC using batch file. Is there a way to find the installation location of GacUtil.exe or is there a way to register the assembly without GacUtil?

你最好的选择是使用一个包装Publish.GacInstall的 powershell 脚本,比如这个🕗

GacUtil is not installed with a framework install only with an SDK install - so you couldn't guarantee it would be on the box you're installing on.

This won't work within your batch file but if you have developed the application yourself you can use the GacInstall method described below:
http://msdn.microsoft.com/en-us/library/system.enterpriseservices.internal.publish.gacinstall.aspx

Alternatively I'd recommend producing an msi file to deploy the application. Tutorial here:
http://www.dreamincode.net/forums/topic/58021-deploying-ac%23-application-visual-studio-setup-project/

It would be an inadvisable solution to include a copy of GacUtil.exe in your distribution because it comes under a different licence and you probably aren't licenced to redistribute it

You may install a dll into the GAC (global assembly cache) by doing the following

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

This has to do very little with native PowerShell but rather with instantiating and using .NET libraries from PowerShell

Do a iisreset .

Source

I used InnoSetup and created an installation including my assembly.

The important line is like below:

Source: "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"; DestDir: "{app}"; StrongAssemblyName: "WinSCPnet, Version=1.3.7.7333, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf, ProcessorArchitecture=MSIL"; Flags: ignoreversion gacinstall uninsnosharedfileprompt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM