Undoubtedly, CommunityToolkit.Mvvm, aka Microsoft MVVM Toolkit, has recently become one of the most popular NuGet packages among MVVM developers.
It effectively abstracts away the boilerplate code, enabling developers to concentrate exclusively on the task.
However, after the release of package version 8.3 and later, while building the project referencing this Toolkit has encountered failures, accompanied by perplexing error messages like System.TypeInitializationException or Found conflicts between different versions of 'WinRT.Runtime' that could not be resolved. when targeting the Windows 10 platform.
To resolve this build error, it is imperative to incorporate the below MSBuild property within the project file. This is due to the use of the new Windows SDK projections by the latest version of the toolkit.
<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>
If your project is intended for a Windows 10 SDK version other than 19041, kindly replace 19041 with the relevant version number. For example:
<WindowsSdkPackageVersion>10.0.22621.38</WindowsSdkPackageVersion>
Note: The most recent release of both the All-in-One .NET MAUI Templates and the WinUI CLI Templates will have this property preconfigured when you select either the MVVM option or just the inclusion of this Toolkit package during the project creation process itself.
Happy coding. Stay connected as we continue to learn and share the experiences from this exciting journey of being a .NET developer.