{"id":2533,"date":"2022-11-15T20:15:32","date_gmt":"2022-11-16T01:15:32","guid":{"rendered":"https:\/\/badecho.com\/?p=2533"},"modified":"2023-02-20T20:38:16","modified_gmt":"2023-02-21T01:38:16","slug":"monogame-pipeline-net7","status":"publish","type":"post","link":"https:\/\/badecho.com\/index.php\/2022\/11\/15\/monogame-pipeline-net7\/","title":{"rendered":"MonoGame Pipeline Extensions with .NET 7"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2022\/11\/PipelineExtensionsWith7.png\" alt=\"MonoGame Pipeline Extensions with .NET 7\" class=\"wp-image-2535\" width=\"856\" height=\"448\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2022\/11\/PipelineExtensionsWith7.png 856w, https:\/\/badecho.com\/wp-content\/uploads\/2022\/11\/PipelineExtensionsWith7-300x157.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2022\/11\/PipelineExtensionsWith7-768x402.png 768w, https:\/\/badecho.com\/wp-content\/uploads\/2022\/11\/PipelineExtensionsWith7-480x251.png 480w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/figure><\/div>\n\n\n\n<p><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-dotnet-7\/\" target=\"_blank\" rel=\"noreferrer noopener\">.NET 7 has just been released<\/a>! If you&#8217;re like me, you like to get everything updated to the latest as soon as possible. And, if you&#8217;ve been working with MonoGame, doing so should be relatively painless.<\/p>\n\n\n\n<p>You actually shouldn&#8217;t have to do anything: it should just work! That is unless you&#8217;re doing anything special, such as <a href=\"https:\/\/badecho.com\/index.php\/2022\/08\/17\/extending-pipeline\/\" target=\"_blank\" rel=\"noreferrer noopener\">writing an extension to MonoGame&#8217;s content pipeline<\/a>. If your extension is targeting .NET 7, it isn&#8217;t going to work.<\/p>\n\n\n\n<p>This article is going to go over how we can set up an environment where all our game-related components are targeting .NET 7 without having any errors thrown in our faces. <\/p>\n\n\n\n<p>This is something that will be eventually addressed by the MonoGame team; however, given that .NET 6 was out for almost a year before an official MonoGame fix was released, I feel like this article will have value for a good amount of time.<\/p>\n\n\n\n<h2>The Problem<\/h2>\n\n\n\n<p>Developing a game using MonoGame involves referencing several libraries. In previous releases, they were of the typical .NET Standard v2.0 variety; however, they are targeting .NET 6 as of the latest release. <\/p>\n\n\n\n<p>That little bit of minutia is neither here nor there, however, as referencing a .NET 6 library from a .NET 7 library or application is fine and will result in no errors.<\/p>\n\n\n\n<p>A computer game involves more work than just a standard software application: we also need to be aware of all the game-related content that needs to be shipped with and ultimately rendered in the game.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2022\/07\/MGCBEditor.png\" alt=\"Shows the MonoGame content builder UI.\" class=\"wp-image-2410\" width=\"865\" height=\"462\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2022\/07\/MGCBEditor.png 865w, https:\/\/badecho.com\/wp-content\/uploads\/2022\/07\/MGCBEditor-300x160.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2022\/07\/MGCBEditor-768x410.png 768w, https:\/\/badecho.com\/wp-content\/uploads\/2022\/07\/MGCBEditor-480x256.png 480w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><figcaption>The MGCB editor is used to organize the content built and shipped with your game.<\/figcaption><\/figure><\/div>\n\n\n\n<h3>Content Building Involves a Number of Tools<\/h3>\n\n\n\n<p>A game powered by MonoGame loads pre-processed game-related data in a platform-neutral manner using its content pipeline. This requires said data to be stored in MonoGame&#8217;s XNB format, the encoding of which is achieved by using MonoGame&#8217;s content builder tools.<\/p>\n\n\n\n<p>The first tool involved is the MGCB Editor, a graphical interface used to organize the <code>.mgcb<\/code> file that defines the assets bundled with the game and the manner of their bundling.<\/p>\n\n\n\n<p>The second tool is the MonoGame Content Builder, which builds the content, available as a .NET tool, and is invoked either at build-time by the <code>MonoGame.Content.Builder.Task<\/code> or manually through either the MGCB Editor or via the command line.<\/p>\n\n\n\n<h3>.NET 7 Pipeline Extensions Cause All MGCB Tools to Fail<\/h3>\n\n\n\n<p>Although it&#8217;s fine that the MonoGame libraries we&#8217;re referencing target a (now) older version of .NET, it suddenly becomes a problem if our pipeline extension targets a newer version, since the content pipeline&#8217;s libraries and tools need to load&nbsp;<em>our<\/em>&nbsp;extension.<\/p>\n\n\n\n<p>And, as you might know, although .NET assemblies are backward compatible, they most definitely are not forward compatible.<\/p>\n\n\n\n<p>The MonoGame.Content.Builder.Task and the .NET tool it invokes need to load the pipeline extension so it can use its content importers and processors. The MGCB Editor needs to load the pipeline extension to discover what importers and processors it makes available.<\/p>\n\n\n\n<p>All of these tools will fail to function, a problem that can only be remedied by retargeting these libraries and tools so that they target the latest version of .NET. Luckily for you, I took care of this already so you don&#8217;t have to!<\/p>\n\n\n\n<h2>Use Bad Echo&#8217;s Assemblies in the Interim<\/h2>\n\n\n\n<p>Last time I checked, MonoGame&#8217;s experimental NuGet package feed did not reflect the latest source on its GitHub. When targeting .NET 6 was an issue, we all had to wait until a stable release came out.<\/p>\n\n\n\n<p>Until such a release fixing our .NET 7 problem arrives, you can use the assemblies I built and published. They were compiled using the latest source (at the time of this article&#8217;s publishing) but are powered instead by .NET 7.<\/p>\n\n\n\n<h3>Here&#8217;s What You Need to Grab<\/h3>\n\n\n\n<p>Everything needed can be found on the official <a href=\"https:\/\/www.nuget.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">nuget.org<\/a> feed through Visual Studio&#8217;s &#8220;Manage NuGet Packages&#8230;&#8221; interface. Note that all these packages are marked as pre-releases (so don&#8217;t forget to check <em>that one<\/em> box!).<\/p>\n\n\n\n<p>First, you&#8217;ll need to install the <code><a href=\"https:\/\/www.nuget.org\/packages\/MonoGame.Content.Builder.BadEchoTask\/3.8.2.1-develop\" target=\"_blank\" rel=\"noreferrer noopener\">MonoGame.Content.Builder.BadEchoTask<\/a><\/code> NuGet package to your game or whatever other kind of project you have that needs to build content relying on .NET 7 powered pipeline extensions.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2022\/11\/ContentBuilderBadEchoTask.png\" alt=\"Shows the NuGet package required for .NET 7 friendly pipeline fun.\" class=\"wp-image-2537\" width=\"815\" height=\"60\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2022\/11\/ContentBuilderBadEchoTask.png 815w, https:\/\/badecho.com\/wp-content\/uploads\/2022\/11\/ContentBuilderBadEchoTask-300x22.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2022\/11\/ContentBuilderBadEchoTask-768x57.png 768w, https:\/\/badecho.com\/wp-content\/uploads\/2022\/11\/ContentBuilderBadEchoTask-480x35.png 480w\" sizes=\"(max-width: 815px) 100vw, 815px\" \/><figcaption>This NuGet package needs to be added to whatever project is building content.<\/figcaption><\/figure><\/div>\n\n\n\n<p>You will, of course, want to remove any existing reference to the <code>MonoGame.Content.Builder.Task<\/code> package. Worlds will collide otherwise!<\/p>\n\n\n\n<p>Next, you <em>must<\/em> install the MGCB .NET tool packages, shown here:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2022\/11\/ContentBuilderTools.png\" alt=\"Shows the NuGet .NET tool packages required for .NET 7 friendly pipeline fun.\" class=\"wp-image-2538\" width=\"815\" height=\"208\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2022\/11\/ContentBuilderTools.png 815w, https:\/\/badecho.com\/wp-content\/uploads\/2022\/11\/ContentBuilderTools-300x77.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2022\/11\/ContentBuilderTools-768x196.png 768w, https:\/\/badecho.com\/wp-content\/uploads\/2022\/11\/ContentBuilderTools-480x123.png 480w\" sizes=\"(max-width: 815px) 100vw, 815px\" \/><figcaption>If you don&#8217;t want to use the MGCB Editor, the editor-related packages are optional. The core MGCB .NET tool package, however, is required.<\/figcaption><\/figure><\/div>\n\n\n\n<p>However, you can&#8217;t just search for these NuGet packages and click &#8220;Install&#8221;. Nope, that would be far too easy my friend.<\/p>\n\n\n\n<p>These are .NET tool packages, and their use requires some things that would otherwise be taken care of by a Visual Studio project template (you&#8217;d need to grab some updated MonoGame template projects, and sorry, not interested in packaging modified versions of those up).<\/p>\n\n\n\n<h3>Installing the .NET Tools Locally<\/h3>\n\n\n\n<p>To switch what you&#8217;re using to my .NET 7 friendly version, go to your project&#8217;s root directory and look for a <code>.config<\/code> directory. There should be one in there if you&#8217;ve been using MonoGame&#8217;s current version!<\/p>\n\n\n\n<p>Inside this folder, there will be a <code>dotnet-tools.json<\/code> file. This contains the project&#8217;s .NET tool configuration, and we&#8217;ll want to update that so that the tool packages I published get used.<\/p>\n\n\n\n<h6>dotnet-tools.json<\/h6>\n\n\n<pre class=\"brush: lua; title: ; notranslate\" title=\"\">\n{\n  &quot;version&quot;: 1,\n  &quot;isRoot&quot;: true,\n  &quot;tools&quot;: {\n    &quot;bad-echo-mgcb&quot;: {\n      &quot;version&quot;: &quot;3.8.2.1-develop&quot;,\n      &quot;commands&quot;: [\n        &quot;mgcb&quot;\n      ]\n    },\n    &quot;bad-echo-mgcb-editor&quot;: {\n      &quot;version&quot;: &quot;3.8.2.1-develop&quot;,\n      &quot;commands&quot;: [\n        &quot;mgcb-editor&quot;\n      ]\n    },\n    &quot;bad-echo-mgcb-editor-windows&quot;: {\n      &quot;version&quot;: &quot;3.8.2.1-develop&quot;,\n      &quot;commands&quot;: [\n        &quot;mgcb-editor-windows&quot;\n      ]\n    }\n  }\n}\n<\/pre>\n\n\n<p>The configuration shown above should be used in place of any preexisting entries for <code>dotnet-mgcb<\/code>, <code>dotnet-mgcb-editor<\/code>, and <code>dotnet-mgcb-editor-windows<\/code>.<\/p>\n\n\n\n<p>That&#8217;s it! Enjoy developing your game in a now-fully-.NET-7.0 environment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>.NET 7 has just been released! If you&#8217;re like me, you like to get everything updated to the latest as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[41,42,74],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v14.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\r\n<title>MonoGame Pipeline Extensions with .NET 7 - omni&#039;s hackpad<\/title>\r\n<meta name=\"description\" content=\".NET 7 just came out, but pipeline extensions targeting this version don&#039;t work out of the box. Until there&#039;s an update, here&#039;s a workaround.\" \/>\r\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/badecho.com\/index.php\/2022\/11\/15\/monogame-pipeline-net7\/\" \/>\r\n<meta property=\"og:locale\" content=\"en_US\" \/>\r\n<meta property=\"og:type\" content=\"article\" \/>\r\n<meta property=\"og:title\" content=\"MonoGame Pipeline Extensions with .NET 7 - omni&#039;s hackpad\" \/>\r\n<meta property=\"og:description\" content=\".NET 7 just came out, but pipeline extensions targeting this version don&#039;t work out of the box. Until there&#039;s an update, here&#039;s a workaround.\" \/>\r\n<meta property=\"og:url\" content=\"https:\/\/badecho.com\/index.php\/2022\/11\/15\/monogame-pipeline-net7\/\" \/>\r\n<meta property=\"og:site_name\" content=\"omni&#039;s hackpad\" \/>\r\n<meta property=\"article:published_time\" content=\"2022-11-16T01:15:32+00:00\" \/>\r\n<meta property=\"article:modified_time\" content=\"2023-02-21T01:38:16+00:00\" \/>\r\n<meta property=\"og:image\" content=\"https:\/\/badecho.com\/wp-content\/uploads\/2022\/11\/PipelineExtensionsWith7.png\" \/>\r\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/badecho.com\/#website\",\"url\":\"https:\/\/badecho.com\/\",\"name\":\"omni&#039;s hackpad\",\"description\":\"Game Code Disassembly. Omnified Modification. Madness.\",\"publisher\":{\"@id\":\"https:\/\/badecho.com\/#\/schema\/person\/3de67496328be7ae6e1f52faf582e9d2\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/badecho.com\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/badecho.com\/index.php\/2022\/11\/15\/monogame-pipeline-net7\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/badecho.com\/wp-content\/uploads\/2022\/11\/PipelineExtensionsWith7.png\",\"width\":856,\"height\":448,\"caption\":\"MonoGame Pipeline Extensions with .NET 7\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/badecho.com\/index.php\/2022\/11\/15\/monogame-pipeline-net7\/#webpage\",\"url\":\"https:\/\/badecho.com\/index.php\/2022\/11\/15\/monogame-pipeline-net7\/\",\"name\":\"MonoGame Pipeline Extensions with .NET 7 - omni&#039;s hackpad\",\"isPartOf\":{\"@id\":\"https:\/\/badecho.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/badecho.com\/index.php\/2022\/11\/15\/monogame-pipeline-net7\/#primaryimage\"},\"datePublished\":\"2022-11-16T01:15:32+00:00\",\"dateModified\":\"2023-02-21T01:38:16+00:00\",\"description\":\".NET 7 just came out, but pipeline extensions targeting this version don't work out of the box. Until there's an update, here's a workaround.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/badecho.com\/index.php\/2022\/11\/15\/monogame-pipeline-net7\/\"]}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/badecho.com\/index.php\/2022\/11\/15\/monogame-pipeline-net7\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/badecho.com\/index.php\/2022\/11\/15\/monogame-pipeline-net7\/#webpage\"},\"author\":{\"@id\":\"https:\/\/badecho.com\/#\/schema\/person\/3de67496328be7ae6e1f52faf582e9d2\"},\"headline\":\"MonoGame Pipeline Extensions with .NET 7\",\"datePublished\":\"2022-11-16T01:15:32+00:00\",\"dateModified\":\"2023-02-21T01:38:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/badecho.com\/index.php\/2022\/11\/15\/monogame-pipeline-net7\/#webpage\"},\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/badecho.com\/#\/schema\/person\/3de67496328be7ae6e1f52faf582e9d2\"},\"image\":{\"@id\":\"https:\/\/badecho.com\/index.php\/2022\/11\/15\/monogame-pipeline-net7\/#primaryimage\"},\"keywords\":\".NET,C#,MonoGame\",\"articleSection\":\"General Dev\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/badecho.com\/index.php\/2022\/11\/15\/monogame-pipeline-net7\/#respond\"]}]},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/badecho.com\/#\/schema\/person\/3de67496328be7ae6e1f52faf582e9d2\",\"name\":\"Matt Weber\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/badecho.com\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7e345ac2708b3a41c7bd70a4a0440d41?s=96&d=mm&r=g\",\"caption\":\"Matt Weber\"},\"logo\":{\"@id\":\"https:\/\/badecho.com\/#personlogo\"}}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/posts\/2533"}],"collection":[{"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/comments?post=2533"}],"version-history":[{"count":17,"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/posts\/2533\/revisions"}],"predecessor-version":[{"id":2657,"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/posts\/2533\/revisions\/2657"}],"wp:attachment":[{"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/media?parent=2533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/categories?post=2533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/tags?post=2533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}