
{"id":4810,"date":"2022-12-04T00:40:33","date_gmt":"2022-12-04T05:40:33","guid":{"rendered":"https:\/\/ikriv.com\/blog\/?p=4810"},"modified":"2022-12-04T00:56:11","modified_gmt":"2022-12-04T05:56:11","slug":"compiling-stand-alone-file-in-classic-net-vs-dotnet-core","status":"publish","type":"post","link":"https:\/\/ikriv.com\/blog\/?p=4810","title":{"rendered":"Compiling stand-alone file in classic .NET vs Dotnet core"},"content":{"rendered":"<p>I realized that compiling a single-file program became much more complicated in Dotnet core compared to regular .NET.<\/p>\n<p>For starters, here&#8217;s how you run a Python file: <code>python foo.py<\/code><\/p>\n<p>Here&#8217;s how you used to run a C# file in .NET 4:<\/p>\n<pre>C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\csc.exe foo.cs\r\nfoo.exe<\/pre>\n<p>This is a little bit longer than with Python, but also fine. The only problem was to figure out the Framework version.<\/p>\n<p>Dotnet core brings several problems:<\/p>\n<ul>\n<li>You must specify all reference assemblies, even standard ones<\/li>\n<li>The file produced is not directly executable, you must use <code>dotnet foo.exe<\/code><\/li>\n<li>Even that does not work until you manually create a file named <code>foo.runtimeconfig.json<\/code>. The compiler cannot help with that.<\/li>\n<\/ul>\n<pre>set DOTNET_CLI_TELEMETRY_OPTOUT=1\r\nset LIB_PATH=C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\6.0.11\r\nset LIBS=\"-r:%LIB_PATH%\\System.Private.CoreLib.dll\" \"-r:%LIB_PATH%\\System.Console.dll\" \"-r:%LIB_PATH%\\System.Runtime.dll\" \"-r:%LIB_PATH%\\System.Text.RegularExpressions.dll\" \"-r:%LIB_PATH%\\System.Linq.dll\"\r\ndotnet \"C:\\Program Files\\dotnet\\sdk\\2.0.0\\Roslyn\\csc.exe\" -nologo %LIBS% foo.cs\r\ndotnet foo.exe<\/pre>\n<p>foo.runtimeconfig.json:<\/p>\n<pre>{\r\n  \"runtimeOptions\": {\r\n    \"framework\": {\r\n      \"name\": \"Microsoft.NETCore.App\",\r\n      \"version\": \"6.0.0\"\r\n    }\r\n  }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I realized that compiling a single-file program became much more complicated in Dotnet core compared to regular .NET. For starters, here&#8217;s how you run a Python file: python foo.py Here&#8217;s <a href=\"https:\/\/ikriv.com\/blog\/?p=4810\" class=\"more-link\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[3,4,1],"tags":[],"class_list":["entry","author-ikriv","post-4810","post","type-post","status-publish","format-standard","category-dotnet","category-hack","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4810"}],"version-history":[{"count":4,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4810\/revisions"}],"predecessor-version":[{"id":4814,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4810\/revisions\/4814"}],"wp:attachment":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}