-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
When UseWPF set True in a WinForms. Proj fails to recognize ApplicationConfiguration bootstrap code #6522
Comments
@RussKie, can you take a look at this? |
@Njoro007 please provide a simple repro that manifest the issue. |
To Reproduce
|
Added a WPF Window/Page?...I have done a recording rec-screen.mp4 |
Thank you for the video. I can repro it now. |
I've looked through the binlog, and there's a second compilation pass for a temp WPF project: I guess the Windows Forms source generator isn't run for the temp project, and the temp project can't resolve The Windows Forms SG generates the body of @sharwell @chsienki @jmarolf I think I need you help here.
Thanks |
Hmm, we've seen this problem in a few different iterations. dotnet/roslyn#60257 Basically all of these occur because the 'inner build' isn't including the required source generators. I think it was generally fixed for WPF, but my best guess is that the winforms generator is somehow being conditionally included on the |
@RussKie Yeah, the |
Our source generator is only included for Windows Forms apps: My thinking is though along the lines of that the source generated content should be present on disk, so it can be included in the compilation process. In a way similar to other generated (though not source generated) files, e.g., |
This comment was marked as resolved.
This comment was marked as resolved.
Here's a binlog from a basic Windows Forms app with a WPF window. Upon further digging in I've started thinking that perhaps the issue is caused by wpf/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft.WinFX.targets Lines 439 to 455 in bedefb0
Curiously, the task contains this line:
...however, it is a property and generates a property in the temp project, and it has nothing to do with the list of resolved analyzers, which is contained in @Analyzer item group.
|
I can reproduce the bug on my machine using the Regex source generator so this is unrelated to WinForms. @RussKie The code snippet for I'll try to work on a fix (If you're not already working on one). |
@ThomasGoulet73 do you think your fix would address any of these? |
@RussKie Here's the result of my tests: dotnet/roslyn#60257 #4421 dotnet/roslyn#46300 |
I found the problem, I opened #6535. |
Champion! Thank you |
@singhashish-wpf can we expedite this? This needs to be serviced into .NET 6. |
.NET version
6.0.3
Did it work in .NET Framework?
Yes
Did it work in any of the earlier releases of .NET Core or .NET 5+?
Worked without any issues in NET 5 and Net Framework
Issue description
In a WinForms desktop application targeting .NET 6, the [UseWindowsForms] element in the .proj file is set to True, and a bootstrap ApplicationConfiguration.Initialize(); is generated and called from the startup file Program.
Now I want to enable WPF by setting [EnableWPF] to True. When I do that and build I get the following error in the output log
Program.cs(13,13,13,37): error CS0103: The name 'ApplicationConfiguration' does not exist in the current context 1>Done building project "WinFormsApp1_s2dcxfug_wpftmp.csproj" -- FAILED.
My workaround for a net6 WinForm Project with WPF Enabled is editing the Program.CS to code below
//ApplicationConfiguration.Initialize(); Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1());
Steps to reproduce
To Reproduce
The text was updated successfully, but these errors were encountered: