c#-我必须执行哪些步骤才能将 winform 应用程序转换为控制台
我有一个非常简单的 winforms 应用程序。
我根本不使用表单对象。我想知道我需要删除或更改什么才能将此应用程序转换为控制台。我主要只需要删除所有不需要的参考资料,
请让我知道我应该采取哪些步骤来做到这一点?
i have a very simple winforms application.
i do not use the forms object at all. i would like to know what i need to delete or change in order to convert this app to a console. i mainly just need to get rid of all the unneeded references and such
please let me know what steps i should take to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这实际上取决于您最初是如何编码的以及您使用的模式。如果您已经明确区分了后端和非后端,那么您只需创建一个新类作为程序的
Main
并更改项目的Application Type< /code> 和项目属性中的
启动对象
。如果所有后端代码都与 winform 交织在一起,那么您首先需要将它们分开,然后继续执行上述步骤。
It really depends on how did you code it at first and what pattern are you using. If you have made clear distinctions of what is the back-end and what's not, then you would only have to create a new class to act as the program's
Main
and change the project'sApplication Type
and theStartup Object
in the project's properties.If you have all the back-end code intertwined with the winforms then you first need to separate them and then proceed to with the above steps.
您可以更改项目设置以创建控制台应用程序而不是 Windows 应用程序(只需在解决方案窗口中的项目上按 Ctrl+Enter,然后进行更改)。
这会将应用程序编译为控制台应用程序,然后您将获得一个控制台。但是,您仍然会收到表格。如果您不想使用 Windows 窗体,则需要删除窗体,并用命令行参数或配置替换其功能。然后,您可以删除 Windows 窗体引用,它将被转换。
You can change the project settings to create a Console Application instead of a Windows Application (just hit Ctrl+Enter on the project in the Solution Window, and make that change).
That will compile the application as a Console Application, and you'll get a console. However, you'll still get your forms. If you want to not have Windows Forms, you'll need to remove the forms, and replace their functionality with command line arguments or configuration. You can then remove the Windows Forms references, and it'll be converted.
创建控制台应用程序并将简单代码移过去
Create console app and move the simple code over