New WinUI 3 projects fail to build with CS1061 errors after a fresh OS and VS install.

glen burke 0 Reputation points
2025-07-25T07:55:50.1866667+00:00

The error always appears in the generated file MainWindow.g.cs. This indicates that the XAML compiler is not correctly connecting the UI file to the code-behind file.

Troubleshooting Steps Already Taken:

I have already performed extensive troubleshooting, including:

Rebuilding the solution multiple times.

Cleaning the solution and manually deleting the bin, obj, and .vs folders.

Running dotnet restore from the Developer PowerShell.

Running the "Repair" feature from the Visual Studio Installer.

Performing a full factory reset of Windows and a fresh install.

After the factory reset, performing a fresh install of Visual Studio 2022 Community and also Visual Studio 2022 Preview.

During the installation, I selected the following workloads:

.NET desktop development

  Universal Windows Platform development
  
     Desktop development with C++
     
        WinUI application development
        

The error persists even after a complete OS and Visual Studio reinstall, on both the stable and preview versions of Visual Studio. This seems to be a fundamental issue with the build tools or the SDK installation on my machine.

Any help would be greatly appreciated. Thank you.

Developer technologies | Visual Studio | Setup
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.