简体   繁体   English

在.net中重命名第三方dll

[英]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 . 我使用名为“DocumentHashcode”的控制台应用程序创建了一个工具,其中我使用的是第三方DLL - DocumentFormat.OpenXml.dll

When I'm going to deploy it, I am using DocumentHashcode.exe and DocumentFormat.OpenXml.dll for running the application. 当我要部署它时,我使用DocumentHashcode.exeDocumentFormat.OpenXml.dll来运行应用程序。

I want to rename DocumentFormat.OpenXml.dll to CATBldHashCodeSupporterDll.dll . 我想将DocumentFormat.OpenXml.dll重命名为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. 最简单的方法是在JITer尝试加载DocumentFormat.OpenXml命名空间之前加载它。 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. 或者,您可以侦听AppDomain.AssemblyResolve事件 ,这使您有机会在JITer找不到它时加载重命名的DLL。

You can also try to re-assemble the DLL file with a new name. 您还可以尝试使用新名称重新组装DLL文件。 For details, please check last answer in Stackoverflow: Renaming ICsharcode-dll . 有关详细信息,请查看Stackoverflow中的最后一个答案: 重命名ICsharcode-dll

If you don't mind getting a bit dirty, you can use a text editor to alter your .csproj file. 如果您不介意有点脏,可以使用文本编辑器来更改.csproj文件。 If your .dll, for example, is xr-CommInterop.dll you should find some XML like: 例如,如果您的.dll是xr-CommInterop.dll,您应该找到一些XML:

<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. 如果您将第一个xr-CommInterop(在Reference Include =“...中)更改为CommInterop并重新加载项目,您会发现该引用现在具有不同的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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