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

心已入冬 提交于 2019-11-26 16:13:04

问题


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?


回答1:


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-a-c%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




回答2:


Your bestbet is to use a powershell script that wraps Publish.GacInstall, such as this one🕗




回答3:


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




回答4:


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


来源:https://stackoverflow.com/questions/2950628/c-sharp-how-to-register-assembly-in-the-gac-without-gacutil

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!