简体   繁体   English

vshost.exe一直在访问我的.dll,我在构建它时无法更新它

[英]vshost.exe keeps accessing my .dll and I can't update it when I build it

I have set an output folder for my .dll project though the Project Properties, which I call "Output". 我通过项目属性为我的.dll项目设置了一个输出文件夹,我称之为“输出”。

The problem is, from an empty Output folder, the first time I Build the project, it's fine. 问题是,从一个空的Output文件夹,我第一次构建项目,没关系。 The second time, I get the following error: 第二次,我收到以下错误:

Error 328 Unable to copy file "obj\\Release\\MyLibrary.dll" to "......\\Output\\Release\\MyLibrary.dll". 错误328无法将文件“obj \\ Release \\ MyLibrary.dll”复制到“...... \\ Output \\ Release \\ MyLibrary.dll”。 The process cannot access the file '......\\Output\\Release\\MyLibrary.dll' because it is being used by another process. 该进程无法访问文件'...... \\ Output \\ Release \\ MyLibrary.dll',因为它正由另一个进程使用。

The "another process" is the vshost.exe from Visual Studio. “另一个进程”是Visual Studio中的vshost.exe。 Since it keeps acessing MyLibrary.dll, it can't be deleted or replaced, thus why the error. 由于它不断访问MyLibrary.dll,因此无法删除或替换,从而导致错误。 This keeps the MyLibrary.dll on the Output folder not updated. 这样可以保持Output文件夹上的MyLibrary.dll不会更新。 However I have other .dll projects in my solution in which this does'nt happen. 但是我在我的解决方案中有其他.dll项目,但这不会发生。

The solution I have used so far to update it is to close the VS (thus closing vshost.exe), then run a .bat file which deletes the file Output\\Release\\MyLibrary.dll, then open the VS again and Rebuild it's project. 到目前为止我用来更新它的解决方案是关闭VS(从而关闭vshost.exe),然后运行.bat文件,删除文件Output \\ Release \\ MyLibrary.dll,然后再次打开VS并重建它的项目。

I know little of what exactly vshost.exe does, so I have no idea from where to start to clear this problem from the root. 我对vshost.exe的作用知之甚少,所以我不知道从哪里开始从根目录中清除这个问题。 I don't know why this happens to a specific .dll. 我不知道为什么这会发生在特定的.dll上。 I appreciate any idea that helps me investigate why this happens. 我感谢任何有助于我调查为什么会这样的想法。

vshost.exe is the Visual Studio Hosting process. vshost.exe是Visual Studio Hosting进程。 It is a custom CLR host that loads your EXE and makes debugging easier. 它是一个自定义CLR主机,可以加载EXE并使调试更容易。 You can turn it off, that has very few side-effects. 你可以把它关掉,这种副作用很少。 Project + Properties, Debugging tab, untick the "Enable the Visual Studio hosting process" option. “项目+属性”,“调试”选项卡,取消选中“启用Visual Studio主机进程”选项。

You are more likely to find the real problem in your program now. 您现在更有可能在程序中找到真正的问题。 With the most common issue that your program doesn't quit when you ask it to. 最常见的问题是,当您提出要求时,您的程序不会退出。 You will still get a build error, you'll now see your own EXE fingered as the one that keeps a lock on the DLL. 仍然会遇到构建错误,现在您将看到自己的EXE被指定为锁定DLL的那个。 You will also see it back in the Task Manager's Process tab. 您还将在任务管理器的“进程”选项卡中看到它。 Which also allows you to kill it. 这也允许你杀死它。

It isn't that clear to me how programmers recreate this problem. 我不清楚程序员如何重新创建这个问题。 Pressing Ctrl+F5 instead of F5 certainly will do this, always press F5 to immediately attach the debugger when you start the program. 按Ctrl + F5而不是F5肯定会这样做,在启动程序时总是按F5立即附加调试器。 Using Debugger + Stop Debugging will now reliable stop the program. 使用Debugger + Stop Debugging现在可以可靠地停止程序。 You can otherwise use Tools + Attach to Process to get a debugger attached again later to find out what your program is doing. 否则,您可以使用Tools + Attach to Process来稍后再次附加调试器,以了解您的程序正在执行的操作。

Anti-malware is a common scourge worth mentioning, they get way too excited when they see an executable file appear from nowhere. 反恶意软件值得一提的一个共同的祸患,当他们看到一个可执行文件从何处出现,他们得到激动了。 If you use Avast then just uninstall it completely, it is quite incompatible with VS. 如果你使用Avast然后完全卸载它,它与VS非常不兼容。

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

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