Install the assembly in the GAC programmatically

I need to install the assembly in the GAC using C #. Below is my code:

new System.EnterpriseServices.Internal.Publish().GacInstall("MyAssembly.dll"); 

The above code gives an error:

Absolute path required

But I need this to be done without using a static file path (absolute path). Can someone tell me if this is possible? I added an assembly link inside the project links. I need to install this assembly in the GAC.

+6
source share
5 answers

You can do something like:

 GacInstall((new System.IO.FileInfo("MyAssembly.dll")).FullName); 

or,

 GacInstall(System.IO.Path.GetFullPath("MyAssembly.dll")); 

Suppose the file is in your current working directory. If this is not the case, you need to determine what rules are used to search for this DLL (for example, is it on the same path as your current executable?)

+11
source

try this below i came up let me know if this works

 Assembly assembly = Assembly.GetAssembly(typeof(Program));//Replace your Type here. string filePath = assembly.Location; 

Then use this file path.

+2
source

If you know the relative path of this DLL in relation to your executable, do

 string executableDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string assemblyFullPath = Path.Combine(executableDirectory, relativePathToAssembly); 

If it works for you.

+1
source

The error itself states that you need to specify the full path to the path to the dll located. those. C: \ myprojects \ myassembly.dll in the way

0
source

Simple steps to add a ".dll" file to the global assembly cache in C #:

  • In your project "Add Link" to the DLL file that you want to install in the GAC
  • Make links, right-click on a specific DLL file and select "Properties"
  • Change the Copy Local property to True
  • Creation and Deployment Using wspBuilder
  • To check, just check the manifest file whether the path exists or not, and also in the "C: \ Windows \ assembly" section.
-3
source

Source: https://habr.com/ru/post/925196/


All Articles