Reputation: 1533
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
Reputation: 1
Simple steps to add a ".dll" file into the Global Assembly Cache in c#:
Upvotes: -3
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
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
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
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