microsoft / WindowsAppSDK

The Windows App SDK empowers all Windows desktop apps with modern Windows UI, APIs, and platform features, including back-compat support, shipped via NuGet.
https://docs.microsoft.com/windows/apps/windows-app-sdk/
MIT License
3.84k stars 320 forks source link

Version 1.6.240829007 of Microsoft.WindowsAppSDK breaks WinUI application builds. #4698

Closed DRAirey1 closed 1 month ago

DRAirey1 commented 1 month ago

Describe the bug

Have been building a complex WinUI application (3 yrs old) with no issues using Microsoft.WindowsAppSDK ver. 1.5.240802000. Got a notice that a newer version of the package was available, and upgraded. Now my application build spews out a ton of missing target and conflict errors and won't build.

Steps to reproduce the bug

  1. Create a WinUI application from the templates in VS 2022.
  2. Upgrade to the latest packages.
  3. Build - you get a raft of warning and error messages.

Expected behavior

I expect the builds to finish with no warnings or errors.

Screenshots

4>C:\Users\DonaldAirey\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\buildTransitive\Microsoft.WindowsAppSDK.targets(76,9): error : This version of the Windows App SDK requires Microsoft.Windows.SDK.NET.Ref 10.0.19041.38 or later.
4>C:\Users\DonaldAirey\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\buildTransitive\Microsoft.WindowsAppSDK.targets(76,9): error :     Please update to .NET SDK 6.0.134, 6.0.426, 8.0.109, 8.0.305 or 8.0.402 (or later).
4>C:\Users\DonaldAirey\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\buildTransitive\Microsoft.WindowsAppSDK.targets(76,9): error :     Or add a temporary Microsoft.Windows.SDK.NET.Ref reference which can be added with:
4>C:\Users\DonaldAirey\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\buildTransitive\Microsoft.WindowsAppSDK.targets(76,9): error :         <PropertyGroup>
4>C:\Users\DonaldAirey\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\buildTransitive\Microsoft.WindowsAppSDK.targets(76,9): error :             <WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>
4>C:\Users\DonaldAirey\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\buildTransitive\Microsoft.WindowsAppSDK.targets(76,9): error :         </PropertyGroup>
4>C:\Users\DonaldAirey\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\buildTransitive\Microsoft.WindowsAppSDK.targets(76,9): error :

NuGet package version

Windows App SDK 1.6.0: 1.6.240829007

Packaging type

Packaged (MSIX), Unpackaged

Windows version

Windows 11 version 21H2 (22000)

IDE

Visual Studio 2022

Additional context

No response

ghost1372 commented 1 month ago

Just read your error message, for now you should add this into your csproj file:

<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>
michalleptuch commented 1 month ago

Just read your error message, for now you should add this into your csproj file:

<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>

It doesn't work when you target Windows 11 26100

KaranocaVe commented 1 month ago

This is definitely a bug. Nothing was wrong when I created a new winui3 project a week ago. But just now, I created a new project and encountered this problem. I even haven't updated anything!

DRAirey1 commented 1 month ago

Adding the line from ghost1372 seems to have fixed the problem as long as you go back and modify every WinUI package that you use to have the same settings. I have a WinUI package for common WinUI controls that was screwing up the build until I made the change there as well.

KaranocaVe commented 1 month ago

I think there must be something wrong with the latest WinUI3 default template, I have used Template Studio to create a new project and nothing was wrong.

KaranocaVe commented 1 month ago

Perhaps only bill gates knows how to "update to .NET SDK 6.0.134, 6.0.426, 8.0.109, 8.0.305 or 8.0.402 (or later)." Amazing

luttje commented 1 month ago

Just chiming in that I would really appreciate it if my students could start their experience with WinUI3 in a less buggy way. I kind of expect Visual Studio templates to be able to build and run out-of-the-box.

The solution posted and mentioned in the error works, but is not ideal at all.

Thanks for your efforts.

antokhio commented 1 month ago

That seems to be caused by lower Target OS Version on Visual Studio WinUI Template: image

Basically i set target OS Version to 10.0.19041.0 and it went away

JeroMiya commented 1 month ago

I had this issue as well. These are the settings that worked for me with the template:

Package project: image

Application project: image

And add this to the application project's csproj: image

However, I don't know WHY this works, and I find that a little concerning. There needs to be a table somewhere that lists out all the possible valid combinations of TargetFramework, TargetPlatformMinVersion, WindowsSdkPackageVersion, Microsoft.Windows.SDK.BuildTools, and Microsoft.WindowsAppSDK versions or an algorithm for determining how to update the others after you've updated one. Currently I have to guess and check until the build succeeds.

00000vish commented 1 month ago

I tried all the suggested fixes but nothing worked.

Only thing that worked was to downgrade the WindowsAppSDK nuget.

<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240627000" />

Scottj1s commented 1 month ago

@DRAirey1 Thanks for reporting this issue. C#/WinRT is used to generate .NET projection assemblies for both Windows App SDK and the Windows SDK. On occasion, these must be updated together, but they are released independently. In such cases, WindowsSdkPackageVersion is necessary for a project to override the version of the Windows SDK projection implied by the TFM and the current .NET SDK. The message (which appears to be a raft of errors, but is only one) suggests the project edit needed. The OS version is derived from your TFM (i.e., 19041 is not hardcoded). E.g., a TargetFramework of net8.0-windows10.0.22000.0 will suggest adding a WindowsSdkPackageVersion of 10.0.22000.38. I realize this is a sharp edge - we'll look at defaulting the WindowsSdkPackageVersion as needed in a future release.

DRAirey1 commented 1 month ago

@Scottj1s Listen, for what it's worth, I'm old enough so that I've run into these issues a number of time. Things move forward, we all understand that. The big error, I think, that you made, was not updating the standard IDE template at the same time. If something goes FUBAR, the first thing I do is create a templated program to see how you guys are going it. That's my suggestion, for what it's worth, if you release a breaking change, make sure to update the IDE templates to show the right way to build the project. That'll save us all a lot of time.

mcyenikoylu commented 1 month ago

WindowsSdkPackageVersion works in a new WinUI project, but it doesn't work at all if you want to use WinUI in a WPF project. It must be a shame to release a production version like this.

Scottj1s commented 1 month ago

@DRAirey1 I hear you. Unfortunately, the templates have a completely separate ship vehicle and schedule (being distributed with Visual Studio). This means we have to be able to release changes to either, independent of the other. The decoupling is necessary (and actually beneficial), but could certainly be made more robust.

Scottj1s commented 1 month ago

@mcyenikoylu Thanks - can you open a new issue for tracking this, with repro details?

Scottj1s commented 1 month ago

@mcyenikoylu Thanks - can you open a new issue for tracking this, with repro details?

Yes: https://github.com/microsoft/WindowsAppSDK/issues/4734

c00012 commented 1 month ago

I got a same error. so, I tried ghost1372's suggestion. but I got a following error message:

error NETSDK1112: The runtime pack for Microsoft.Windows.SDK.NET.Ref was not downloaded. Try running a NuGet restore with the RuntimeIdentifier 'any'.

How can I fix it?

Scottj1s commented 1 month ago

I got a same error. so, I tried ghost1372's suggestion. but I got a following error message:

error NETSDK1112: The runtime pack for Microsoft.Windows.SDK.NET.Ref was not downloaded. Try running a NuGet restore with the RuntimeIdentifier 'any'.

How can I fix it?

@c00012 Did you add a WindowsSdkPackageVersion project property with the value suggested in the build error?

manodasanW commented 1 month ago

@c00012 You might also want to make sure that nuget restore did run without issues after you added that property. I have seen this message when the nuget package didn't get restored.

steam3d commented 4 weeks ago

Adding will fix issue

<WindowsSdkPackageVersion>10.0.20348.38</WindowsSdkPackageVersion>
luttje commented 4 weeks ago

In the most recent update of Visual Studio (17.11.5) this issue is fixed for us (without needing csproj shenanigans).

Thanks

carlosbet commented 3 weeks ago

In the most recent update of Visual Studio (17.11.5) this issue is fixed for us (without needing csproj shenanigans).

Thanks

Confirmed. After updating Visual Studio from 17.11.4 to 17.11.5, the problem is solved and no strange trick is required.

Thanks.