{"id":46393,"date":"2023-07-06T10:05:00","date_gmt":"2023-07-06T17:05:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet\/?p=46393"},"modified":"2023-07-05T12:28:05","modified_gmt":"2023-07-05T19:28:05","slug":"announcing-the-dotnet-community-toolkit-821","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-the-dotnet-community-toolkit-821\/","title":{"rendered":"Improved Source Generators and Code Fixers Arrive in .NET Community Toolkit 8.2.1!"},"content":{"rendered":"<p>We&#8217;re happy to announce the official launch of the 8.2.1 release of the .NET Community Toolkit! This new version includes lots of QoL improvements across all libraries, some more performance optimizations to the MVVM Toolkit source generators, new code fixers and improved diagnostics, and more!<\/p>\n<p><a href=\"https:\/\/aka.ms\/toolkit\/dotnet\/\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2023\/07\/NCT-1920x1080-1.png\" alt=\".NET Community Toolkit 8.2.1\" \/><\/a><\/p>\n<p>We want to give a special thank you to all community members that provided valuable feedbacks to help prioritize work items for this new release. Your contributions and bug reports keep helping us making the .NET Community Toolkit even better with each release \u2014 you&#8217;re the best! \ud83d\ude4c<\/p>\n<h2>What&#8217;s in the .NET Community Toolkit? \ud83d\udc40<\/h2>\n<p>The .NET Community Toolkit includes the following libraries:<\/p>\n<ul>\n<li><code>CommunityToolkit.Common<\/code><\/li>\n<li><code>CommunityToolkit.Mvvm<\/code> (aka &#8220;Microsoft MVVM Toolkit&#8221;)<\/li>\n<li><code>CommunityToolkit.Diagnostics<\/code><\/li>\n<li><code>CommunityToolkit.HighPerformance<\/code><\/li>\n<\/ul>\n<blockquote><p>For more details on the history of the .NET Community Toolkit, <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-the-dotnet-community-toolkit-800\/\">here is a link to our previous 8.0.0 announcement post<\/a>.<\/p><\/blockquote>\n<p>Here is a breakdown of the main changes that are included in this new 8.2.1 release of the .NET Community Toolkit. This release is mostly focused on incremental improvements: there&#8217;s no new features, but lots of tweaks and fixes!<\/p>\n<h2>New analyzer and code fixer for <code>[RelayCommand]<\/code> \ud83e\udd16<\/h2>\n<p>The <code>[RelayCommand]<\/code> attribute (see docs <a href=\"https:\/\/learn.microsoft.com\/dotnet\/communitytoolkit\/mvvm\/generators\/relaycommand\">here<\/a>) can automatically handle asynchronous methods, and it will use the <code>IAsyncRelayCommand<\/code> interfaces in that case (along with the corresponding async command type). This feature was not easily discoverable by developers though, and many would instead just make their command methods <code>async void<\/code>. This also meant that they could not leverage all the additional functionality provided by async commands (such as progress reporting and concurrency control).<\/p>\n<p>To help with this, the 8.2.1 version of the MVVM Toolkit ships with a brand new analyzer, which will emit a diagnostic for <code>async void<\/code> methods annotated with <code>[RelayCommand]<\/code>. And to make things even simpler to use, there&#8217;s also a new code fixer that will automatically refactor the code for you \u2014 just click on the lightbulb icon and let Roslyn do the work for you! \ud83c\udf89<\/p>\n<p><a href=\"https:\/\/aka.ms\/toolkit\/dotnet\/\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2023\/07\/IntelliSense-CodeFix.png\" alt=\"MVVM Toolkit analyzer code fix\" \/><\/a><\/p>\n<p>Here you can see the new generated diagnostic showing up for an <code>async void<\/code> method associated with a command, and its corresponding code fixer UI in Visual Studio featuring a preview of the change. It will also automatically add the necessary <code>using<\/code> statement at the top of your file, in case <code>Task<\/code> is not in scope already. And just like with other code fixers in the MVVM Toolkit, you can also easily apply it to all locations in your entire project or solution, with a single click!<\/p>\n<h2>Other changes and improvements \ud83d\ude80<\/h2>\n<ul>\n<li><strong>Fix an AV when indexing a sliced <code>Memory2D&lt;T&gt;<\/code> instance<\/strong> (<a href=\"https:\/\/github.com\/CommunityToolkit\/dotnet\/pull\/675\">#675<\/a>): in some cases, an access violation could be triggered when indexing elements after slicing a <code>Memory2D&lt;T&gt;<\/code> instance. That is now fixed, thank you <a href=\"https:\/\/github.com\/mahalex\">mahalex<\/a> for reporting this!<\/li>\n<li><strong>Fix forwarding attributes with negative enum values<\/strong> (<a href=\"https:\/\/github.com\/CommunityToolkit\/dotnet\/pull\/682\">#681<\/a>): using enum members with negative values will no longer cause issues with the MVVM Toolkit generators for generated observable properties. Thank you <a href=\"https:\/\/github.com\/n-coelho-cerinnov\">n-coelho-cerinnov<\/a> for reporting this!<\/li>\n<li><strong>Fix a generator crash when forwarding invalid attributes<\/strong> (<a href=\"https:\/\/github.com\/CommunityToolkit\/dotnet\/pull\/684\">#683<\/a>): trying to forward attributes that are not referenced correctly will now fail gracefully and produce an easy to understand error message.<\/li>\n<li><strong>Fix <code>ObservableValidator<\/code> generator to detect inherited properties<\/strong> (<a href=\"https:\/\/github.com\/CommunityToolkit\/dotnet\/pull\/692\">#616<\/a>): the generator to validate properties will no longer accidentally ignore properties from base types for the target viewmodel. Thank you <a href=\"https:\/\/github.com\/dgellow\">dgellow<\/a> for reporting this!<\/li>\n<li><strong>Add warning when using packages.config for MVVM Toolkit<\/strong> (<a href=\"https:\/\/github.com\/CommunityToolkit\/dotnet\/pull\/698\">#695<\/a>): the MVVM Toolkit generators only work when using <code>&lt;PackageReference&gt;<\/code> (it&#8217;s a known limitation of the SDK and it&#8217;s by design), but there was previously no clear indication as to why the generators were not running for users trying to use them from a project using <code>packages.config<\/code>. The MVVM Toolkit now ships with improved diagnostics that will produce a useful warning message in that scenario. Thank you <a href=\"https:\/\/github.com\/smaugbend\">smaugbend<\/a> for reporting this!<\/li>\n<li><strong>Check for cancellation more often in generators<\/strong> (<a href=\"https:\/\/github.com\/CommunityToolkit\/dotnet\/pull\/704\">#703<\/a>): this should result in small improvements in the IDE responsiveness when using the MVVM Toolkit.<\/li>\n<li><strong>Remove unnecessary temporary array allocation<\/strong> (<a href=\"https:\/\/github.com\/CommunityToolkit\/dotnet\/pull\/719\">#719<\/a>): another small memory optimizations to the MVVM Toolkit source generators.<\/li>\n<li><strong>Handle <code>[ObservableProperty]<\/code> fields with keyword identifiers<\/strong> (<a href=\"https:\/\/github.com\/CommunityToolkit\/dotnet\/pull\/720\">#710<\/a>): the generator will no longer produce invalid code in case fields annotated with <code>[ObservableProperty]<\/code> are using keyword identifiers that have been escaped in source (eg. <code>@event<\/code>). Thank you <a href=\"https:\/\/github.com\/Get0457\">Get0457<\/a> for reporting this!<\/li>\n<\/ul>\n<blockquote><p>Note: there is a known issue with source generators in older versions of Roslyn that might cause IntelliSense to sometimes not work correctly for generated members (see <a href=\"https:\/\/github.com\/CommunityToolkit\/dotnet\/issues\/493\">#493<\/a>, and related <a href=\"https:\/\/github.com\/dotnet\/roslyn\/issues\/67123\">Roslyn tracking issue<\/a>). This has finally been fixed in VS 2022 17.7, which is currently in preview. If you&#8217;re seeing any issues using the MVVM Toolkit, make sure to try out the latest VS 17.7 Preview!<\/p><\/blockquote>\n<h2>Other changes \u2699\ufe0f<\/h2>\n<p>You can see the full changelog for this release from the <a href=\"https:\/\/github.com\/CommunityToolkit\/dotnet\/releases\/tag\/v8.2.1\">GitHub release page<\/a>.<\/p>\n<h2>Get started today! \ud83c\udf89<\/h2>\n<p>You can find all source code in our <a href=\"https:\/\/aka.ms\/toolkit\/dotnet\/\">GitHub repo<\/a>, some handwritten docs on <a href=\"https:\/\/aka.ms\/toolkit\/docs\/\">MS learn<\/a>, and complete API references in the .NET API browser website. If you would like to contribute, feel free to open issues or to reach out to let us know about your experience! To follow the conversation on Twitter, use the #CommunityToolkit hashtag. All your feedbacks greatly help in shape the direction of these libraries, so make sure to share them!<\/p>\n<p>Happy coding! \ud83d\udcbb<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;re happy to announce the official launch of the .NET Community Toolkit 8.2.1 release, featuring lots of QoL improvements, bug fixes and optimizations to the source generators, new code fixers, and more!<\/p>\n","protected":false},"author":81469,"featured_media":46394,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[685,7233,756,3009,509,489],"tags":[4,7748,7238,30,46,51,7262,100,108],"class_list":["post-46393","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","category-maui","category-csharp","category-performance","category-wpf","category-xaml","tag-net","tag-net-community-toolkit","tag-net-maui","tag-announcement","tag-c","tag-community","tag-development","tag-mvvm","tag-performance"],"acf":[],"blog_post_summary":"<p>We&#8217;re happy to announce the official launch of the .NET Community Toolkit 8.2.1 release, featuring lots of QoL improvements, bug fixes and optimizations to the source generators, new code fixers, and more!<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/46393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/81469"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=46393"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/46393\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/46394"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=46393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=46393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=46393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}