sharmila
sharmila

Reputation: 1533

Install an assembly into GAC programmatically

I need to install an assembly in GAC using c#. Below is my code:

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

The above code gives the error:

Absolute path required

But i need this to run without using static file path (absolute path). Can anyone tell me whether its possible? I have added the reference to the assembly inside the project references. I need to install this assembly inside GAC.

Upvotes: 6

Views: 11118

Answers (5)

Abhishek
Abhishek

Reputation: 1

Simple steps to add a ".dll" file into the Global Assembly Cache in c#:

  1. In your project, "Add reference" to the .dll file you want to install in the GAC
  2. Form the References, right click on the particular .dll file and select "Properties"
  3. Change the property "Copy Local" to "True"
  4. Build and deploy using wspBuilder
  5. For verification, just check in the manifest file whether the path exists or not and also in "C:\Windows\assembly".

Upvotes: -3

Tigran
Tigran

Reputation: 62265

If you know relative path of that DLL in regard of your executeble, make

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

Should work for you.

Upvotes: 1

Vignesh.N
Vignesh.N

Reputation: 2666

try this below piece I cameup with, 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.

Upvotes: 2

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239824

You could do something like:

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

or,

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

Assuming that the file is in your current working directory. If it's not, then you need to define what rules are being used to find this DLL (e.g. is it in the same path as your current executable?)

Upvotes: 12

VIRA
VIRA

Reputation: 1504

Error itself states, that you need to give full location path of the dll residing. ie C:\myprojects\myassembly.dll in the path

Upvotes: 0

Related Questions