Skip to content
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

WPF projects don't compile #1337

Closed
virzak opened this issue Sep 21, 2021 · 10 comments
Closed

WPF projects don't compile #1337

virzak opened this issue Sep 21, 2021 · 10 comments
Labels
Bug This issue describes behavior that is not working as expected Triaged This issue has been reviewed

Comments

@virzak
Copy link

virzak commented Sep 21, 2021

Steps to reproduce:

mkdir WpfFormat
cd WpfFormat
dotnet new wpf
dotnet format --verify-no-changes

The resulting error is:

MainWindow.xaml.cs(25,13): error CS0103: The name 'InitializeComponent' does not exist in the current context [WpfFormat.csproj]

@DavidZidar
Copy link

This should really be fixed before .NET 6 RTM.

@DavidZidar
Copy link

I reported this to the dotnet/sdk repo as dotnet format now is included in the SDK.

@JoeRobich
Copy link
Member

@jasonmalinowski Is it possible to invoke additional targets when loading projects/solutions using the MSBuild workspace? It seems that maybe WPF need something additional to work properly.

@JoeRobich JoeRobich added Bug This issue describes behavior that is not working as expected Triaged This issue has been reviewed labels Oct 18, 2021
@jasonmalinowski
Copy link
Member

@JoeRobich Are source generators not being ran? They'll run as long as the analyzer gets pulled in via MSBuild, but possibly something isn't working right there?

@DavidZidar
Copy link

@jasonmalinowski WPF does not use source generators, it's older tech. WPF generates source files that are written to disk under obj, it's using multiple compiler passes.

@jmarolf
Copy link
Contributor

jmarolf commented Oct 18, 2021

We will need to talk to the WPF team about what the exact build targets are that they use in their "double build". If I remember correctly, they generate additional project files that will need to be picked up by the MSBuild workspace.

@JoeRobich
Copy link
Member

I worked out the missing property from looking at the binlog OmniSharp generated when opening a wpf template app. I think we should simplify the properties passed by Roslyn to always set BuildingInsideVisualStudio regardless of the TFM being built.

@JoeRobich
Copy link
Member

Opened dotnet/roslyn#57219 for getting a fix into Roslyn.

@DavidZidar
Copy link

I just upgraded to .NET 6 RTM and it seems that dotnet format does work with WPF now even though the fixes above hasn't been merged yet.

When formatting one project I did get the following incorrect error though:

MainView.xaml.cs(200,40): error CS1503: Argument 1: cannot convert from 'MyApp.Views.MainView' to 'System.Windows.DependencyObject'

This seemed to be caused by the fact that the partial class in my MainView.xaml.cs-file did not have an explicit base class set, I was able to work around the issue by adding the same base class as specified in the generated part of the partial class.

@virzak
Copy link
Author

virzak commented Apr 28, 2023

This works now:

mkdir WpfFormat
cd WpfFormat
dotnet new wpf
dotnet new tool-manifest
dotnet tool install dotnet-format --version 8.0.422703 --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json
dotnet tool run dotnet-format --verify-no-changes

The error you might get in AssemblyInfo is easily corrected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This issue describes behavior that is not working as expected Triaged This issue has been reviewed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants