{"id":248389,"date":"2024-03-27T08:00:55","date_gmt":"2024-03-27T15:00:55","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/visualstudio\/?p=248389"},"modified":"2024-03-26T18:40:47","modified_gmt":"2024-03-27T01:40:47","slug":"experimental-msbuild-editor","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/experimental-msbuild-editor\/","title":{"rendered":"A new MSBuild editing experience"},"content":{"rendered":"<p>MSBuild is a fundamental part of the .NET development experience, but it can be challenging to new and experienced developers alike. To help developers better understand their project files and access advanced functionality that requires editing the project file directly, we\u2019re releasing an <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=mhutch.MSBuildEditor\">experimental MSBuild editor<\/a>\u00a0that has a much richer understanding of MSBuild files than the current XML schema allows. Based on feedback, we hope to make it available by default to all .NET developers. If you work with MSBuild files at all, please try it and let us know how it goes.<\/p>\n<h2>Who is this for?<\/h2>\n<p>Although Visual Studio provides a rich UI for managing your project and its settings, you may need to edit your csproj file directly to access certain advanced features that are not exposed in the UI. You may also need to edit csproj files directly when merging changes from source control, or you may be writing targets and props files for local use or for publishing in a NuGet package. If any of these scenarios apply to you, we\u2019d like your feedback on the new experience.<\/p>\n<h2>Understand your project file<\/h2>\n<p>The new MSBuild editor provides Quick Info not just for XML elements in MSBuild files, but also for properties, items and metadata in MSBuild expressions. The Quick Info popup is richer, and has deep links to relevant documentation, as well as hyperlinks to references in other files that may help you understand how that property or item is used by the underlying targets.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/quickinfo.png\"><img decoding=\"async\" class=\"alignnone wp-image-248396 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/quickinfo.png\" alt=\"Quick Info on compiler warning codes\" width=\"698\" height=\"168\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/quickinfo.png 698w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/quickinfo-300x72.png 300w\" sizes=\"(max-width: 698px) 100vw, 698px\" \/><\/a><\/p>\n<p>If you\u2019d like to understand how a property or item is used, you can use Ctrl-Click or the <em>Go to Definition<\/em> command to go to where it\u2019s defined. You can also use the <em>Find References <\/em>command to perform a precise search across all imported files:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/findrefs.png\"><img decoding=\"async\" class=\"alignnone wp-image-248392 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/findrefs.png\" alt=\"Tool window showing result of Find References\" width=\"936\" height=\"208\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/findrefs.png 936w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/findrefs-300x67.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/findrefs-768x171.png 768w\" sizes=\"(max-width: 936px) 100vw, 936px\" \/><\/a><\/p>\n<h2>Code without leaving the editor<\/h2>\n<p>Even as an experienced MSBuild author, I often used to open the documentation to find the exact names and allowed values of MSBuild properties, items and metadata. I do that far less when using the MSBuild editor, as it provides IntelliSense almost everywhere in the file, with documentation powered by its schemas:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/intellisense.png\"><img decoding=\"async\" class=\"alignnone wp-image-248393 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/intellisense.png\" alt=\"IntelliSense for comparands in condition expressions\" width=\"882\" height=\"118\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/intellisense.png 882w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/intellisense-300x40.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/intellisense-768x103.png 768w\" sizes=\"(max-width: 882px) 100vw, 882px\" \/><\/a><\/p>\n<p>It has special support for NuGet packages, allowing you to search for the package ID, and see the package description and a link to its NuGet.org page:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/vs-packageref-completion.gif\"><img decoding=\"async\" class=\"alignnone wp-image-248475 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/vs-packageref-completion.gif\" alt=\"IntelliSense for PackageReference items, showing completion from NuGet.org\" width=\"812\" height=\"221\" \/><\/a><\/p>\n<p>Other types also have special handling, for example culture names:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/culturenames.png\"><img decoding=\"async\" class=\"alignnone wp-image-248391 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/culturenames.png\" alt=\"IntelliSense offering completion for culture names for the NeutralLanguage property\" width=\"772\" height=\"130\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/culturenames.png 772w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/culturenames-300x51.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/culturenames-768x129.png 768w\" sizes=\"(max-width: 772px) 100vw, 772px\" \/><\/a><\/p>\n<p>And there is IntelliSense within MSBuild expressions, including property functions and item functions:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/propertyfunc.png\"><img decoding=\"async\" class=\"alignnone wp-image-248395 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/propertyfunc.png\" alt=\"IntelliSense for property functions\" width=\"762\" height=\"102\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/propertyfunc.png 762w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/propertyfunc-300x40.png 300w\" sizes=\"(max-width: 762px) 100vw, 762px\" \/><\/a><\/p>\n<p>The editor isn\u2019t limited to those properties and items defined in its schemas. It scans all imported MSBuild files, and provides inferred completion for any properties, items, metadata and targets it finds in those files as well. Even better, the tooltip has a hyperlink to the property or item is used in:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/targetname.png\"><img decoding=\"async\" class=\"alignnone wp-image-248398 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/targetname.png\" alt=\"IntelliSense offering completions for target names\" width=\"936\" height=\"180\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/targetname.png 936w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/targetname-300x58.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/targetname-768x148.png 768w\" sizes=\"(max-width: 936px) 100vw, 936px\" \/><\/a><\/p>\n<h2>Catch problems early<\/h2>\n<p>The MSBuild Editor\u2019s validations go beyond just XML validation. It overlays a type system onto MSBuild, so you will get errors about malformed values such as URLs or version strings. Its understanding of the MSBuild expression format means you can catch malformed conditions and expressions without having to run your build.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/squiggle.png\"><img decoding=\"async\" class=\"alignnone wp-image-248397 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/squiggle.png\" alt=\"Error squiggle on a missing quote character in a condition expression\" width=\"474\" height=\"100\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/squiggle.png 474w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/squiggle-300x63.png 300w\" sizes=\"(max-width: 474px) 100vw, 474px\" \/><\/a><\/p>\n<p>There are even a few Roslyn-style analyzers and code fixes.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/codefix.png\"><img decoding=\"async\" class=\"alignnone wp-image-248390 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/codefix.png\" alt=\"Code fix offering a spelling fix for a misspelled property name\" width=\"694\" height=\"144\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/codefix.png 694w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/03\/codefix-300x62.png 300w\" sizes=\"(max-width: 694px) 100vw, 694px\" \/><\/a><\/p>\n<h2>Enhance the MSBuild editing experience<\/h2>\n<p>The MSBuild Editor is powered by a new MSBuild-specific json-based <a href=\"https:\/\/github.com\/mhutch\/MonoDevelop.MSBuildEditor\/blob\/main\/MonoDevelop.MSBuild\/Schemas\/buildschema.json\">schema format<\/a> that allows defining documentation and type annotations for MSBuild properties, items, item metadata, and targets. It <a href=\"https:\/\/github.com\/mhutch\/MonoDevelop.MSBuildEditor\/tree\/main\/MonoDevelop.MSBuild\/Schemas\">includes built-in schemas<\/a> for the .NET SDK and other commonly used targets and SDKs.<\/p>\n<p>However, you can also <a href=\"https:\/\/github.com\/mono\/t4\/blob\/main\/Mono.TextTemplating.Build\/T4.BuildTools.targets.buildschema.json\">write schemas for your own MSBuild targets<\/a> to allow the MSBuild editor to provide a richer experience when editing or consuming them. If you\u2019re an author of a NuGet package that contains build targets, you can <a href=\"https:\/\/github.com\/mono\/t4\/blob\/5d0f76c785e83a712390aba8023a77aa945fe59f\/Mono.TextTemplating.Build\/Mono.TextTemplating.Build.csproj#L22\">ship that sidecar schema in the NuGet package<\/a> to provide a better MSBuild editing experience for consumers of your package.<\/p>\n<h2>Q&amp;A<\/h2>\n<p><strong>Q.<\/strong> The extension has a GitHub repository \u2013 can I build from source and contribute?<\/p>\n<p><strong>A.<\/strong> Absolutely! Just clone the repository and its submodules, open in Visual Studio, and hit F5.<\/p>\n<p><strong>Q.<\/strong> Why do the extension repository, namespaces and assemblies have \u201cMonoDevelop\u201d in the name?<\/p>\n<p><strong>A.<\/strong> MSBuild Editor is a descendant of an extension I originally created for the MonoDevelop IDE in March 2015. Although it evolved a lot over the years, including porting to Visual Studio, I kept the internal name for nostalgia\u2019s sake.<\/p>\n<p><strong>Q.<\/strong> Can I use the extension in Visual Studio Code?<\/p>\n<p><strong>A.<\/strong> Not yet! I\u2019m currently porting the extension to LSP (Language Server Protocol) so it can be used in a Visual Studio Code extension. While LSP would be the obvious choice for a new extension, this codebase goes back to before Visual Studio Code was released.<\/p>\n<h2>We want your feedback!<\/h2>\n<p>If you\u2019d like to give the extension a spin, you can find it by searching for \u201cMSBuild Editor\u201d from within Visual Studio extension manager or download it <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=mhutch.MSBuildEditor\">from the Visual Studio Marketplace<\/a>. The extension is currently only available for Visual Studio, but work is in progress on porting it to Visual Studio Code.<\/p>\n<p>If you run into any problems with the extension, please post them on its <a href=\"https:\/\/github.com\/mhutch\/MonoDevelop.MSBuildEditor\/issues\">GitHub issues page<\/a>. The extension is open source and contributions are welcome. Please also let us know about your experience by filling out <a href=\"https:\/\/www.surveymonkey.com\/r\/G3F9SC3\">this survey<\/a>. We appreciate your feedback, and it will help guide how the experiment develops and whether the MSBuild Editor becomes an officially supported part of the .NET development experience.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MSBuild is a fundamental part of the .NET development experience, but it can be challenging to new and experienced developers alike. To help developers better understand their project files and access advanced functionality that requires editing the project file directly, we\u2019re releasing an experimental MSBuild editor\u00a0that has a much richer understanding of MSBuild files than [&hellip;]<\/p>\n","protected":false},"author":1390,"featured_media":248396,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[155],"tags":[6879,6862,37],"class_list":["post-248389","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-visual-studio","tag-editor","tag-experiment","tag-msbuild"],"acf":[],"blog_post_summary":"<p>MSBuild is a fundamental part of the .NET development experience, but it can be challenging to new and experienced developers alike. To help developers better understand their project files and access advanced functionality that requires editing the project file directly, we\u2019re releasing an experimental MSBuild editor\u00a0that has a much richer understanding of MSBuild files than [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/248389","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\/1390"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=248389"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/248389\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/248396"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=248389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=248389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=248389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}