简体   繁体   English

Visual Studio 2017 控制台未显示但正在运行

[英]Visual Studio 2017 Console not showing but running

I have a problem where a Console app window is not showing during debugging when there is also a .NET Core web app inside the same solution.我有一个问题,即当同一解决方案中还有一个 .NET Core Web 应用程序时,在调试过程中没有显示控制台应用程序窗口。 The console app code runs fine, just no black console window.控制台应用程序代码运行良好,只是没有黑色控制台窗口。

Visual Studio: Version 15.5.6 Microsoft .NET Framework: Version 4.7.02556 Visual Studio:版本 15.5.6 Microsoft .NET Framework:版本 4.7.02556

Console App: Target Framework: .NET Framework 4.6.1 Web App: Target Framework: .NET Core 2.0控制台应用程序:目标框架:.NET Framework 4.6.1 Web 应用程序:目标框架:.NET Core 2.0

If I create a separate .sln and add the .NET Framework console app to it, the window shows during debugging.如果我创建一个单独的 .sln 并将 .NET Framework 控制台应用程序添加到其中,则在调试期间会显示该窗口。 Both the Core 2 web and the .NET Framework console share a .NET Standard library. Core 2 Web 和 .NET Framework 控制台共享一个 .NET Standard 库。

I was suffering from the same problem on an inherited legacy application.我在继承的遗留应用程序上遇到了同样的问题。

The issue here was that although the application had the structure of a Console App, it was actually configured to run as a Windows App (with no code to show forms or anything).这里的问题是,虽然应用程序具有控制台应用程序的结构,但它实际上被配置为作为 Windows 应用程序运行(没有代码来显示表单或任何东西)。

在此处输入图片说明

To fix, I just changed Windows App to Console App in the project's Properties page.为了解决这个问题,我只是在项目的属性页面中将 Windows 应用程序更改为控制台应用程序。

在此处输入图片说明

This is a genuine issue.这是一个真正的问题。 I'm having the the exact same problem on all my development machines.我在所有开发机器上都遇到了完全相同的问题。

Visual Studio: Version 15.6.4 Microsoft .NET Framework: Version 4.7.02556 Visual Studio:版本 15.6.4 Microsoft .NET Framework:版本 4.7.02556

Console App: Target Framework: .NET Framework 4.6.1 Web App: Target Framework: .NET Core 2.0控制台应用程序:目标框架:.NET Framework 4.6.1 Web 应用程序:目标框架:.NET Core 2.0

I've tried to unload/reload projects, changed target framework back and forth and a few other things.我尝试卸载/重新加载项目,来回更改目标框架以及其他一些事情。 Nothing helps.没有任何帮助。 Running my project from within VS2017 works the first 5-10 times when starting VS2017 and loading up my project.在启动 VS2017 并加载我的项目时,从 VS2017 中运行我的项目前 5-10 次。 Then all of a sudden the console windows just stops showing when running/debugging from within VS2017.然后,在 VS2017 中运行/调试时,控制台窗口突然停止显示。 But the app is running in the background for sure.但该应用程序肯定在后台运行。

UPDATE:更新:

As earlier stated I did try to change the target framework of my problematic project back and forth.如前所述,我确实尝试来回更改有问题的项目的目标框架。 Instead of changing back and forth I tried to just change the target framework to 4.7.1 and keep it there.我没有来回更改,而是尝试将目标框架更改为 4.7.1 并将其保留在那里。 That resolved the issue.那解决了这个问题。

At the top of your Visual Studio IDE在 Visual Studio IDE 的顶部在此处输入图片说明

change the改变在此处输入图片说明

and in the drop down , select your Project name instead ie)并在下拉列表中,选择您的项目名称,即) 在此处输入图片说明

I can't comment for clarification(don't have the reputation yet) did you set your console project as the start up project or the web project?我无法评论澄清(还没有声誉)您是否将控制台项目设置为启动项目或网络项目? You can switch between the two if you're trying to debug something on the console or on your site.如果您尝试在控制台或站点上调试某些内容,则可以在两者之间切换。

You can also unload/load your web project to switch between them.您还可以卸载/加载您的 Web 项目以在它们之间切换。 Whatever is easiest for you.什么对你来说都是最简单的。

在此处输入图片说明

Right click on your project and click on 'Set as StartUp Project'.右键单击您的项目,然后单击“设置为启动项目”。

If this option isn't available unload your web project by right clicking on that project and selecting 'Unload Project'.如果此选项不可用,请通过右键单击该项目并选择“卸载项目”来卸载您的 Web 项目。 Try changing the startup project again.再次尝试更改启动项目。

I was facing the same issue, Changed my Framework from 4.7 to 4.5 and then again to 4.7 and it started working.我遇到了同样的问题,将我的框架从 4.7 更改为 4.5,然后再次更改为 4.7,它开始工作。 Bit of weird but it worked for me.有点奇怪,但它对我有用。

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

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