-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NET 5 cannot produce console app with visible window if it references Windows Forms #14503
Comments
After many permutations, I found out that one can install the NET 5.0.100 SDK, but use the older NET Core 3.1.302 SDK by including a
I placed this file in ~/Documents/, and that seemed to work. |
I'm using the following workaround for debugging:
Hopefully this workaround will not be needed anymore in Visual Studio 16.9 |
@rbqm Thank you! That works. |
I have the same problem. <OutputType> is "Exe" and <UseWindowsForms> is "true". Generated exe file is "WinExe" instead (I assume) and doesn't show Console output. The error seems to only happen, if I use the new Core-Style project files. I just created a new framework project (with old-style project) it seems to work correctly. But I already updated most of our active projects to new Core-Style project files (even though I haven't updated target framework to core, because of external dependencies). |
That worked for me, but only from a console, not from Visual Studio. But it's still good, because without it the programm cannot be build as Console anymore. The workaround with launching via 'dotnet' and 'project.dll' didn't work, because TargetFramework is net471 and this only works for Core. |
OK, here is another workaround, but this probably only applies for Application targeting .net Framework. I set <UseWindowsForms> to "false". Instead I just added |
This looks to be intentional. See https://docs.microsoft.com/en-us/dotnet/core/compatibility/windows-forms/5.0/automatically-infer-winexe-output-type To revert to the old behavior, you can set this property in the .csproj file:
|
"Reason for change" : Break production 3.1 apps and waste peoples time - ticking time bomb for loads of people the next time they rebuild their 3.1 app on DevOps. (like I did today) |
If I explicitly set If for whatever reason this behavior has to stay, it could at least issue a warning saying something like this:
|
@kaby76 I was making a console app( .NET CORE 5 ) and tried referencing windows.forms In it and modified the cs.proj to this
` But only the form and no console is shown ? Did you find a way to show both console and form using dontnet 5 console app? |
@ChahatKumar You need to add the following to your csproj file: <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<DisableWinExeOutputInference>true</DisableWinExeOutputInference> <!-- Add this line -->
</PropertyGroup>
</Project> Otherwise This is precisely the point of my comment earlier. Without a warning of some kind for the csproj above, users like myself and @ChahatKumar will have no way of knowing that they will get something else than what they expect. |
@Manuzor Okay Thanks a lot ! |
You are trying to open a Form instance while the project is building? So in other words, trying to run your code before it is compiled? That obviously doesn't work. I don't think I understand what you're trying to achieve, but it sounds unrelated to this issue. |
I just wanted a way to show a pop-up or any tool to show the user a message and collect info during build time . |
Given that the upgrade-assistant tool provided by Microsoft seems to set all projects to <UseWindowsForms> by default, this is unbelievably obnoxious. I've just wasted an hour of my life trying to work out why a console application doesn't show the console, and can't call Console.WriteLine without crashing, before finally stumbling across this. Please, please stop torturing us. Please think for at least five seconds before breaking something like this. |
This has already been fixed so that .NET 6 SDK no longer changes OutputType to WinExe in Windows Forms projects. See #16563 and dotnet/docs#25636. Is this issue now a duplicate of #16563 or is this a request to make the same change to .NET 5 SDK as well? |
I mean, it ought to do the same for .NET 5 because it should never have behaved this stupidly in the first place... so sure, please go ahead and fix it in .NET 5. Bit late for me though, as I'm doing the update to .NET 5 today, because that's the current release (.NET 6 still in preview). (You'll have to pardon me if I'm a bit snarky. I've got 173 projects to upgrade to .NET instead of Framework, and it's the most painful experience I've had in 19 years as a software developer because of nonsense like this). |
Found this thread because of a closely-coupled issue. Can't compile my .NET 5 class library into
|
Old bug triage: Looks like folks determined the workaround of using |
Please see my response. |
I have the following code:
consoleapp.csproj
Program.cs
Under Net Core 3.1.302,
dotnet build
produces an .exe that when double-clicked in Windows Explorer, starts the app with a visible window.Under Net 5.0.100,
dotnet build
produces an .exe that when double-clicked in Windows Explorer, starts the application but there is no visible window.In the documentation, it notes "* Starting in .NET 5.0, Windows Forms and Windows Presentation Foundation (WPF) projects should specify the .NET SDK (Microsoft.NET.Sdk) instead of Microsoft.NET.Sdk.WindowsDesktop. For these projects, setting TargetFramework to net5.0-windows and UseWPF or UseWindowsForms to true will automatically import the Windows desktop SDK. If your project targets .NET 5.0 or later and specifies the Microsoft.NET.Sdk.WindowsDesktop SDK, you'll get build warning NETSDK1137." Following those instructions--and many permutations with/without
.WindowsDesktop
,TargetFramework
,UseWPF
,UseWindowsForms
--there is nothing that I can do to produce a console app that, when double-clicking on the .exe, has a visible window for NET 5.This is a problem because when the .csproj is opened in VS2019.8 and the program debugged via F5, there is no window. (It is actually worse in my application because a Read() from stdin return EOF=-1, just because there really is no visible/attacted window for a CLI prompt. I could start the program in a cmd.exe terminal, then attach the debugger to my program, but this is a royal pain, and I have to insert Sleep() calls at the start of the program if I want to debug start up code.) If I click on Properties for "consoleapp" in the Solution Explorer in VS2019.8, the "Output type" is "Windows Application", I change the "Output type" to "Console Application", then save. After closing and reopening, I re-display the the properties for the program--it's stuck at "Windows Application".
This is a console application that requires a window because it's a CLI program. On some commands, it will pop open a Windows Form. I can start the program in a console window, but I cannot debug the program startup because there is no visible window.
The actual use case is my program Trash, a Bash-like shell but for parsing, parse trees, grammar refactorings, compiler development, where I want a console application that can occasionally display decorated parse trees using Automatic Graph Layout. For the moment, the AGL display is in-process, but I may move to an out-of-process command set if I can pass huge trees between processes with fast IPC. But I am not hopeful because parse trees are frigging huge.
Is there a way of setting up the csproj file--or elsewhere--so that I get a visible window? Why does VS2019.8 think this is a Windows Application? Does the Output set to "Exe" mean anything? Why does VS2019.8 application settings for Console Application not stick?
(As I note in a follow-up comment, setting up a global.json file for 3.1.302 is a workaround. However, I'd like to move forward to NET 5.)
--Ken Domino
The text was updated successfully, but these errors were encountered: