乐知付加密服务平台

如果你有资源, 平台可以帮你实现内容变现, 无需搭建知识付费服务平台。

点击访问官方网站 https://lezhifu.cc

扫码关注公众号 乐知付加密服务平台-微信公众号
记录第一次使用WinUI3运行HelloWorld的错误 | chenzuoli's blog

记录第一次使用WinUI3运行HelloWorld的错误

第一次开发windows客户端程序,搭建本地环境,按照官档搭建winui3环境,开发一个简单的点击时间界面。
这篇文章介绍一个错误,怎么解决,欢迎大家讨论。

环境信息

.net version: 8.0.401
visual studio 2022
windows 11

错误信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
严重性	代码	说明	项目	文件	行	禁止显示状态
错误(活动) This version of the Windows App SDK requires Microsoft.Windows.SDK.NET.Ref 10.0.19041.38 or later.
Please update to .NET SDK 6.0.134, 6.0.426, 8.0.109, 8.0.305 or 8.0.402 (or later).
Or add a temporary Microsoft.Windows.SDK.NET.Ref reference which can be added with:
<PropertyGroup>
<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>
</PropertyGroup>
HelloWorld C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\buildTransitive\Microsoft.WindowsAppSDK.targets 76
错误(活动) CS1061 “MainWindow”未包含“InitializeComponent”的定义,并且找不到可接受第一个“MainWindow”类型参数的可访问扩展方法“InitializeComponent”(是否缺少 using 指令或程序集引用?) HelloWorld E:\VisualStudioProjects\HelloWorld\HelloWorld\HelloWorld\MainWindow.xaml.cs 28
错误(活动) CS0103 当前上下文中不存在名称“myButton” HelloWorld E:\VisualStudioProjects\HelloWorld\HelloWorld\HelloWorld\MainWindow.xaml.cs 33
警告(活动) MSB3277 发现无法解析的“WinRT.Runtime”的不同版本之间存在冲突。
“WinRT.Runtime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709”与“WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709”之间存在冲突。
已选择“WinRT.Runtime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709”,因为它是主版本而“WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709”不是。
依赖于“WinRT.Runtime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709”[C:\Users\Administrator\.nuget\packages\microsoft.windows.sdk.net.ref\10.0.19041.34\lib\net6.0\WinRT.Runtime.dll]的引用。
C:\Users\Administrator\.nuget\packages\microsoft.windows.sdk.net.ref\10.0.19041.34\lib\net6.0\WinRT.Runtime.dll
导致引用“C:\Users\Administrator\.nuget\packages\microsoft.windows.sdk.net.ref\10.0.19041.34\lib\net6.0\WinRT.Runtime.dll”的项目文件项 Include 特性。
C:\Users\Administrator\.nuget\packages\microsoft.windows.sdk.net.ref\10.0.19041.34\lib/net6.0/WinRT.Runtime.dll
依赖于或已统一到“WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709”[] 的引用。
C:\Users\Administrator\.nuget\packages\microsoft.web.webview2\1.0.2651.64\lib_manual\net6.0-windows10.0.17763.0\Microsoft.Web.WebView2.Core.Projection.dll
导致引用“C:\Users\Administrator\.nuget\packages\microsoft.web.webview2\1.0.2651.64\lib_manual\net6.0-windows10.0.17763.0\Microsoft.Web.WebView2.Core.Projection.dll”的项目文件项 Include 特性。
C:\Users\Administrator\.nuget\packages\microsoft.web.webview2\1.0.2651.64\build\..\\lib_manual\net6.0-windows10.0.17763.0\Microsoft.Web.WebView2.Core.Projection.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.WinUI.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.InteractiveExperiences.Projection.dll
导致引用“C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.InteractiveExperiences.Projection.dll”的项目文件项 Include 特性。
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.InteractiveExperiences.Projection.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.WinUI.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.WinUI.dll
导致引用“C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.WinUI.dll”的项目文件项 Include 特性。
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.WinUI.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.AppLifecycle.Projection.dll
导致引用“C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.AppLifecycle.Projection.dll”的项目文件项 Include 特性。
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.AppLifecycle.Projection.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.AppNotifications.Builder.Projection.dll
导致引用“C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.AppNotifications.Builder.Projection.dll”的项目文件项 Include 特性。
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.AppNotifications.Builder.Projection.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.AppNotifications.Projection.dll
导致引用“C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.AppNotifications.Projection.dll”的项目文件项 Include 特性。
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.AppNotifications.Projection.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.AppNotifications.Builder.Projection.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.ApplicationModel.DynamicDependency.Projection.dll
导致引用“C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.ApplicationModel.DynamicDependency.Projection.dll”的项目文件项 Include 特性。
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.ApplicationModel.DynamicDependency.Projection.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.Management.Deployment.Projection.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.ApplicationModel.Resources.Projection.dll
导致引用“C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.ApplicationModel.Resources.Projection.dll”的项目文件项 Include 特性。
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.ApplicationModel.Resources.Projection.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.WinUI.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.ApplicationModel.WindowsAppRuntime.Projection.dll
导致引用“C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.ApplicationModel.WindowsAppRuntime.Projection.dll”的项目文件项 Include 特性。
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.ApplicationModel.WindowsAppRuntime.Projection.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.Management.Deployment.Projection.dll
导致引用“C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.Management.Deployment.Projection.dll”的项目文件项 Include 特性。
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.Management.Deployment.Projection.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.PushNotifications.Projection.dll
导致引用“C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.PushNotifications.Projection.dll”的项目文件项 Include 特性。
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.PushNotifications.Projection.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.Security.AccessControl.Projection.dll
导致引用“C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.Security.AccessControl.Projection.dll”的项目文件项 Include 特性。
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.Security.AccessControl.Projection.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.Storage.Projection.dll
导致引用“C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.Storage.Projection.dll”的项目文件项 Include 特性。
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.Storage.Projection.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.System.Power.Projection.dll
导致引用“C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.System.Power.Projection.dll”的项目文件项 Include 特性。
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.System.Power.Projection.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.System.Projection.dll
导致引用“C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.System.Projection.dll”的项目文件项 Include 特性。
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.System.Projection.dll
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.Widgets.Projection.dll
导致引用“C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.Widgets.Projection.dll”的项目文件项 Include 特性。
C:\Users\Administrator\.nuget\packages\microsoft.windowsappsdk\1.6.240829007\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.Widgets.Projection.dll HelloWorld D:\VisualStudio\VisualStudioIDE\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets 2412

解决办法

根据错误日志堆栈信息,提示:

1
2
3
4
5
6
错误(活动)		This version of the Windows App SDK requires Microsoft.Windows.SDK.NET.Ref 10.0.19041.38 or later.
Please update to .NET SDK 6.0.134, 6.0.426, 8.0.109, 8.0.305 or 8.0.402 (or later).
Or add a temporary Microsoft.Windows.SDK.NET.Ref reference which can be added with:
<PropertyGroup>
<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>
</PropertyGroup>

我们修改项目的依赖windows sdk版本为10.0.19041.38
位置:

  1. 切换到【解决方案资源管理器】
  2. 双击查看项目依赖配置文件
    info

添加windows sdk版本:

1
2
3
<PropertyGroup>
<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>
</PropertyGroup>

好了,记录到这里,如有问题,欢迎大家联系我讨论。

修行


书山有路勤为径,学海无涯苦作舟。

欢迎关注微信公众号:【乐知付加密平台】,您的网络资源可变现
乐知付加密平台

一起学习,一起进步。

-------------本文结束感谢您的阅读-------------