{"id":5484,"date":"2018-06-17T13:00:46","date_gmt":"2018-06-17T13:00:46","guid":{"rendered":"http:\/\/writeasync.net\/?p=5484"},"modified":"2018-06-16T16:52:18","modified_gmt":"2018-06-16T16:52:18","slug":"binary-implosion-use-the-source","status":"publish","type":"post","link":"http:\/\/writeasync.net\/?p=5484","title":{"rendered":"Binary implosion: use the source!"},"content":{"rendered":"<p>As I&#8217;ve written previously, we seem to have a real problem with <a href=\"http:\/\/writeasync.net\/?p=3201\">binary explosion<\/a> and we would do well with some techniques to curtail it (such as a <a href=\"http:\/\/writeasync.net\/?p=5478\">monolithic core<\/a> design). Today I want to talk about another definitely-not-new practice to stem binary sprawl &#8212; consuming source code instead! It may sound trivially obvious but I rarely see it in the .NET world. Here are three ways for you to share functionality via code files instead of binaries.<\/p>\n<h2>Code generators<\/h2>\n<p>Anyone who has used Visual Studio project templates should be hip to code generators. Think of all the boilerplate code that you get for free in &#8220;<a href=\"https:\/\/support.microsoft.com\/en-us\/help\/312311\/how-to-work-with-code-behind-class-files-in-an-asp-net-application-by\">code-behind<\/a>&#8221; or hidden within partial classes for frameworks like <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/framework\/wpf\/getting-started\/introduction-to-wpf-in-vs\">WPF<\/a>, <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/framework\/winforms\/\">WinForms<\/a>, <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/framework\/wcf\/whats-wcf\">WCF<\/a>, and so on. What is less common in my experience is for teams to build and use their own code generators. With technologies like <a href=\"https:\/\/github.com\/dotnet\/roslyn\">Roslyn<\/a>, it is easier than ever to get started with code manipulation tools.<\/p>\n<h2>Linked source files<\/h2>\n<p>Even easier than generating code is just including pre-canned code files. In a .csproj file, you can do this by adding a <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/msbuild\/common-msbuild-project-items#compile\">Link metadata item within a Compile item<\/a>. This is very commonly used for <a href=\"https:\/\/stackoverflow.com\/questions\/6771694\/shared-assemblyinfo-for-uniform-versioning-across-the-solution\">shared AssemblyInfo.cs files<\/a>, but can work for any bit of code that you want to share across a set of projects in the scope of a solution or repository.<\/p>\n<h2>NuGet source packages<\/h2>\n<p>Surprisingly I was not even aware that source-only NuGet packages existed until quite recently. A source-only package is a good solution when you need to more broadly publish\/consume a dependency and gain all the proper versioning benefits you get with a package manager. <a href=\"https:\/\/twitter.com\/kzu\">Daniel Cazzulino<\/a> (you may know him as the creator of <a href=\"https:\/\/github.com\/Moq\">Moq<\/a>) has a pretty good tutorial in his blog post <a href=\"http:\/\/blogs.clariusconsulting.net\/kzu\/how-to-create-lightweight-reusable-source-code-with-nuget\/\">&#8220;How to create lightweight reusable source code with NuGet.&#8221;<\/a> See also <a href=\"https:\/\/nikcodes.com\/\">Nik Molnar<\/a>&#8216;s post <a href=\"https:\/\/nikcodes.com\/2013\/10\/23\/packaging-source-code-with-nuget\/\">&#8220;Packaging Source Code With NuGet.&#8221;<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I&#8217;ve written previously, we seem to have a real problem with binary explosion and we would do well with some techniques to curtail it (such as a monolithic core design). Today I want to talk about another definitely-not-new practice&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[91],"tags":[],"class_list":["post-5484","post","type-post","status-publish","format-standard","hentry","category-design"],"_links":{"self":[{"href":"http:\/\/writeasync.net\/index.php?rest_route=\/wp\/v2\/posts\/5484","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/writeasync.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/writeasync.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/writeasync.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/writeasync.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5484"}],"version-history":[{"count":1,"href":"http:\/\/writeasync.net\/index.php?rest_route=\/wp\/v2\/posts\/5484\/revisions"}],"predecessor-version":[{"id":5485,"href":"http:\/\/writeasync.net\/index.php?rest_route=\/wp\/v2\/posts\/5484\/revisions\/5485"}],"wp:attachment":[{"href":"http:\/\/writeasync.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/writeasync.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5484"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/writeasync.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}