Visual Studio中添加可执行文件同名的DLL [英] Visual Studio adding executable file with same name as dll

查看:326
本文介绍了Visual Studio中添加可执行文件同名的DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio 2008中,我添加WinScp.dll(项目根目录)作为参照,马上出现了一个黄色图标。在编译时:




  • 类型或命名空间名称'的WinSCP'找不到(是否缺少using指令或程序集引用?)

  • 解决文件有一个不好的形象,没有元数据,或因其他原因无法访问。无法加载文件或程序集E:...... \winscp.exe或它的一个依赖。该模块应包含一个程序集清单。



一个小时的挫折后,我想通了,如果我删除WinSCP.exe作为项目文件(也在项目的根),一切编译罚款。的古怪!!!!



现在的问题是,我需要两个WinSCP.dll和WinSCP.exe在我的输出目录。 ?我该怎么办



修改:据我了解,有变通办法,如重命名文件或改变路径。我改名的EXE在第一;现在我重命名的DLL(感谢@迈克尔),因为它不要求我还指定在我的代码重命名的exe文件。



但为什么会出现在第一个问题地点? WinSCP.dll和WinSCP.exe是两个不同的文件。这是在Visual Studio中的一个bug,或DLL的复杂性/ exe文件,我不明白?


解决方案

WinSCP.dll和WinSCP.exe是两个不同的文件




不要组装装载机,它不讲究一个文件扩展名。它只知道它需要找到一个装配有的WinSCP的显示名称的。当进行匹配搜索,它首先会尝试使用该名称,旁边一个DLL文件的EXE文件。有些事情,你可以用Fuslogvw.exe实用看到。显示名称是由微软家伙,曾在此博客文章描述融合组件上:




名称的部分通常是组装的文件名,包括扩展名。因此,对于装配foo.dll,名称部分是富。当然,因为我说:通常,有些时候,名称部分是不一样的排除扩展名的文件名。我将在一点讨论。




着重号。因此,它首先找到WinSCP.exe,这是一个KABOOM,它不是一个有效的.NET程序集。简单的解决方法是的改名的该DLL,改变组件的显示名称。


In Visual Studio 2008, I added WinScp.dll (in project root) as a reference and immediately there was a yellow icon. At compile-time:

  • The type or namespace name 'WinSCP' could not be found (are you missing a using directive or an assembly reference?)
  • Resolved file has a bad image, no metadata, or is otherwise inaccessible. Could not load file or assembly 'E:...\winscp.exe' or one of its dependencies. The module was expected to contain an assembly manifest.

After an hour's frustration, I figured out that if I removed WinSCP.exe as a project file (also in project root), everything compiled fine. Weird!!!!

The problem is that I need both WinSCP.dll and WinSCP.exe in my output directory. What do I do?

EDIT: I understand that there are workarounds, such as renaming the files or changing the paths. I renamed the exe at first; now I rename the dll (thanks @Michael) because it does not require me to also specify the renamed exe in my code.

But why is there a problem in the first place? WinSCP.dll and WinSCP.exe are two different files. Is this a bug in Visual Studio, or an intricacy of dll/exe that I don't understand?

解决方案

WinSCP.dll and WinSCP.exe are two different files

Not to the assembly loader, it doesn't pay attention to a filename extension. All it knows is that it needs to find an assembly with a display name of "winscp". When searching for a match, it first tries an EXE file with that name, next a DLL file. Something you can see with the Fuslogvw.exe utility. Display names are described in this blog post by the Microsoft guy that worked on the Fusion component:

The "name" part is usually the file name of the assembly, excluding the extension. So for assembly foo.dll, the "name" part is "foo". Of course, since I said "usually", there are times when the "name" part is not the same as the file name excluding extension. I will discuss this in a bit.

Emphasis added. So it finds WinSCP.exe first and that's a kaboom, it is not a valid .NET assembly. The simple workaround is rename the DLL, that changes the display name of the assembly.

这篇关于Visual Studio中添加可执行文件同名的DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆