C# 输出类型为类库的项目无法直接启动(二)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12301832/
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-08-09 22:48:09  来源:igfitidea点击:

A project with an output type of class library cannot be started directly (2)

c#

提问by user1577052

A project with an output type of class library cannot be started directly. In order to debug this project, add an executable project to this solution which references the library project. Set the executable project as the startup project.

输出类型为类库的项目不能直接启动。为了调试这个项目,向这个解决方案添加一个引用库项目的可执行项目。将可执行项目设置为启动项目。

While running the program in C# visual studio 2010 I am getting this error. Please tell me how to sort out this error?

在 C# Visual Studio 2010 中运行程序时,我收到此错误。请告诉我如何解决这个错误?

回答by Bartosz

Go to your project properties page, change Output Type to Console Applicationor Windows Application(depending on what it is).

转到您的项目属性页面,将输出类型更改为Console ApplicationWindows Application(取决于它是什么)。

Make sure that you've got correct project set as startup one (right click -> set as startup project), and that this one is not of type Class Library. If your only project in solution is class library, then you need to create some test executable for it.

确保您已将正确的项目设置为启动项目(右键单击 -> 设置为启动项目),并且该项目不是 type Class Library。如果您在解决方案中唯一的项目是类库,那么您需要为其创建一些测试可执行文件。

回答by Justin Niessner

You created the project as a class library project, not an executable program. Class libraries are compiled and then used by other applications for common functionality.

您将项目创建为类库项目,而不是可执行程序。类库被编译,然后被其他应用程序用于公共功能。

If you meant to create a class library, you need to create a test application (or, better yet, Unit Tests) to test the functionality. If you meant to create an executable application, you'll need to modify the project.

如果您打算创建一个类库,您需要创建一个测试应用程序(或者,更好的是,单元测试)来测试功能。如果您打算创建一个可执行应用程序,则需要修改该项目。

If you have multiple projects in a single solution, you might also need to make sure you have the correct project set as the "Start Project" rather than one of the class library projects.

如果在一个解决方案中有多个项目,您可能还需要确保将正确的项目设置为“启动项目”而不是类库项目之一。

回答by CloudyMarble

Set your startproject in the project explorer by clicking right mouseclick on an executable project and choose "Set as start project"

通过单击鼠标右键单击可执行项目并选择“设置为启动项目” ,在项目资源管理器中设置您的启动项目

回答by akton

If you want to debug code in the DLL or run it using tests, go to the properties of the project, go to the Debug tab, select "Start external program" and enter the name of the application to use, such as a test runner.

如果要调试 DLL 中的代码或使用测试运行它,请转到项目的属性,转到“调试”选项卡,选择“启动外部程序”并输入要使用的应用程序的名称,例如测试运行程序.

回答by Parv Sharma

what you have done is that you have made a class librarywith all your code
every project in .Net needs a starting point like Main()function in c# which obsly isnt present in a class libraty type of project
what you can do instead is
1. Make a console projectinside the same solution. by right clicking the solution and add new project
2. Add a reference to the class library
3. Access the classes/methods of the class libraryand then starting the console projectinstead of class libraryproject

Alternatively,
If you have a console projectOR any other project in the solution already
right click the project in the solution explorer and Set as Startup project

你所做的是你已经用你的class library所有代码制作了一个
.Net 中的每个项目都需要一个起点,比如Main()c# 中的函数,它显然不存在于类库类型的项目中
,而你可以做的是
1. 制作一个控制台项目在同一个解决方案中。通过右键单击该解决方案,并添加新的项目
2.添加一个引用到类库
3.访问类/的方法类库,然后启动控制台项目,而不是类库项目

或者,
如果你有一个控制台项目或任何解决方案中的其他项目已经
右键单击解决方案资源管理器中的项目并设置为启动项目

回答by Rahman

Right click on Solution-->Go to properties-->Expand Common properties tab-->(On right side) Select Radio button with option Single startup project-->choose project from drop down list.
Enjoy.

右键单击解决方案--> 转到属性--> 扩展通用属性选项卡-->(在右侧)选择带有选项单启动项目的单选按钮--> 从下拉列表中选择项目。
享受。

回答by user7002447

The same error type i have found in my one of project suddenly which is running in VS 2012 with MVC 4 only. I have run multiple ways to resolve this error, but i have found filly with small change option in Property window of your respective error giving project. I have went project property window there i have change startup Project from Healpars to Myproject.Then it is working fine. Thank you

我突然在我的一个项目中发现了相同的错误类型,它仅在 VS 2012 中运行,仅使用 MVC 4。我已经运行了多种方法来解决这个错误,但我发现在您各自的错误项目的属性窗口中,有一些小的更改选项。我去了项目属性窗口,我将启动项目从 Healpars 更改为 Myproject。然后它工作正常。谢谢

回答by beanmf

I was surprised to learn that you can indeed set some Class Libraries as Startup and run them, IF they contain user controls. They run in the UserControl TestContainer which allows one to modify properties, etc. Basically debug at DesignTime, which can be really helpful. I have about 20 user controls in a single Project. This way I can run the TestContainer and choose which user control to run and debug.

我很惊讶地发现您确实可以将一些类库设置为启动并运行它们,如果它们包含用户控件。它们在 UserControl TestContainer 中运行,允许修改属性等。基本上在 DesignTime 进行调试,这真的很有帮助。我在一个项目中有大约 20 个用户控件。这样我就可以运行 TestContainer 并选择要运行和调试的用户控件。