C# 输出类型为类库的项目无法直接启动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14506185/
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
A project with an Output Type of Class Library cannot be started directly
提问by user3357963
Please can someone could explain why I get this error and what to do to fix it (or what I'm doing wrong!). The steps I have taken are
请有人可以解释为什么我会收到此错误以及如何修复它(或我做错了什么!)。我采取的步骤是
- Download Source code from http://www.codeproject.com/Articles/16859/AForge-NET-open-source-framework
Opening in VS2010 shows the references cannot be found
Re-Add all 3 references from
PlayingCardRecognition\bin\Release
so no further warningsWhen I try and build or Run I get the following message
- 从http://www.codeproject.com/Articles/16859/AForge-NET-open-source-framework下载源代码
在 VS2010 中打开显示找不到引用
重新添加所有 3 个引用,
PlayingCardRecognition\bin\Release
因此没有进一步的警告当我尝试构建或运行时,我收到以下消息
采纳答案by dutzu
The project type set as the Start-up project in that solution is of type ClassLibrary. DUe to that, the output is a dll not an executable and so, you cannot start it.
在该解决方案中设置为启动项目的项目类型为 ClassLibrary 类型。因此,输出是一个 dll 而不是可执行文件,因此您无法启动它。
If this is an error then you can do this:
如果这是一个错误,那么您可以这样做:
A quick and dirty fix for this, if that is the only csproj in the solution is to open the .csproj file in a text editor and change the value of the node <ProjectGuid>
to the Guid corresponding to a WinForms C# project. (That you may obtain from a google search or by creating a new project and opening the .csproj file generated by Visual Studio to find out what the GUID for that type is). (Enjoy - not many people know about this sneaky trick)
如果这是解决方案中唯一的 csproj,则对此问题的快速修复是在文本编辑器中打开 .csproj 文件并将节点的值更改为<ProjectGuid>
对应于 WinForms C# 项目的 Guid。(您可以从谷歌搜索或通过创建新项目并打开 Visual Studio 生成的 .csproj 文件以找出该类型的 GUID 来获得)。(享受 - 没有多少人知道这个鬼鬼祟祟的把戏)
BUT: the project might be a class library rightfully and then you should reference it in another project and use it that way.
但是:该项目可能是一个正确的类库,然后您应该在另一个项目中引用它并以这种方式使用它。
回答by keyboardP
The project you've downloaded is a class library, not an executable assembly. This means you need to import that library into your own project instead of trying to run it directly.
您下载的项目是一个类库,而不是一个可执行程序集。这意味着您需要将该库导入到您自己的项目中,而不是尝试直接运行它。
回答by LukeHennerley
Your project type is a class library one would suspect, add a ConsoleApplication
or WindowsApplication
and use that as your startup object. Reference this project and then access the code.
您的项目类型是一个人们会怀疑的类库,添加一个ConsoleApplication
orWindowsApplication
并将其用作您的启动对象。引用这个项目,然后访问代码。
回答by Rapha?l Althaus
The project you downloaded is a class library. Which can't be started.
您下载的项目是一个类库。哪个不能启动。
Add a new project which can be started (console app, win forms, what ever you want) and add a reference to the class library project to be able to "play with it".
添加一个可以启动的新项目(控制台应用程序、win 表单、任何你想要的)并添加对类库项目的引用,以便能够“玩它”。
And set this new project as "Startup project"
并将这个新项目设置为“启动项目”
回答by Corneliu
The project is a class library. It cannot be run or debugged without an executable project (F5 doesn't work!!!). You can only build the project (Ctrl+Shift+B).
该项目是一个类库。如果没有可执行项目,它就无法运行或调试(F5 不起作用!!!)。您只能构建项目 (Ctrl+Shift+B)。
If you want to debug the code add a console application project (set it as the start up project) to the solution and add the reference to the library.
如果要调试代码,请在解决方案中添加一个控制台应用程序项目(将其设置为启动项目)并添加对库的引用。
回答by P.Brian.Mackey
.Exe
's and .dll
's are both assemblies. The key difference is that executeables define an entry point Main
which can be invoked by the runtime. The error
.Exe
's 和.dll
's 都是程序集。关键区别在于可执行文件定义了一个Main
可以由运行时调用的入口点。错误
"Class library cannot be started directly"
“不能直接启动类库”
is due to the fact that said .dll
's do not have a Main
. To fix this issue, change the project type to a Windows application/Console application and define an entry point. Or, add a new project that is of type Windows application/Console application and reference said .dll
.
是因为说.dll
的没有Main
。要解决此问题,请将项目类型更改为 Windows 应用程序/控制台应用程序并定义入口点。或者,添加一个 Windows 应用程序/控制台应用程序类型的新项目并引用.dll
.
回答by SRoy
To fix this issue, do these steps:
要解决此问题,请执行以下步骤:
- Right click the Project name in Solution Explorer of Visual Studio
- Select
Set as StartUp Project
from the menu - Re-run your project It should work!
- 在 Visual Studio 的解决方案资源管理器中右键单击项目名称
- 选择
Set as StartUp Project
从菜单 - 重新运行你的项目它应该可以工作!
If it did not work, be sure that you have set your start page. If your project is C# Windows Application or C# Console Application, try this:
如果它不起作用,请确保您已设置起始页。如果您的项目是 C# Windows 应用程序或 C# 控制台应用程序,请尝试以下操作:
- Right click the Project name in Solution Explorer of Visual Studio
- Select
Properties
- Select the Application tab
- In the
Output Type
drop box - Select the correct application type of your project
- Re-run your project and let me know if it won't work.
- 在 Visual Studio 的解决方案资源管理器中右键单击项目名称
- 选择
Properties
- 选择应用程序选项卡
- 在
Output Type
投递箱 - 为您的项目选择正确的应用程序类型
- 重新运行您的项目,如果它不起作用,请告诉我。
回答by user3867250
Just right click on the Project Solution A window pops up. Expand the common Properties. Select Start Up Project
只需右键单击“项目解决方案”,就会弹出一个窗口。展开公共属性。选择启动项目
In there on right hand side Select radio button with Single Startup Project Select your Project in there and apply.
在右侧选择带有单个启动项目的单选按钮在那里选择您的项目并应用。
That's it. Now save and build your project. Run the project to see the output.
就是这样。现在保存并构建您的项目。运行项目以查看输出。
_Sarath@F1
_萨拉思@F1
回答by Mahesh K Naik
Goto the Solution properties -> on Build right side you see the startup project type. here you need to select the console appication/windows appication.
转到解决方案属性 -> 在构建右侧,您会看到启动项目类型。在这里您需要选择控制台应用程序/Windows 应用程序。
回答by Govindarajan v
If you convert the WPF application to Class library for get the projects .dll file.After that convert the same project to the WPF application you get the following error.
如果您将 WPF 应用程序转换为类库以获取项目 .dll 文件。然后将同一项目转换为 WPF 应用程序,您会收到以下错误。
Error:".exe does not contain a static main method suitable for an entry point".
错误:“.exe 不包含适合入口点的静态 main 方法”。
Steps to troubleshoot: 1.Include the App.xaml file in the respective project. 2.Right Click on App.xaml file change the build action to Application Definition 3.Now Build your project
故障排除步骤: 1. 在相应的项目中包含 App.xaml 文件。2.右键单击 App.xaml 文件,将构建操作更改为 Application Definition 3.Now Build your project