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.72k stars 307 forks source link

Can not install nuget package: 1.5.240607001 on WinForms project target .net 8.0 for Windows #4509

Open zydjohnHotmail opened 6 days ago

zydjohnHotmail commented 6 days ago

Describe the bug

Hi, I want to create one WinForms app project using Visual Studio 2022 (Version 17.10.3) and use Nuget Microsoft.WindowsAppSDK to do some OCR tests, but as long as I installed the Nuget Microsoft.WindowsAppSDK current version, I saw the error, and the whole project is not able to open again normally. If you open the project, it is no long a WinForms app project, all the items in the original project are unloaded.

Steps to reproduce the bug

  1. Create a WinForms app project.
  2. Change CPU from anyCPU to X64
  3. Try to install nuget package current version: PM>Install-Package Microsoft.WindowsAppSDK -Version 1.5.240607001
  4. You will see the error, then your project is basically useless.

Expected behavior

The nuget package Microsoft.WindowsAppSDK -Version 1.5.240607001 should be installed without any of such issue, and users should be able to write code to use this package to do some OCR jobs.

Screenshots

See the screenshot for the error: InstallMicrosoft WindowsAppSDKNOK

NuGet package version

Windows App SDK 1.5.4: 1.5.240607001

Packaging type

Unpackaged

Windows version

Windows 10 version 22H2 (19045, 2022 Update)

IDE

Visual Studio 2022

Additional context

Hi, since the font of the error message is too small, so I have to use some free online tools to do "OCR" to show you the error message. (: The following is the error messages in text: @ The project ‘MicrosoftAlOCRForm' ran into a problem during the last operation: A numeric comparison was attempted on "$(TargetPlatformVersion)" that evaluates to“ instead of a number, in condition "'$(TargetPlatformldentifier)’ == Windows’ and ‘$(TargetPlatformVersion)' >= '8.0"". C:\Users\ohn.nuget\packages\microsoft.windowsappsdk\1.5.240607001\ build Transitive\ Microsoft.UI.Xaml.Markup.Compiler.interop.targets You may need to reload the solution after fixing the problem. No response

DarranRowe commented 4 days ago

One possible problem is that the Windows App SDK requires you to target a Windows 10 version >= 10.0.17763.0. This doesn't get set with a .NET application. For now, the easiest way to fix the project is to open the .csproj file and add the version to the TargetFramework element. As an example, from:

Screenshot 2024-06-27 132705

to:

Screenshot 2024-06-27 132735

Note the addition of the version number. This should allow you to get the project you are working on back up and running.

The current way to add the Windows App SDK to the project first requires that you set the Target OS version in the project properties.

Screenshot 2024-06-27 133128

Screenshot 2024-06-27 133144

This adds the version number to the TargetFramework element. You need to do this before you add the Windows App SDK NuGet package.

You would expect that the target version be set to an appropriate value though.

zydjohnHotmail commented 4 days ago

Hello: I have tried my best to understand your instruction and install it again, but no luck. I have done the following, and maybe combine some actions:

  1. Create one WinForms App project: WindowsAppSDKOCRForm
  2. Change CPU to x64 (I think better not even allow x86 any more nowadays)
  3. Change the target Windows 10 version >= 10.0.17763.0. (Actually, I have tried all 5 different versions of Windows 10, but I always get the same errors)
  4. Close the project and re-open
  5. Install WindowsAppSDK nuget package current version: PM>Install-Package Microsoft.WindowsAppSDK -Version 1.5.240607001
  6. Almost immediately, I got 7 errors.
  7. I also tried another way: set target to .net 8.0 windows, then use text editor to change the target to something like this: net8.0-windows10.0.22000.0

    But I always got the same errors, total 7 errors. You can see the screenshot. At least I have to say that for this Nuget package, it is very very user not friendly. Unless you are the member in the team who develop this package, who may know how to use this. But ask your colleagues in Microsoft, even they are developers, and may want to use this Nuget package, do you think they can figure this out. But my experience shows that your advice did NOT work yet. Please advise what I can do to get this installed? Please refer to the screen shots for details> TargetWindowsSDKVersionInstallMicrosoft WindowsAppSDKNOK

Best Regards,

DarranRowe commented 4 days ago

Ironically, seeing those errors means that you got it to work. The Windows App SDK NuGet is in and working. Congratulations. What you are seeing now is something missing from your project file. I didn't think to mention this earlier, since I was only thinking about getting the package to install for you.

Anyway, you also need to set the runtime identifiers for any platform that you are targetting.

Screenshot 2024-06-27 164613

With this set, it will still warn about a version specific RID, but that is a known issue.

zydjohnHotmail commented 3 days ago

Hi, If I can install this nuget package even see 7 errors, as you said if installation is ironically successful, but how can build the project? Whenever I have those 7 errors, I can't build the project. Please advise either how to build the project with 7 errors or how to fix those 7 errors, even those errors are not directly caused by this nuget package?

DarranRowe commented 2 days ago

I already told you, look at the screenshot. This allows the project to build successfully with a single warning.

zydjohnHotmail commented 2 days ago

Hi, I tried again according to your advice, here is my current .csproj file:

WinExe net8.0-windows10.0.22000.0 enable true enable win-x64

I hope my .csproj file is correct. But when I built my project, I still got the same 7 errors. Please see the screenshot. Let me know if I missed anything. Thanks, MSAIOcrProjectNOK

DarranRowe commented 1 day ago

Look at my screenshot again, carefully. It has <RuntimeIdentifiers>win-x64</RuntimeIdentifiers>. Notice the plural.

WinFormsWASDKTest.zip

Above is a project that is set up to use the Windows App SDK.

zydjohnHotmail commented 1 day ago

Hi, Thanks for your reply, I finally got this installed. However, what I want to use this nuget pacakge in WinForm app project is I found maybe I can use new library to do OCR job, refer to this article: Text Recognition in the Windows App SDK (Url: https://learn.microsoft.com/en-us/windows/ai/apis/text-recognition) But this article indicate that I need a NPU and write C++ code to do job, since NPU is very new device, I don't have this yet, and I don't believe most of the people have this nowadays. And since my knowledge for C++ is also very limited. But I want to know if I can use this Nuget package running in my C# WinForm project to do the same OCR job as described in the article without a NPU hardware and without writting C++ code, I can write C# code in my Windows 10 PC without a NPU. Please advise, Thanks,