问题
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.
回答1:
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?)
回答2:
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.
回答3:
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.
回答4:
Error itself states, that you need to give full location path of the dll residing. ie C:\myprojects\myassembly.dll in the path
回答5:
Simple steps to add a ".dll" file into the Global Assembly Cache in c#:
- In your project, "Add reference" to the .dll file you want to install in the GAC
- Form the References, right click on the particular .dll file and select "Properties"
- Change the property "Copy Local" to "True"
- Build and deploy using wspBuilder
- For verification, just check in the manifest file whether the path exists or not and also in "C:\Windows\assembly".
来源:https://stackoverflow.com/questions/12382831/install-an-assembly-into-gac-programmatically