<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aptivi</title>
    <description>The latest articles on DEV Community by Aptivi (@aptivi).</description>
    <link>https://dev.to/aptivi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F872874%2F816bb858-4d44-4a15-bf70-21c4c42a898e.png</url>
      <title>DEV Community: Aptivi</title>
      <link>https://dev.to/aptivi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aptivi"/>
    <language>en</language>
    <item>
      <title>Coloring console text easily with Terminaux</title>
      <dc:creator>Aptivi</dc:creator>
      <pubDate>Sat, 16 Dec 2023 10:51:36 +0000</pubDate>
      <link>https://dev.to/aptivi/coloring-console-text-easily-with-terminaux-1a4</link>
      <guid>https://dev.to/aptivi/coloring-console-text-easily-with-terminaux-1a4</guid>
      <description>&lt;p&gt;&lt;strong&gt;Updated for Terminaux 2.1.0&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Terminaux is a C# library that allows you to give your terminal applications a great makeover using its powerful features. It allows you to color your console text, easily create pane-based interactive applications, make your interactive applications resizable, perform basic console graphics, and more.&lt;/p&gt;

&lt;p&gt;You can install Terminaux to your project by following the instructions on &lt;a href="https://www.nuget.org/packages/Terminaux/" rel="noopener noreferrer"&gt;this NuGet page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This article talks about how to colorfully print your text to the console in an easy way. This article assumes that you have installed .NET 8.0 SDK to your machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making a console project
&lt;/h2&gt;

&lt;p&gt;To make a console project, make a directory that will hold your project files. For example, we're going to name our project &lt;code&gt;Colorful&lt;/code&gt;. Make a directory called &lt;code&gt;Colorful&lt;/code&gt; and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;dotnet new console &lt;span class="nt"&gt;--use-program-main&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, open the &lt;code&gt;Colorful.csproj&lt;/code&gt; file using your favorite text editor and add the following lines to install Terminaux to the project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;ItemGroup&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;PackageReference&lt;/span&gt; &lt;span class="na"&gt;Include=&lt;/span&gt;&lt;span class="s"&gt;"Terminaux"&lt;/span&gt; &lt;span class="na"&gt;Version=&lt;/span&gt;&lt;span class="s"&gt;"2.1.0"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ItemGroup&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the text file and run the following command to install Terminaux to the project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;dotnet restore
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once this is done, open your &lt;code&gt;Program.cs&lt;/code&gt; file and remove the line that says &lt;code&gt;Console.WriteLine("Hello, World!");&lt;/code&gt; so that your program code becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;Colorful&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Program&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Coloring text
&lt;/h2&gt;

&lt;p&gt;This section assumes that your console supports the VT sequences needed to print colors higher than 16 colors. If your console doesn't support that, you'll not get colored text.&lt;/p&gt;

&lt;p&gt;Make sure that you manually reset the colors using &lt;code&gt;ConsoleExtensions.ResetColor()&lt;/code&gt; from &lt;code&gt;Terminaux.Base&lt;/code&gt;, or the color will leak after exiting the app, just like shown in the screenshots.&lt;/p&gt;

&lt;p&gt;Now, suppose that you want to use the green color from the pre-defined &lt;code&gt;ConsoleColors&lt;/code&gt; enumeration to print &lt;code&gt;Hello World!&lt;/code&gt; to the console. You'll have to use the &lt;code&gt;WriteColor()&lt;/code&gt; function from the &lt;code&gt;TextWriterColor&lt;/code&gt; class to be able to write text with color. You can use one of the following function overloads sorted from simplest to most complex:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;WriteColor(string Text, ConsoleColors color, params object[] vars)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;WriteColor(string Text, bool Line, ConsoleColors color, params object[] vars)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;WriteColor(string Text, bool Line, bool Highlight, ConsoleColors color, params object[] vars)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Writing with green color
&lt;/h3&gt;

&lt;p&gt;To write the above text with the green color, you'll need to use the first function variant, which works for most situations. Place the following usings at the top of the source code file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Terminaux.Writer.ConsoleWriters&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Terminaux.Colors&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, place the following statement inside the &lt;code&gt;Main()&lt;/code&gt; function body to do the action by calling the &lt;code&gt;WriteColor()&lt;/code&gt; function like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Terminaux.Writer.ConsoleWriters&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Terminaux.Colors&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;Colorful&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Program&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;TextWriterColor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello World!"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ConsoleColors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Green&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you're done, save the source file and run &lt;code&gt;dotnet build&lt;/code&gt;. Upon finishing the build, run the application using either &lt;code&gt;dotnet run Colorful.csproj&lt;/code&gt; or &lt;code&gt;dotnet path/to/Colorful.dll&lt;/code&gt;, and you should see the &lt;code&gt;Hello World&lt;/code&gt; text in green as shown in the screenshot:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyyj019ily1e99emxf4ab.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyyj019ily1e99emxf4ab.png" alt="Hello World in Green" width="791" height="429"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The next section talks about how to write two parts of a text in a single line using different colors.&lt;/p&gt;

&lt;h3&gt;
  
  
  Writing two parts of text
&lt;/h3&gt;

&lt;p&gt;Let's assume that you want "Hello" in green and "World" in light blue. To do this, change the first call to the &lt;code&gt;WriteColor()&lt;/code&gt; function so that it prints just "Hello" instead in one line without advancing to the new line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;TextWriterColor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ConsoleColors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Green&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Afterwards, add the second call to the same function, but, this time, make it print "World" in light blue and make it advance to the new line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;TextWriterColor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;" World!"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ConsoleColors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SkyBlue1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you're done, save the changes and run &lt;code&gt;dotnet build&lt;/code&gt; and &lt;code&gt;dotnet run&lt;/code&gt; again. Afterwards, you should see "Hello" in green and "World" in light blue.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa0l1l8v2r1djh7fqr18z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa0l1l8v2r1djh7fqr18z.png" alt="Hello World!" width="792" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Writing text in true color
&lt;/h3&gt;

&lt;p&gt;This is when the power of Terminaux's console writer lies in! You can also write text easily in true color! Terminaux provides you several ways to write text in true color, but let's focus on the simplest way to do this.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;WriteColor(string Text, Color color, params object[] vars)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;WriteColor(string Text, bool Line, Color color, params object[] vars)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;WriteColor(string Text, bool Line, bool Highlight, Color color, params object[] vars)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Assuming that your &lt;code&gt;Program.cs&lt;/code&gt; file is empty, let's assume that you want to print "Terminaux is Awesome" in pastel green (&lt;code&gt;#A5D687&lt;/code&gt;). You can use the hex representation of a color, the color name, the RGB specifier in the format of &lt;code&gt;RRR;GGG;BBB&lt;/code&gt;, and more.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;TextWriterColor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Terminaux is Awesome!"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"#A5D687"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From &lt;a href="https://aptivi.gitbook.io/terminaux-manual/usage/color-sequences#building-a-color-instance" rel="noopener noreferrer"&gt;Terminaux's documentation&lt;/a&gt;, you can use the following modes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;num&amp;gt;&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;num&amp;gt;&lt;/code&gt; should be of the range between 0 and 255&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;&amp;lt;rrr&amp;gt;;&amp;lt;ggg&amp;gt;;&amp;lt;bbb&amp;gt;&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;rrr&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;ggg&amp;gt;&lt;/code&gt;, and &lt;code&gt;&amp;lt;bbb&amp;gt;&lt;/code&gt; should be of the range between 0 and 255&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;cmyk:&amp;lt;ccc&amp;gt;;&amp;lt;mmm&amp;gt;;&amp;lt;yyy&amp;gt;;&amp;lt;kkk&amp;gt;&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;ccc&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;mmm&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;yyy&amp;gt;&lt;/code&gt;, and &lt;code&gt;&amp;lt;kkk&amp;gt;&lt;/code&gt; should be of the range between 0 and 100&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;cmy:&amp;lt;ccc&amp;gt;;&amp;lt;mmm&amp;gt;;&amp;lt;yyy&amp;gt;&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;ccc&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;mmm&amp;gt;&lt;/code&gt;, and &lt;code&gt;&amp;lt;yyy&amp;gt;&lt;/code&gt; should be of the range between 0 and 100&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;hsl:&amp;lt;hhh&amp;gt;;&amp;lt;sss&amp;gt;;&amp;lt;lll&amp;gt;&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;hhh&amp;gt;&lt;/code&gt; should be of the range between 0 and 360 in degrees and not radians&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;sss&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;lll&amp;gt;&lt;/code&gt; should be of the range between 0 and 100&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;hsv:&amp;lt;hhh&amp;gt;;&amp;lt;sss&amp;gt;;&amp;lt;vvv&amp;gt;&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;hhh&amp;gt;&lt;/code&gt; should be of the range between 0 and 360 in degrees and not radians&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;sss&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;vvv&amp;gt;&lt;/code&gt; should be of the range between 0 and 100&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;ryb:&amp;lt;rrr&amp;gt;;&amp;lt;yyy&amp;gt;;&amp;lt;bbb&amp;gt;&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;rrr&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;yyy&amp;gt;&lt;/code&gt;, and &lt;code&gt;&amp;lt;bbb&amp;gt;&lt;/code&gt; should be of the range between 0 and 255, just like RGB.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;#000000&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;Hexadecimal representation of the color for HTML fans. You can also use the &lt;code&gt;#RGB&lt;/code&gt; format, implying that the three digits represent:&lt;/li&gt;
&lt;li&gt;R: Red color level converted to RR (F becomes FF)&lt;/li&gt;
&lt;li&gt;G: Green color level converted to GG (F becomes FF)&lt;/li&gt;
&lt;li&gt;B: Blue color level converted to BB (F becomes FF)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;&amp;lt;ColorName&amp;gt;&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;Color name from &lt;code&gt;ConsoleColors&lt;/code&gt; enumeration&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Once you're done, save the changes and run &lt;code&gt;dotnet build&lt;/code&gt; and &lt;code&gt;dotnet run&lt;/code&gt; again. Afterwards, you should see "Terminaux is Awesome" in pastel green.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3zk09vnnim1d4ra3p8q6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3zk09vnnim1d4ra3p8q6.png" alt="Terminaux is Awesome" width="800" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Your experiments
&lt;/h2&gt;

&lt;p&gt;We'll come back with more Terminaux tips and tricks. Stay tuned!&lt;/p&gt;

&lt;p&gt;Now, it's your turn to show us your awesome text made with Terminaux. Show your results in the comments section of this article!&lt;/p&gt;

&lt;p&gt;Enjoy hacking!&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Rebuild All currently doesn't work properly</title>
      <dc:creator>Aptivi</dc:creator>
      <pubDate>Sat, 25 Nov 2023 06:50:32 +0000</pubDate>
      <link>https://dev.to/aptivi/rebuild-all-currently-doesnt-work-properly-52l6</link>
      <guid>https://dev.to/aptivi/rebuild-all-currently-doesnt-work-properly-52l6</guid>
      <description>&lt;p&gt;For the modern .NET projects, you’ll notice that if you alter a file that is to be included in the resources and rebuild the entire solution using the Rebuild All button, you’ll notice that you can’t run the application properly, because you’ll see an interesting error message printed to the console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Program Files\dotnet\'.
Failed to run as a self-contained app.
  - The application was run as a self-contained app because 'E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Nitrocid.runtimeconfig.json' was not found.
  - If this should be a framework-dependent app, add the 'E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Nitrocid.runtimeconfig.json' file and specify the appropriate framework.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, you’ll notice another message in the Output pane:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;According to the build output, you’ll see something like this when trying to “Rebuild All,” which appears to work properly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Rebuild started at 5:50 PM...
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.LanguagePacks\Nitrocid.LanguagePacks.csproj (in 18 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.ScreensaverPacks\Nitrocid.ScreensaverPacks.csproj (in 24 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.SftpShell\Nitrocid.Extras.SftpShell.csproj (in 5 ms).
Restored E:\Source\Public\NitrocidKS\private\Nitrocid.Tests\Nitrocid.Tests.csproj (in 29 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.InternetRadioInfo\Nitrocid.Extras.InternetRadioInfo.csproj (in 33 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.NameGen\Nitrocid.Extras.NameGen.csproj (in 4 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.LanguageStudio\Nitrocid.Extras.LanguageStudio.csproj (in 3 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.Tips\Nitrocid.Extras.Tips.csproj (in 39 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.JsonShell\Nitrocid.Extras.JsonShell.csproj (in 2 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.ThemePacks\Nitrocid.ThemePacks.csproj (in 44 ms).
Restored E:\Source\Public\NitrocidKS\private\Nitrocid.LocaleCheck\Nitrocid.LocaleCheck.csproj (in 2 ms).
Restored E:\Source\Public\NitrocidKS\private\Nitrocid.LocaleClean\Nitrocid.LocaleClean.csproj (in 3 ms).
Restored E:\Source\Public\NitrocidKS\private\Nitrocid.LocaleTools\Nitrocid.LocaleTools.csproj (in 7 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.ToDoList\Nitrocid.Extras.ToDoList.csproj (in 49 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.LocaleGen\Nitrocid.LocaleGen.csproj (in 2 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.LocaleGen.Core\Nitrocid.LocaleGen.Core.csproj (in 2 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.MailShell\Nitrocid.Extras.MailShell.csproj (in 22 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.ArchiveShell\Nitrocid.Extras.ArchiveShell.csproj (in 58 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.Forecast\Nitrocid.Extras.Forecast.csproj (in 4 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.UnitConv\Nitrocid.Extras.UnitConv.csproj (in 68 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.SplashPacks\Nitrocid.SplashPacks.csproj (in 77 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.Dictionary\Nitrocid.Extras.Dictionary.csproj (in 3 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Analyzers\Nitrocid.Analyzers\Nitrocid.Analyzers.csproj (in 25 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.ColorConvert\Nitrocid.Extras.ColorConvert.csproj (in 1 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.Contacts\Nitrocid.Extras.Contacts.csproj (in 9 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.Calendar\Nitrocid.Extras.Calendar.csproj (in 2 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Analyzers\Nitrocid.Analyzers.CodeFixes\Nitrocid.Analyzers.CodeFixes.csproj (in 26 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Analyzers\Nitrocid.Analyzers.Package\Nitrocid.Analyzers.Package.csproj (in 32 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.FtpShell\Nitrocid.Extras.FtpShell.csproj (in 1 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.Calculators\Nitrocid.Extras.Calculators.csproj (in 6 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.HttpShell\Nitrocid.Extras.HttpShell.csproj (in 3 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.ChatGpt\Nitrocid.Extras.ChatGpt.csproj (in 37 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.GitShell\Nitrocid.Extras.GitShell.csproj (in 5 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.Caffeine\Nitrocid.Extras.Caffeine.csproj (in 6 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.BassBoom\Nitrocid.Extras.BassBoom.csproj (in 91 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.TimeInfo\Nitrocid.Extras.TimeInfo.csproj (in 2 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Analyzers\Nitrocid.StandaloneAnalyzer\Nitrocid.StandaloneAnalyzer.csproj (in 50 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Analyzers\Nitrocid.Analyzers.Vsix\Nitrocid.Analyzers.Vsix.csproj (in 45 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.ThemeStudio\Nitrocid.Extras.ThemeStudio.csproj (in 2 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.RetroKS\Nitrocid.Extras.RetroKS.csproj (in 2 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.RssShell\Nitrocid.Extras.RssShell.csproj (in 5 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.SqlShell\Nitrocid.Extras.SqlShell.csproj (in 3 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.Notes\Nitrocid.Extras.Notes.csproj (in 2 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.Amusements\Nitrocid.Extras.Amusements.csproj (in 108 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid\Nitrocid.csproj (in 66 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Legacy.InxiNet\Nitrocid.Legacy.InxiNet.csproj (in 10 ms).
Restored E:\Source\Public\NitrocidKS\public\Nitrocid.Addons\Nitrocid.Extras.Timers\Nitrocid.Extras.Timers.csproj (in 2 ms).
Restored E:\Source\Public\NitrocidKS\private\Nitrocid.Analyzers.Test\Nitrocid.Analyzers.Test.csproj (in 314 ms).
------ Rebuild All started: Project: Nitrocid.LocaleTools, Configuration: Debug Any CPU ------
Nitrocid.LocaleTools -&amp;gt; E:\Source\Public\NitrocidKS\private\Nitrocid.LocaleTools\bin\Debug\netstandard2.0\Nitrocid.LocaleTools.dll
------ Rebuild All started: Project: Nitrocid.LocaleCheck, Configuration: Debug Any CPU ------
Nitrocid.LocaleCheck -&amp;gt; E:\Source\Public\NitrocidKS\private\Nitrocid.LocaleCheck\bin\Debug\net8.0\Nitrocid.LocaleCheck.dll
------ Rebuild All started: Project: Nitrocid.LocaleClean, Configuration: Debug Any CPU ------
Nitrocid.LocaleClean -&amp;gt; E:\Source\Public\NitrocidKS\private\Nitrocid.LocaleClean\bin\Debug\net8.0\Nitrocid.LocaleClean.dll
------ Rebuild All started: Project: Nitrocid.StandaloneAnalyzer, Configuration: Debug Any CPU ------
Nitrocid.StandaloneAnalyzer -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSAnalyzer\net8.0\Nitrocid.StandaloneAnalyzer.dll
------ Rebuild All started: Project: Nitrocid.Analyzers, Configuration: Debug Any CPU ------
Nitrocid.Analyzers -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSAnalyzer\netstandard2.0\Nitrocid.Analyzers.dll
------ Rebuild All started: Project: Nitrocid.Analyzers.CodeFixes, Configuration: Debug Any CPU ------
Nitrocid.Analyzers.CodeFixes -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSAnalyzer\netstandard2.0\Nitrocid.Analyzers.CodeFixes.dll
------ Rebuild All started: Project: Nitrocid.Analyzers.Vsix, Configuration: Debug Any CPU ------
Nitrocid.Analyzers.Vsix -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSAnalyzer\net8.0\Nitrocid.Analyzers.Vsix.vsix
------ Rebuild All started: Project: Nitrocid.Analyzers.Test, Configuration: Debug Any CPU ------
Nitrocid.Analyzers.Test -&amp;gt; E:\Source\Public\NitrocidKS\private\Nitrocid.Analyzers.Test\bin\Debug\net8.0\Nitrocid.Analyzers.Test.dll
------ Rebuild All started: Project: Nitrocid.Analyzers.Package, Configuration: Debug Any CPU ------
Nitrocid.Analyzers.Package -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSAnalyzer\netstandard2.0\Nitrocid.Analyzers.Package.dll
Successfully created package 'E:\Source\Public\NitrocidKS\public\Nitrocid\KSAnalyzer\Nitrocid.Analyzers.0.1.0-beta2.nupkg'.
Successfully created package 'E:\Source\Public\NitrocidKS\public\Nitrocid\KSAnalyzer\Nitrocid.Analyzers.0.1.0-beta2.symbols.nupkg'.
------ Rebuild All started: Project: Nitrocid.LocaleGen.Core, Configuration: Debug Any CPU ------
Nitrocid.LocaleGen.Core -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Nitrocid.LocaleGen.Core.dll
Successfully created package 'E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\Nitrocid.LocaleGen.Core.0.1.0-beta2.nupkg'.
Successfully created package 'E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\Nitrocid.LocaleGen.Core.0.1.0-beta2.symbols.nupkg'.
------ Rebuild All started: Project: Nitrocid, Configuration: Debug Any CPU ------
Nitrocid -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Nitrocid.dll
Successfully created package 'E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\KS.0.1.0-beta2.nupkg'.
Successfully created package 'E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\KS.0.1.0-beta2.symbols.nupkg'.
------ Rebuild All started: Project: Nitrocid.Extras.JsonShell, Configuration: Debug Any CPU ------
Nitrocid.Extras.JsonShell -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.JsonShell\Nitrocid.Extras.JsonShell.dll
------ Rebuild All started: Project: Nitrocid.Extras.SqlShell, Configuration: Debug Any CPU ------
Nitrocid.Extras.SqlShell -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.SqlShell\Nitrocid.Extras.SqlShell.dll
------ Rebuild All started: Project: Nitrocid.Legacy.InxiNet, Configuration: Debug Any CPU ------
Nitrocid.Legacy.InxiNet -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Legacy.InxiNet\Nitrocid.Legacy.InxiNet.dll
------ Rebuild All started: Project: Nitrocid.Extras.ChatGpt, Configuration: Debug Any CPU ------
Nitrocid.Extras.ChatGpt -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.ChatGpt\Nitrocid.Extras.ChatGpt.dll
------ Rebuild All started: Project: Nitrocid.Extras.RssShell, Configuration: Debug Any CPU ------
Nitrocid.Extras.RssShell -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.RssShell\Nitrocid.Extras.RssShell.dll
------ Rebuild All started: Project: Nitrocid.Extras.SftpShell, Configuration: Debug Any CPU ------
Nitrocid.Extras.SftpShell -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.SftpShell\Nitrocid.Extras.SftpShell.dll
------ Rebuild All started: Project: Nitrocid.Extras.MailShell, Configuration: Debug Any CPU ------
Nitrocid.Extras.MailShell -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.MailShell\Nitrocid.Extras.MailShell.dll
------ Rebuild All started: Project: Nitrocid.Extras.HttpShell, Configuration: Debug Any CPU ------
Nitrocid.Extras.HttpShell -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.HttpShell\Nitrocid.Extras.HttpShell.dll
------ Rebuild All started: Project: Nitrocid.Extras.FtpShell, Configuration: Debug Any CPU ------
Nitrocid.Extras.FtpShell -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.FtpShell\Nitrocid.Extras.FtpShell.dll
------ Rebuild All started: Project: Nitrocid.Extras.Caffeine, Configuration: Debug Any CPU ------
Nitrocid.Extras.Caffeine -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.Caffeine\Nitrocid.Extras.Caffeine.dll
------ Rebuild All started: Project: Nitrocid.Extras.RetroKS, Configuration: Debug Any CPU ------
Nitrocid.Extras.RetroKS -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.RetroKS\Nitrocid.Extras.RetroKS.dll
------ Rebuild All started: Project: Nitrocid.Extras.InternetRadioInfo, Configuration: Debug Any CPU ------
Nitrocid.Extras.InternetRadioInfo -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.InternetRadioInfo\Nitrocid.Extras.InternetRadioInfo.dll
------ Rebuild All started: Project: Nitrocid.Extras.TimeInfo, Configuration: Debug Any CPU ------
Nitrocid.Extras.TimeInfo -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.TimeInfo\Nitrocid.Extras.TimeInfo.dll
------ Rebuild All started: Project: Nitrocid.Extras.ColorConvert, Configuration: Debug Any CPU ------
Nitrocid.Extras.ColorConvert -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.ColorConvert\Nitrocid.Extras.ColorConvert.dll
------ Rebuild All started: Project: Nitrocid.Extras.LanguageStudio, Configuration: Debug Any CPU ------
Nitrocid.Extras.LanguageStudio -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.LanguageStudio\Nitrocid.Extras.LanguageStudio.dll
------ Rebuild All started: Project: Nitrocid.Extras.ThemeStudio, Configuration: Debug Any CPU ------
Nitrocid.Extras.ThemeStudio -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.ThemeStudio\Nitrocid.Extras.ThemeStudio.dll
------ Rebuild All started: Project: Nitrocid.SplashPacks, Configuration: Debug Any CPU ------
Nitrocid.SplashPacks -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\SplashPacks\Nitrocid.SplashPacks.dll
------ Rebuild All started: Project: Nitrocid.ScreensaverPacks, Configuration: Debug Any CPU ------
Nitrocid.ScreensaverPacks -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\ScreensaverPacks\Nitrocid.ScreensaverPacks.dll
------ Rebuild All started: Project: Nitrocid.Extras.Calculators, Configuration: Debug Any CPU ------
Nitrocid.Extras.Calculators -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.Calculators\Nitrocid.Extras.Calculators.dll
------ Rebuild All started: Project: Nitrocid.Extras.BassBoom, Configuration: Debug Any CPU ------
Nitrocid.Extras.BassBoom -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.BassBoom\Nitrocid.Extras.BassBoom.dll
Nitrocid.Extras.BassBoom -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.BassBoom.Windows\Nitrocid.Extras.BassBoom.dll
------ Rebuild All started: Project: Nitrocid.Extras.UnitConv, Configuration: Debug Any CPU ------
Nitrocid.Extras.UnitConv -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.UnitConv\Nitrocid.Extras.UnitConv.dll
------ Rebuild All started: Project: Nitrocid.Extras.NameGen, Configuration: Debug Any CPU ------
Nitrocid.Extras.NameGen -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.NameGen\Nitrocid.Extras.NameGen.dll
------ Rebuild All started: Project: Nitrocid.Extras.Dictionary, Configuration: Debug Any CPU ------
Nitrocid.Extras.Dictionary -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.Dictionary\Nitrocid.Extras.Dictionary.dll
------ Rebuild All started: Project: Nitrocid.Extras.Timers, Configuration: Debug Any CPU ------
Nitrocid.Extras.Timers -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.Timers\Nitrocid.Extras.Timers.dll
------ Rebuild All started: Project: Nitrocid.Extras.ToDoList, Configuration: Debug Any CPU ------
Nitrocid.Extras.ToDoList -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.ToDoList\Nitrocid.Extras.ToDoList.dll
------ Rebuild All started: Project: Nitrocid.Extras.Forecast, Configuration: Debug Any CPU ------
Nitrocid.Extras.Forecast -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.Forecast\Nitrocid.Extras.Forecast.dll
------ Rebuild All started: Project: Nitrocid.Extras.Contacts, Configuration: Debug Any CPU ------
Nitrocid.Extras.Contacts -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.Contacts\Nitrocid.Extras.Contacts.dll
------ Rebuild All started: Project: Nitrocid.Extras.Calendar, Configuration: Debug Any CPU ------
Nitrocid.Extras.Calendar -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.Calendar\Nitrocid.Extras.Calendar.dll
------ Rebuild All started: Project: Nitrocid.Extras.ArchiveShell, Configuration: Debug Any CPU ------
Nitrocid.Extras.ArchiveShell -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.ArchiveShell\Nitrocid.Extras.ArchiveShell.dll
------ Rebuild All started: Project: Nitrocid.Extras.Amusements, Configuration: Debug Any CPU ------
Nitrocid.Extras.Amusements -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.Amusements\Nitrocid.Extras.Amusements.dll
------ Rebuild All started: Project: Nitrocid.Extras.GitShell, Configuration: Debug Any CPU ------
Nitrocid.Extras.GitShell -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.GitShell\Nitrocid.Extras.GitShell.dll
------ Rebuild All started: Project: Nitrocid.Extras.Tips, Configuration: Debug Any CPU ------
Nitrocid.Extras.Tips -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.Tips\Nitrocid.Extras.Tips.dll
------ Rebuild All started: Project: Nitrocid.Extras.Notes, Configuration: Debug Any CPU ------
Nitrocid.Extras.Notes -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\Extras.Notes\Nitrocid.Extras.Notes.dll
------ Rebuild All started: Project: Nitrocid.LanguagePacks, Configuration: Debug Any CPU ------
Nitrocid.LanguagePacks -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\LanguagePacks\Nitrocid.LanguagePacks.dll
------ Rebuild All started: Project: Nitrocid.ThemePacks, Configuration: Debug Any CPU ------
Nitrocid.ThemePacks -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Addons\ThemePacks\Nitrocid.ThemePacks.dll
------ Rebuild All started: Project: Nitrocid.Tests, Configuration: Debug Any CPU ------
Nitrocid.Tests -&amp;gt; E:\Source\Public\NitrocidKS\private\Nitrocid.Tests\KSTest\net8.0\Nitrocid.Tests.dll
------ Rebuild All started: Project: Nitrocid.LocaleGen, Configuration: Debug Any CPU ------
Nitrocid.LocaleGen -&amp;gt; E:\Source\Public\NitrocidKS\public\Nitrocid\KSBuild\net8.0\Nitrocid.LocaleGen.dll
========== Rebuild All: 48 succeeded, 0 failed, 0 skipped ==========
========== Rebuild completed at 5:50 PM and took 31.047 seconds ==========
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To work around this problem, you’ll have to right-click on the solution and click on the Clean Solution button. Afterward, click on the Build Solution button to re-build the solution.&lt;/p&gt;

&lt;p&gt;When you click on the green Run button, you should no longer get this error message.&lt;/p&gt;

&lt;p&gt;This bug is tracked with &lt;a href="https://developercommunity.visualstudio.com/t/Rebuild-for-NET-80-doesnt-build-proje/10524624" rel="noopener noreferrer"&gt;this ticket&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>discuss</category>
      <category>csharp</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>.NET 8.0 LTS Released!</title>
      <dc:creator>Aptivi</dc:creator>
      <pubDate>Wed, 15 Nov 2023 04:28:33 +0000</pubDate>
      <link>https://dev.to/aptivi/net-80-lts-released-42jj</link>
      <guid>https://dev.to/aptivi/net-80-lts-released-42jj</guid>
      <description>&lt;p&gt;The fourth Long Term Support (LTS) release for the modern .NET framework, .NET 8.0 has just been released! This release features performance improvements across various areas, feature additions, and many changes that will improve your .NET development experience.&lt;/p&gt;

&lt;p&gt;To download this version of .NET, visit the below link by clicking on the links shown below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dotnet.microsoft.com/en-us/download/dotnet/8.0" rel="noopener noreferrer"&gt;Download&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://devblogs.microsoft.com/dotnet/announcing-dotnet-8/" rel="noopener noreferrer"&gt;Learn More&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/dotnet/core/tree/main/release-notes/8.0" rel="noopener noreferrer"&gt;Release Notes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are some of the changes introduced in this .NET version:&lt;/p&gt;

&lt;h2&gt;
  
  
  Built-in JSON improvements
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://learn.microsoft.com/en-us/dotnet/api/system.text.json?view=net-8.0" rel="noopener noreferrer"&gt;&lt;code&gt;System.Text.Json&lt;/code&gt;&lt;/a&gt; library has just accumulated some of the nice improvements and feature additions that will improve your experience with interacting with the JSON files and manipulating them.&lt;/p&gt;

&lt;p&gt;Learn more about the System.Text.Json improvements by clicking &lt;a href="https://devblogs.microsoft.com/dotnet/system-text-json-in-dotnet-8/" rel="noopener noreferrer"&gt;this link&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;required&lt;/code&gt; and &lt;code&gt;init&lt;/code&gt; members
&lt;/h3&gt;

&lt;p&gt;Starting from .NET 8.0, the &lt;code&gt;System.Text.Json&lt;/code&gt; library supports deserializing classes that contain properties that contain the required and the init modifiers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Combining source generators
&lt;/h3&gt;

&lt;p&gt;You can now combine two or more source generators to the &lt;code&gt;TypeInfoResolver&lt;/code&gt; property when populating the JSON serialization options starting from this version of .NET.&lt;/p&gt;

&lt;h3&gt;
  
  
  Compiler-generated types
&lt;/h3&gt;

&lt;p&gt;Compiler-generated types, or unspeakable types, are types that are automatically generated by the compiler for the lambda delegates. This library used to fail when trying to perform serialization operations on such types.&lt;/p&gt;

&lt;p&gt;However, this is changed because the .NET 8.0 version can now perform such operations on such types.&lt;/p&gt;

&lt;h3&gt;
  
  
  Disable Reflection-based Serialization
&lt;/h3&gt;

&lt;p&gt;In addition to the above changes, you can now disable the reflection-based serialization as a default when building your .NET 8.0 project that makes use of the JSON serialization operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ahead of Time (AOT) Improvements
&lt;/h2&gt;

&lt;p&gt;In addition to the big number of System.Text.Json changes, the .NET 8.0 framework witnessed several improvements regarding the native Ahead of Time (AOT) compilation.&lt;/p&gt;

&lt;p&gt;Your native AOT applications can now enjoy the smaller size footprint when building your application on the .NET 8.0 SDK versus the .NET 7.0 SDK.&lt;/p&gt;

&lt;p&gt;For example, in the &lt;a href="https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-8#native-aot-support" rel="noopener noreferrer"&gt;What’s New&lt;/a&gt; article, the team added support for AOT compilation for both the 64-bit macOS and the newer ARM64 macOS operating system. Not only that, but the overall reduction of the size is up to ~50%.&lt;/p&gt;

&lt;h2&gt;
  
  
  Download
&lt;/h2&gt;

&lt;p&gt;Get yourselves excited with the .NET 8.0 release! Download .NET 8.0 by going to the top of the page and clicking on Download to get started!&lt;/p&gt;

&lt;p&gt;Visual Studio 17.8 is shipped with built-in support for .NET 8.0 so that you can use this version of .NET with Visual Studio seamlessly.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>news</category>
      <category>csharp</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>UseShellExecute Process and StartInfo Debugging on .NET</title>
      <dc:creator>Aptivi</dc:creator>
      <pubDate>Fri, 03 Nov 2023 09:09:50 +0000</pubDate>
      <link>https://dev.to/aptivi/useshellexecute-process-and-startinfo-debugging-on-net-3508</link>
      <guid>https://dev.to/aptivi/useshellexecute-process-and-startinfo-debugging-on-net-3508</guid>
      <description>&lt;p&gt;Check the relevant issue ticket &lt;a href="https://github.com/dotnet/runtime/issues/94338" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We’ve recently run an investigation made internally that involves the Process class and its &lt;a href="https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.useshellexecute" rel="noopener noreferrer"&gt;UseShellExecute&lt;/a&gt; feature. This is an investigation about a pitfall when debugging the &lt;code&gt;StartInfo&lt;/code&gt; property of a process that is to be executed from the Process class with the &lt;code&gt;UseShellExecute&lt;/code&gt; feature enabled.&lt;/p&gt;

&lt;p&gt;Before going into the details of this investigation, we’ll explain a bit about what is &lt;code&gt;UseShellExecute&lt;/code&gt;. This property in the Process class describes whether the operating system shell (&lt;code&gt;ShellExecute&lt;/code&gt; in Windows) is to be used when executing processes or the operating system should create a process directly from the executable file. This is available for all platforms, despite the usage of the &lt;code&gt;ShellExecute&lt;/code&gt; name in the property.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Investigation
&lt;/h2&gt;

&lt;p&gt;We’re going straight to the investigation details and a case study about why debugging the &lt;code&gt;StartInfo&lt;/code&gt; property in &lt;code&gt;UseShellExecute&lt;/code&gt;-enabled process instances causes a confusing exception.&lt;/p&gt;

&lt;h3&gt;
  
  
  Symptoms
&lt;/h3&gt;

&lt;p&gt;This investigation is a case study about the above subject. Suppose that you have this block of code that defines a process class that re-executes your .NET 6.0 application with the &lt;code&gt;runas&lt;/code&gt; verb to execute it as an elevated user account.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;selfProcess&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Process&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;StartInfo&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ChangeExtension&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Assembly&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetExecutingAssembly&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;Location&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;".exe"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;UseShellExecute&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;Verb&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"runas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;Arguments&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;EnvironmentTools&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// Now, go ahead and start.&lt;/span&gt;
&lt;span class="n"&gt;selfProcess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Normally, you’d check that all the parameters work as expected, such as taking a look at the StartInfo property value by putting it to a watch when debugging your program.&lt;/p&gt;

&lt;p&gt;However, when you actually try to start the process after taking a look at that property and making sure that all the values are populated as expected, instead of your program executing the process, you’ll actually notice that your program throws an exception as seen in the below screenshot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz6pycq8w8kxk2pa77c5i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz6pycq8w8kxk2pa77c5i.png" alt="Exception thrown" width="523" height="196"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you can’t see the screenshot, here’s a text version of the exception:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;System.InvalidOperationException: The Process object must have the UseShellExecute property set to false in order to use environment variables.&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Investigation
&lt;/h3&gt;

&lt;p&gt;Our verification using the example POC app, which its source code is short, verifies that this exception only gets thrown on Windows systems. Linux systems are unaffected. Here’s the source code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;System.Diagnostics&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;poc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Program&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"POC of UseShellExecute pitfall"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;proc&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Process&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;StartInfo&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"C:/WINDOWS/System32/cmd.exe"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;UseShellExecute&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;Verb&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"runas"&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;
        &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;proc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StartInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;EnvironmentVariables&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;proc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Invocation of the &lt;a href="https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.environment" rel="noopener noreferrer"&gt;Environment&lt;/a&gt; or the &lt;a href="https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.environmentvariables" rel="noopener noreferrer"&gt;EnvironmentVariables&lt;/a&gt; property from the &lt;code&gt;StartInfo&lt;/code&gt; property causes the above exception, and Google searches won’t help pinpoint the problem.&lt;/p&gt;

&lt;p&gt;Further investigation of the .NET source code suggests that these properties are populated upon the first invocation of any of the two properties, as you can see here (taken from the .NET 8.0 source code):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;IDictionary&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;?&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Environment&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;get&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_environmentVariables&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;IDictionary&lt;/span&gt; &lt;span class="n"&gt;envVars&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Environment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetEnvironmentVariables&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

            &lt;span class="n"&gt;_environmentVariables&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;DictionaryWrapper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Dictionary&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;?&amp;gt;(&lt;/span&gt;
                &lt;span class="n"&gt;envVars&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;OperatingSystem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;IsWindows&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="n"&gt;StringComparer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OrdinalIgnoreCase&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;StringComparer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Ordinal&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

            &lt;span class="c1"&gt;// Manual use of IDictionaryEnumerator instead of foreach to avoid DictionaryEntry box allocations.&lt;/span&gt;
            &lt;span class="n"&gt;IDictionaryEnumerator&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;envVars&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetEnumerator&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="n"&gt;Debug&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;(!(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="n"&gt;IDisposable&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="s"&gt;"Environment.GetEnvironmentVariables should not be IDisposable."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MoveNext&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;DictionaryEntry&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Entry&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="n"&gt;_environmentVariables&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;?)&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;_environmentVariables&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;a href="https://source.dot.net/#System.Diagnostics.Process/System/Diagnostics/ProcessStartInfo.cs,308d8db8b1b66161" rel="noopener noreferrer"&gt;property getter&lt;/a&gt; doesn’t check the &lt;code&gt;UseShellExecute&lt;/code&gt; property before populating the environment variable, which causes the environment variable lists to be populated, which is inappropriate for process instances with &lt;code&gt;UseShellExecute&lt;/code&gt; enabled.&lt;/p&gt;

&lt;p&gt;In our opinion, only checking for &lt;code&gt;null&lt;/code&gt; in the &lt;code&gt;Environment&lt;/code&gt; property getter is insufficient. Furthermore, when &lt;a href="https://source.dot.net/#System.Diagnostics.Process/System/Diagnostics/Process.cs,e9edeff01b1851af" rel="noopener noreferrer"&gt;&lt;code&gt;Start()&lt;/code&gt;&lt;/a&gt; is called on the process after this property is populated, the abstraction of the Process class, depending on your platform, is called to call the platform-specific methods of process starting function.&lt;/p&gt;

&lt;p&gt;Investigating the &lt;a href="https://source.dot.net/#System.Diagnostics.Process/System/Diagnostics/Process.Unix.cs,2cbba2bbbfb82be9" rel="noopener noreferrer"&gt;Unix abstraction&lt;/a&gt; of the Process class, this piece of code snippet below only checks for redirection when ShellExecute is enabled.&lt;/p&gt;

&lt;p&gt;However, when it comes to the &lt;a href="https://github.com/dotnet/runtime/blob/release/8.0/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Win32.cs#L30" rel="noopener noreferrer"&gt;Windows abstraction&lt;/a&gt; of the Process class, the &lt;code&gt;StartCore&lt;/code&gt; checks to see if &lt;code&gt;ShellExecute&lt;/code&gt; is used. In our case, &lt;code&gt;StartWithShellExecuteEx()&lt;/code&gt; is called, and does the following checks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In line 32, if the username or the password is provided, the exception is thrown.&lt;/li&gt;
&lt;li&gt;In line 35, if any redirection is enabled, the exception is thrown.&lt;/li&gt;
&lt;li&gt;In line 38, line 41, and line 44, if you’re attempting to set the encoding to the process, the exception is thrown.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;In &lt;a href="https://github.com/dotnet/runtime/blob/7331dcb60e0fd7c74a6f7216d61819c9f57a1ade/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Win32.cs#L47" rel="noopener noreferrer"&gt;line 47&lt;/a&gt;, if the environment variable list is populated, intentionally (as in the POC) or not (as in StartInfo debugging), the exception is thrown.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Workaround
&lt;/h3&gt;

&lt;p&gt;There is no way to nullify the internal environment variable list as pinpointed in line 47 except using the dirty private reflection hack. However, this hack lasts until you try to access the environment variables property again. This is the reflection hack used to nullify this field (taken from the source code of Nitrocid KS 0.1.0):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;internal&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;ProcessStartInfo&lt;/span&gt; &lt;span class="nf"&gt;StripEnvironmentVariables&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ProcessStartInfo&lt;/span&gt; &lt;span class="n"&gt;processStartInfo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// --- UseShellExecute and the Environment property population Hack ---&lt;/span&gt;
    &lt;span class="c1"&gt;//&lt;/span&gt;
    &lt;span class="c1"&gt;// We need UseShellExecute to be able to use the runas verb, but it looks like that we can't start the process with the VS debugger,&lt;/span&gt;
    &lt;span class="c1"&gt;// because the StartInfo always populates the _environmentVariables field once the Environment property is populated.&lt;/span&gt;
    &lt;span class="c1"&gt;// _environmentVariables is not a public field.&lt;/span&gt;
    &lt;span class="c1"&gt;//&lt;/span&gt;
    &lt;span class="c1"&gt;// .NET expects _environmentVariables to be null when trying to start the process with the UseShellExecute being set to true,&lt;/span&gt;
    &lt;span class="c1"&gt;// but when calling Start(), .NET calls StartWithShellExecuteEx() and checks to see if that variable is null, so executing the&lt;/span&gt;
    &lt;span class="c1"&gt;// process in this way is basically impossible after evaluating the Environment property without having to somehow nullify this&lt;/span&gt;
    &lt;span class="c1"&gt;// _environmentVariables field using private reflection after evaluating the Environment property.&lt;/span&gt;
    &lt;span class="c1"&gt;//&lt;/span&gt;
    &lt;span class="c1"&gt;// if (startInfo._environmentVariables != null)&lt;/span&gt;
    &lt;span class="c1"&gt;//     throw new InvalidOperationException(SR.CantUseEnvVars);&lt;/span&gt;
    &lt;span class="c1"&gt;//&lt;/span&gt;
    &lt;span class="c1"&gt;// Please DO NOT even try to evaluate selfProcess.StartInfo.Environment in your debugger even if hovering over selfProcess.StartInfo,&lt;/span&gt;
    &lt;span class="c1"&gt;// because that would undo all the changes that we've made to the _environmentVariables and causes us to lose all the changes made&lt;/span&gt;
    &lt;span class="c1"&gt;// to this instance of StartInfo.&lt;/span&gt;
    &lt;span class="c1"&gt;//&lt;/span&gt;
    &lt;span class="c1"&gt;// if (_environmentVariables == null)&lt;/span&gt;
    &lt;span class="c1"&gt;// {&lt;/span&gt;
    &lt;span class="c1"&gt;//     IDictionary envVars = System.Environment.GetEnvironmentVariables();&lt;/span&gt;
    &lt;span class="c1"&gt;//     _environmentVariables = new DictionaryWrapper(new Dictionary&amp;lt;string, string?&amp;gt;(&lt;/span&gt;
    &lt;span class="c1"&gt;//     (...)&lt;/span&gt;
    &lt;span class="c1"&gt;// }&lt;/span&gt;
    &lt;span class="c1"&gt;//&lt;/span&gt;
    &lt;span class="c1"&gt;// This hack is only applicable to developers debugging the StartInfo instance of this specific process using VS. Nitrocid should&lt;/span&gt;
    &lt;span class="c1"&gt;// be able to restart itself as elevated normally if no debugger is attached.&lt;/span&gt;
    &lt;span class="c1"&gt;//&lt;/span&gt;
    &lt;span class="c1"&gt;// References:&lt;/span&gt;
    &lt;span class="c1"&gt;//   - https://github.com/dotnet/runtime/blob/release/8.0/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Win32.cs#L47&lt;/span&gt;
    &lt;span class="c1"&gt;//   - https://github.com/dotnet/runtime/blob/release/8.0/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessStartInfo.cs#L91&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;privateReflection&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;BindingFlags&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NonPublic&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;BindingFlags&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Instance&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;BindingFlags&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SetField&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;startInfoType&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;processStartInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetType&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;envVarsField&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;startInfoType&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"_environmentVariables"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;privateReflection&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;envVarsField&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SetValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;processStartInfo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// &lt;/span&gt;
    &lt;span class="c1"&gt;// --- UseShellExecute and the Environment property population Hack End ---&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;processStartInfo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After nullifying this list, &lt;code&gt;Start()&lt;/code&gt; works again. In our opinion, an exception should be thrown when &lt;code&gt;UseShellExecute&lt;/code&gt; is enabled and an attempt to get environment variables is tried to reduce confusing errors.&lt;/p&gt;

&lt;p&gt;Enjoy hacking!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>dotnet</category>
      <category>coding</category>
      <category>csharp</category>
    </item>
  </channel>
</rss>
