{"id":236215,"date":"2022-01-10T08:00:48","date_gmt":"2022-01-10T16:00:48","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/visualstudio\/?p=236215"},"modified":"2024-01-30T16:43:32","modified_gmt":"2024-01-31T00:43:32","slug":"bringing-code-cleanup-on-save-to-visual-studio-2022-17-1-preview-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/bringing-code-cleanup-on-save-to-visual-studio-2022-17-1-preview-2\/","title":{"rendered":"Bringing Code Cleanup on Save To Visual Studio 2022 17.1 Preview 2"},"content":{"rendered":"<p>Starting in Visual Studio 2022 17.1 Preview 2, developers can now perform Code Cleanup automatically when a file is being saved! Code Cleanup automatically on Save is a new feature integrated into Visual Studio 2022 that can clean up your code file to make sure it is formatted correctly and that your coding style preferences are applied. Some customizable preferences include: format document, sort usings, remove unnecessary usings, and more. This feature can help minimize stylistic violations within PRs and more to allow developers to spend less time fixing code not meeting specific standards and more time doing what they do best. To give it code cleanup on save a try, download Visual Studio 2022 Preview:<\/p>\n<p><div  class=\"d-flex justify-content-center\"><a class=\"cta_button_link btn-primary mb-24\" href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\" target=\"_blank\">Download Visual Studio 2022 Preview<\/a><\/div><\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-236216\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/01\/word-image.gif\" alt=\"Moving image demonstrating code cleanup on save\" width=\"1041\" height=\"542\" \/><\/p>\n<h2>How to enable Code Cleanup on Save<\/h2>\n<p>First, navigate to Analyze &gt; Code Cleanup &gt; Configure Code Cleanup to personalize desirable customizations to your code cleanup profile(s).<\/p>\n<h2><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/01\/Picture1-1.png\"><img decoding=\"async\" class=\"alignnone wp-image-236221 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/01\/Picture1-1.png\" alt=\"Screenshot for configuring code cleanup profiles\" width=\"964\" height=\"688\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/01\/Picture1-1.png 964w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/01\/Picture1-1-300x214.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/01\/Picture1-1-768x548.png 768w\" sizes=\"(max-width: 964px) 100vw, 964px\" \/><\/a><\/h2>\n<p>Next, navigate to Tools &gt; Options &gt; Text Editor &gt; Code Cleanup. Add a check in the \u201cRun Code Cleanup profile on Save\u201d. Be sure to select the appropriate profile you want to execute automatically whenever you save!<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/01\/Picture2.png\"><img decoding=\"async\" class=\"alignnone wp-image-236223 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/01\/Picture2.png\" alt=\"Screenshot of dialogue to enable code cleanup on save\" width=\"964\" height=\"774\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/01\/Picture2.png 964w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/01\/Picture2-300x241.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/01\/Picture2-768x617.png 768w\" sizes=\"(max-width: 964px) 100vw, 964px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>Try it out and share your feedback!<\/h2>\n<p>We would love to get your feedback on Code Cleanup on Save so please give it a try and let us know what you think! You can share any feedback via <a href=\"https:\/\/developercommunity2.visualstudio.com\/home\">Developer Community<\/a> to help us make Visual Studio better for you!<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Starting in Visual Studio 2022 17.1 Preview 2, developers can now perform Code Cleanup automatically when a file is being saved! Code Cleanup automatically on Save is a new feature integrated into Visual Studio 2022 that can clean up your code file to make sure it is formatted correctly and that your coding style preferences [&hellip;]<\/p>\n","protected":false},"author":78633,"featured_media":255385,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"image","meta":{"_acf_changed":false,"footnotes":""},"categories":[155],"tags":[],"class_list":["post-236215","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-visual-studio","post_format-post-format-image"],"acf":[],"blog_post_summary":"<p>Starting in Visual Studio 2022 17.1 Preview 2, developers can now perform Code Cleanup automatically when a file is being saved! Code Cleanup automatically on Save is a new feature integrated into Visual Studio 2022 that can clean up your code file to make sure it is formatted correctly and that your coding style preferences [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/236215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/users\/78633"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=236215"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/236215\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/255385"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=236215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=236215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=236215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}