question

BartoszWojtowicz-7700 avatar image
1 Vote"
BartoszWojtowicz-7700 asked LauXjpn-8288 answered

Project Output Type forced to Windows Application from Console Application - Visual Studio Upgrade 16.8.1

I have a similar problem to this one that started occurring after I installed VS 16.8.1 yesterday. My project is a WPF project for which I want to open a console as well. So, in the project properties Output Type was set to Console Application and all worked fine. Since the update that Output type is reset to Windows application with every build and when I run the project the console is not launched and app crashes because it can't access the Console properties (i.e. Console.BufferWidth)

This is my projects content. It doesn't specify anywhere it is a console app, maybe that is the problem. The Output type from the Project Properties window is not persisted.

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
<UseWPF>true</UseWPF>
<StartupObject>Viewer.Program</StartupObject>
</PropertyGroup>

I cannot remove <UseWPF>true</UseWPF> flag because then the project doesn't compile as I use WPF components.
Can you please advice how to get it working again?


vs-generalvs-debuggingvs-msbuild
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DylanZhu-MSFT avatar image
0 Votes"
DylanZhu-MSFT answered DylanZhu-MSFT commented

Hi BartoszWojtowicz-7700,

I'm afraid that you can't do that. The <UseWPF> means that your project is a wpf application instead of a console application, so you could not get and set the properties of console. Or we suggest you could recreate a console for your project.

Best Regards,
Dylan


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

It worked perfectly fine in the VS 16.7 version I had till Monday.

0 Votes 0 ·
rbqm-7459 avatar image
0 Votes"
rbqm-7459 answered rbqm-7459 edited

What I did to solve this problem is change the Sdk to "Microsoft.NET.Sdk", remove the UseWpf and UseWindowsForms elements, and manually add back the required WPF assembly references.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

What assemblies did you add? I added these which were all that disappeared when I switched to Microsoft.NET.Sdk but I still can't compile:

"PresentationCore"
"PresentationFramework"
"System.Windows.Controls.Ribbon"
"System.Xaml"
"UIAutomationClient"
"UIAutomationClientsideProviders"
"UIAutomationProvider"
"UIAutomationTypes"
"WindowsBase"

I get compilation error: CS1061 'App' does not contain a definition for 'InitializeComponent' and no accessible extension method 'InitializeComponent' accepting a first argument of type 'App' could be found (are you missing a using directive or an assembly reference?)


0 Votes 0 ·
rbqm-7459 avatar image rbqm-7459 BartoszWojtowicz-7700 ·

Your use case is a bit different from mine. My application really is a console application that happens to have some dependencies on WPF assemblies. But your application is a really a WPF application that also needs a console.

The reason why you get InitializeComponent errors is because by removing the UseWPF element, Visual Studio does not use the correct build action for the XAML files of your application anymore. You can fix it by changing the build action to "Page" for each XAML file, but this defeats the purpose of using the new SDK style project files if you have may XAML files.

Perhaps the solution suggested by DylanZhu-MSFT is more appropriate for you.

0 Votes 0 ·
LauXjpn-8288 avatar image
0 Votes"
LauXjpn-8288 answered

This breaking change has been documented as OutputType set to WinExe for WPF and WinForms apps:


However, if you want to revert to the old behavior, set the DisableWinExeOutputInference property to true in your project file.

<DisableWinExeOutputInference>true</DisableWinExeOutputInference>

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.