visual-studio 输出类型为类库的项目无法直接启动——用启动exe

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/757010/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:22:48  来源:igfitidea点击:

A project with output type of class library cannot be started directly - with a startup exe

visual-studiovisual-studio-2010visual-studio-2005

提问by Rory

Firstly I'm completely aware of this message and why it happens normally. It's not that I'm just trying to run a dll (like this question).

首先,我完全了解这条消息以及它为什么会正常发生。这并不是说我只是想运行一个 dll(就像这个问题)。

I have a project that compiles to a dll but has a startup program specified in the project properties. Most of the time I'm able to right-click on the project and select Debug > Start new instance, and it will run the program and let me debug my dll. However, occasionally I get this message (A project with output type of class library cannot be started directly) as if I haven't got a startup program. The first few times I thought it was just me accidentally clicking on the wrong project but I'm certain this isn't the case given that it's happened so many times and I've been careful to watch it.

我有一个编译为 dll 的项目,但在项目属性中指定了一个启动程序。大多数情况下,我可以右键单击项目并选择调试 > 启动新实例,它将运行程序并让我调试我的 dll。但是,偶尔我会收到这个消息(一个输出类型为类库的项目不能直接启动),就好像我没有启动程序一样。最初的几次我以为只是我不小心点击了错误的项目,但我确信事实并非如此,因为它发生了很多次而且我一直很小心地观看它。

When this message appears I'm able to try it again and it always works on the second or third attempt.

当这条消息出现时,我可以再试一次,它总是在第二次或第三次尝试时有效。

A colleague using the same Solution never has this problem :-/

使用相同解决方案的同事从来没有遇到过这个问题:-/

Anyone else had this problem or know how to solve it?

其他人有这个问题或知道如何解决它?

I'm using Visual Studio 2005 Pro Version 8.0.50727.762 (SP.050727-7600) Edit: Also happens with Visual Studio 2010

我使用的是 Visual Studio 2005 专业版 8.0.50727.762 (SP.050727-7600)编辑:Visual Studio 2010也会 发生

采纳答案by Rory

Another colleague suggested it's because after clicking Debug > Start new instance, while I'm waiting for it to start up, I click on a different project. I don't do it for any reason, just randomly selecting things as I wait for the project to start up. Maybe Visual Studio looks at the selected project sometime after I clicked the menu, gets confused, and shows the error message?

另一位同事建议这是因为在单击调试 > 启动新实例后,在等待它启动时,我单击了另一个项目。我不会出于任何原因这样做,只是在等待项目启动时随机选择内容。也许在我单击菜单后的某个时候,Visual Studio 会查看所选项目,感到困惑并显示错误消息?

Anyone able to confirm this matches their experience?

任何人都能够确认这与他们的经验相符吗?

回答by Dirk Vollmar

Typically problems in VS are caused by:

VS 中的问题通常由以下原因引起:

  • Add-ins: Run VS without and see if the problems is solved
  • Corrupted files in your solution: Delete / rename all files created by Visual Studio which are not part of your project, i.e. all .suo, .ncb files and a like.
  • 加载项:运行 VS 并查看问题是否已解决
  • 解决方案中的损坏文件:删除/重命名由 Visual Studio 创建的所有不属于您的项目的文件,即所有 .suo、.ncb 文件等。

回答by Shea

I had this problem with projects that were created as "Windows Control Library" that somehow forget their status. Unloading and reloading the project usually did the trick.

我在创建为“Windows 控制库”的项目中遇到了这个问题,但不知何故忘记了它们的状态。卸载和重新加载项目通常可以解决问题。

If it was created as a "Class Library" then to make it a "Windows Control Library" I manually add the following to the .csproj file. It was the only difference I could see between a class library and windows control library project.

如果它是作为“类库”创建的,那么为了使其成为“Windows 控制库”,我手动将以下内容添加到 .csproj 文件中。这是我能看到的类库和 Windows 控件库项目之间的唯一区别。

BTW - starting a Windows Control Library starts the User Control Test Container - allows you to test any user control in the library. Very cool.

顺便说一句 - 启动 Windows 控件库会启动用户控件测试容器 - 允许您测试库中的任何用户控件。很酷。

<Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" />

add that inside of an <itemgroup>element.

将其添加到<itemgroup>元素内部。

回答by Roman Polen.

If you plan to use/create/add extra dll's or just have more than one project in your solution, you may get this kind of problem, especially if you forgot a simple rule: 1. In your "Solution Explorer" window. Right click and chose "Set StartUp Projects..." 2. Under "Start Up Project" select and change "Single startup project" to your working entity.

如果您打算使用/创建/添加额外的 dll 或在您的解决方案中有多个项目,您可能会遇到此类问题,特别是如果您忘记了一个简单的规则: 1. 在您的“解决方案资源管理器”窗口中。右键单击并选择“Set StartUp Projects...” 2. 在“Start Up Project”下选择并将“Single startup project”更改为您的工作实体。

回答by Alexis Coles

Going to resurrect this thread, I have just been experiencing similar issues, when right clicking a project and start new instance..

要复活这个线程,我刚刚遇到了类似的问题,当右键单击一个项目并启动新实例时..

So instead of right clicking the project and selecting start new instance, I right clicked and clicked set as startup project.

因此,我没有右键单击项目并选择启动新实例,而是右键单击并单击设置为启动项目。

Low and behold a class library project was set to bold, certainly not the one I was right clicking.

瞧,一个类库项目被设置为粗体,当然不是我右击的那个。

I tried selecting a different executable project and setting that as the startup project. Same class library was highlighted as the start up project.

我尝试选择一个不同的可执行项目并将其设置为启动项目。与启动项目相同的类库被突出显示。

Realised that the current open file was from that project, possibly all the open files were from that project...

意识到当前打开的文件来自该项目,可能所有打开的文件都来自该项目......

closed all open files and tried again.... Problem solved, behaviour as expected for both set as start up project and start new instance options...

关闭所有打开的文件并重试.... 问题解决了,设置为启动项目和启动新实例选项的行为符合预期...

Definitely a bug, hope this helps others..

绝对是一个错误,希望这可以帮助其他人..

  • Microsoft Visual Studio 2010 Version 10.0.40219.1 SP1Rel
  • Microsoft .NET Framework Version 4.0.30319 SP1Rel
  • Microsoft Visual Studio 2010 版本 10.0.40219.1 SP1Rel
  • Microsoft .NET Framework 版本 4.0.30319 SP1Rel

回答by Alexis Coles

no just make a start up project

不只是做一个启动项目

回答by Paul Sonier

This sounds like a transient Visual Studio problem. Reinstallation or upgrade may solve your problem.

这听起来像是一个暂时的 Visual Studio 问题。重新安装或升级可能会解决您的问题。

回答by Reuben

I've found that I've had the Startup Project on the Solution set to Current selection, then at some point, I've unloaded a project, and the solution has reverted to Single startup project on a project that happens to be a class library.

我发现我已经将解决​​方案上的启动项目设置为当前选择,然后在某个时候,我卸载了一个项目,并且该解决方案已恢复到恰好是一个类的项目上的单个启动项目图书馆。

回答by efess

I've seen this as well, and it seems like a bug in VS. It happens after you right-click/build a class library (that requires rebuilding), and then right-click/debug > start new instance.

我也看到了这个,它似乎是 VS 中的一个错误。它发生在您右键单击/构建类库(需要重建),然后右键单击/调试> 启动新实例之后。

edit- It's still very intermittent, I can't seem reproduce it reliably

编辑 - 它仍然非常断断续续,我似乎无法可靠地重现它