简体   繁体   中英

renaming a third party dll in .net

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?

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.

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM