问题
I have created one tool using console application named "DocumentHashcode" in which I am using third party DLL - DocumentFormat.OpenXml.dll
.
When I'm going to deploy it, I am using DocumentHashcode.exe
and DocumentFormat.OpenXml.dll
for running the application.
I want to rename DocumentFormat.OpenXml.dll
to CATBldHashCodeSupporterDll.dll
. Can anyone advise how to achieve this?
回答1:
You need to manually load the assembly. The simplest way is to load it before the JITer tries to load the DocumentFormat.OpenXml namespace. You can manually load it like this:
var dllPath = Path.Combine(Directory.GetCurrentDirectory(), "reNamed.dll");
Assembly.LoadFile(dllPath);
Alternatively you could listen to the AppDomain.AssemblyResolve event, which gives you the chance to load the renamed DLL once the JITer has failed to find it.
回答2:
You can also try to re-assemble the DLL file with a new name. For details, please check last answer in Stackoverflow: Renaming ICsharcode-dll.
回答3:
If you don't mind getting a bit dirty, you can use a text editor to alter your .csproj file. If your .dll, for example, is xr-CommInterop.dll you should find some XML like:
<Reference Include="xr-CommInterop, Version=3.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Mypath\xr-CommInterop.dll</HintPath>
</Reference>
If you alter the first xr-CommInterop (in Reference Include="...) to just CommInterop and reload the project, you will find the reference now has a different name.
来源:https://stackoverflow.com/questions/14229982/renaming-a-third-party-dll-in-net