<?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: Vu Le</title>
    <description>The latest articles on DEV Community by Vu Le (@levu74).</description>
    <link>https://dev.to/levu74</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%2F246608%2F74ae2dd5-99cd-4109-a2b0-c5fbca373180.jpeg</url>
      <title>DEV Community: Vu Le</title>
      <link>https://dev.to/levu74</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/levu74"/>
    <language>en</language>
    <item>
      <title>Tutorial: Running Your C# Code Without a Project File</title>
      <dc:creator>Vu Le</dc:creator>
      <pubDate>Mon, 26 May 2025 07:44:00 +0000</pubDate>
      <link>https://dev.to/levu74/tutorial-running-your-c-code-without-a-project-file-49nk</link>
      <guid>https://dev.to/levu74/tutorial-running-your-c-code-without-a-project-file-49nk</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Important Note:&lt;/strong&gt; The ability to run C# files directly using &lt;code&gt;dotnet run file.cs&lt;/code&gt; as described here is a feature currently available in the &lt;strong&gt;.NET 10 Preview SDK&lt;/strong&gt;. Ensure you have the .NET 10 Preview SDK installed to follow this tutorial. This feature provides a streamlined way to execute simple C# programs without the traditional &lt;code&gt;.csproj&lt;/code&gt; project file setup.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Welcome! This tutorial is designed to guide you through the experience of running a simple C# application directly from a source file using the .NET 10 Preview SDK. This approach, often referred to as running "file-based programs", can be particularly useful for quick tests, learning exercises, or simple scripts where the overhead of a full project structure feels unnecessary. Our goal today is not just to execute some code, but to understand how the .NET Command Line Interface (CLI) in .NET 10 Preview enables this workflow, including how to incorporate external libraries (NuGet packages) and control the underlying SDK used.&lt;/p&gt;

&lt;p&gt;Throughout this session, think of me as your guide. We'll take small, manageable steps together. You'll write a basic C# program, and then we'll use the &lt;code&gt;dotnet run&lt;/code&gt; command to compile and run it directly. You'll see the output immediately, connecting your action with its result. This immediate feedback is crucial for learning. Don't worry about memorizing every detail right now; the focus is on the &lt;em&gt;doing&lt;/em&gt; and observing the outcome. By the end, you'll have successfully run C# code without the usual project setup and gained familiarity with this powerful new feature of the .NET 10 Preview SDK.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting the Stage: Your First C# File
&lt;/h2&gt;

&lt;p&gt;Let's begin by creating our C# source file. Open your favorite text editor or integrated development environment (IDE). Create a new file and name it &lt;code&gt;app.cs&lt;/code&gt;. The &lt;code&gt;.cs&lt;/code&gt; extension is important.&lt;/p&gt;

&lt;p&gt;Inside &lt;code&gt;app.cs&lt;/code&gt;, let's write a very basic C# program using top-level statements:&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="c1"&gt;// app.cs&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;System&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;"Hello from a project-less world in .NET 10 Preview!"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code simply prints a message to the console. Save this file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running the Basic Code
&lt;/h2&gt;

&lt;p&gt;Now, let's run the simple code we just wrote. Open your terminal or command prompt, navigate to the directory where you saved &lt;code&gt;app.cs&lt;/code&gt;, and execute 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;dotnet run app.cs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Assuming you have the .NET 10 Preview SDK correctly installed and configured in your PATH, the .NET CLI will compile your &lt;code&gt;app.cs&lt;/code&gt; file in memory and run it. You should see the output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello from a project-less world in .NET 10 Preview!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This demonstrates the basic capability. The CLI implicitly creates a minimal project definition based on the default &lt;code&gt;dotnet new console&lt;/code&gt; template for the installed SDK version to compile and run your single file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding NuGet Packages with Directives
&lt;/h2&gt;

&lt;p&gt;A key enhancement in the .NET 10 Preview for file-based programs is the ability to reference NuGet packages directly within the source file using special comments called &lt;em&gt;app directives&lt;/em&gt;. Let's modify our &lt;code&gt;app.cs&lt;/code&gt; to use the popular &lt;code&gt;Humanizer&lt;/code&gt; package.&lt;/p&gt;

&lt;p&gt;First, add the directive at the top of your &lt;code&gt;app.cs&lt;/code&gt; 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="err"&gt;#&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;package&lt;/span&gt; &lt;span class="n"&gt;Humanizer&lt;/span&gt;&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;.*&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, modify the code to use the package:&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="c1"&gt;// app.cs&lt;/span&gt;
&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;package&lt;/span&gt; &lt;span class="n"&gt;Humanizer&lt;/span&gt;&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="m"&gt;2&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;Humanizer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Example: Pluralize a word&lt;/span&gt;
&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;singular&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"hobby"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;plural&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;singular&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Pluralize&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;"Plural of '{0}' is '{1}'"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;singular&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;plural&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the changes. Now, run the file again using the same command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet run app.cs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This time, the .NET CLI will detect the &lt;code&gt;#:package&lt;/code&gt; directive. It will resolve and download the &lt;code&gt;Humanizer&lt;/code&gt; package (if not already cached) and include it during the implicit compilation. The output should now pluralize the word "hobby":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Plural of 'hobby' is 'hobbies'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This demonstrates how easily you can incorporate external libraries into your single-file programs using directives, making this feature much more powerful for scripting and small utilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  Specifying SDK and Properties (Advanced)
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;#:sdk&lt;/code&gt; directive allows specifying the project SDK (e.g., &lt;code&gt;#:sdk Microsoft.NET.Sdk.Web&lt;/code&gt; for a web context, though single-file execution primarily targets console apps). The &lt;code&gt;#:property&lt;/code&gt; directive allows setting MSBuild properties (e.g., &lt;code&gt;#:property LangVersion=preview&lt;/code&gt;).&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="c1"&gt;// Example showing potential directives (syntax based on proposal)&lt;/span&gt;
&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;sdk&lt;/span&gt; &lt;span class="n"&gt;Microsoft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NET&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sdk&lt;/span&gt;
&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;property&lt;/span&gt; &lt;span class="n"&gt;LangVersion&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="n"&gt;preview&lt;/span&gt;
&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;package&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;CommandLine&lt;/span&gt;

&lt;span class="c1"&gt;// ... rest of your code&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These directives further configure the implicit project file generated behind the scenes. While the default (&lt;code&gt;Microsoft.NET.Sdk&lt;/code&gt; for console) often suffices, these provide finer control when needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Direct Execution with Shebang (Unix-like Systems)
&lt;/h2&gt;

&lt;p&gt;On Unix-like operating systems (Linux, macOS), you can make your C# file directly executable like a shell script by adding a &lt;em&gt;shebang&lt;/em&gt; line at the very beginning of the file and setting the execute permission.&lt;/p&gt;

&lt;p&gt;Modify your &lt;code&gt;app.cs&lt;/code&gt; file to include the shebang line pointing to &lt;code&gt;dotnet run&lt;/code&gt;:&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="err"&gt;#&lt;/span&gt;&lt;span class="p"&gt;!/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="p"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="p"&gt;/&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt; &lt;span class="n"&gt;dotnet&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;

&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;package&lt;/span&gt; &lt;span class="n"&gt;Humanizer&lt;/span&gt;&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="m"&gt;2&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;Humanizer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Example: Pluralize a word&lt;/span&gt;
&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;singular&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"hobby"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;plural&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;singular&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Pluralize&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;"Plural of '{0}' is '{1}'"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;singular&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;plural&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; The shebang line (&lt;code&gt;#!/usr/bin/env dotnet run&lt;/code&gt;) &lt;em&gt;must&lt;/em&gt; be the very first line in the file.&lt;/p&gt;

&lt;p&gt;Next, you need to make the file executable. Open your terminal in the directory containing &lt;code&gt;app.cs&lt;/code&gt; and run:&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="nb"&gt;chmod&lt;/span&gt; +x app.cs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you can execute the C# file directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./app.cs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The operating system will use the shebang line to invoke &lt;code&gt;/usr/bin/env dotnet run&lt;/code&gt;, which in turn will execute your C# code, including processing any directives like &lt;code&gt;#:package&lt;/code&gt;. You should see the same output as before, but without explicitly typing &lt;code&gt;dotnet run&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This makes C# files feel even more like native scripts on these platforms, further lowering the barrier for simple tasks and automation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding the Context and Limitations
&lt;/h2&gt;

&lt;p&gt;Remember, this file-based execution model in .NET 10 Preview is designed for simplicity and quick tasks. The implicit project created is minimal. If your application involves multiple source files interacting in complex ways, requires intricate build configurations, targets multiple frameworks, or has extensive dependencies, transitioning to a standard project structure using a &lt;code&gt;.csproj&lt;/code&gt; file is the recommended approach. This feature provides a fantastic low-friction entry point, not a replacement for the full project system in complex scenarios.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Grow-Up Path
&lt;/h2&gt;

&lt;p&gt;Should your single-file program evolve and require the structure of a full project, .NET 10 Preview provides a command to facilitate this transition. Running &lt;code&gt;dotnet project convert app.cs&lt;/code&gt; (syntax based on the proposal) would materialize the implicit project file (&lt;code&gt;.csproj&lt;/code&gt;) on disk, allowing you to manage it explicitly.&lt;/p&gt;

&lt;p&gt;This concludes our revised tutorial on running C# without a project file using the .NET 10 Preview SDK. You've seen how to run basic files and incorporate NuGet packages using directives, providing a powerful yet simple way to execute C# code.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=98MizuB7i-w" rel="noopener noreferrer"&gt;No projects just C# with &lt;code&gt;dotnet run app.cs&lt;/code&gt; | DEM518&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/dotnet/sdk/blob/v10.0.100-preview.4.25258.110/src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs" rel="noopener noreferrer"&gt;VirtualProjectBuildingCommand&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>dotnet</category>
      <category>programming</category>
      <category>microsoft</category>
    </item>
    <item>
      <title>How CSS-in-JS Works and Why It Matters</title>
      <dc:creator>Vu Le</dc:creator>
      <pubDate>Mon, 26 May 2025 01:15:39 +0000</pubDate>
      <link>https://dev.to/levu74/how-css-in-js-works-and-why-it-matters-2a27</link>
      <guid>https://dev.to/levu74/how-css-in-js-works-and-why-it-matters-2a27</guid>
      <description>&lt;h2&gt;
  
  
  🧐 What Is CSS-in-JS?
&lt;/h2&gt;

&lt;p&gt;CSS-in-JS is a styling approach where CSS is written within JavaScript files—often directly inside React components—using libraries like styled-components or Emotion.&lt;/p&gt;

&lt;p&gt;Instead of maintaining separate .css files, CSS-in-JS lets you co-locate styles with the components they affect. This improves maintainability, enables powerful tooling (like theming and dynamic styles), and avoids common problems like global namespace collisions.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚙️ How CSS-in-JS Works Under the Hood
&lt;/h2&gt;

&lt;p&gt;Libraries like &lt;code&gt;styled-components&lt;/code&gt; and &lt;code&gt;@emotion/styled&lt;/code&gt; turn your style definitions into actual CSS rules injected into the document's &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; at runtime.&lt;/p&gt;

&lt;p&gt;Here's what happens:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You Define a Styled Component
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;styled-components&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="s2"&gt;`
  background: blue;
  color: white;
  padding: 10px;
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The Library Generates a Unique Class Name&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;At build or runtime, the library:&lt;/p&gt;

&lt;p&gt;Parses your template literal&lt;/p&gt;

&lt;p&gt;Hashes the content to generate a unique class name (e.g., .sc-a1234)&lt;/p&gt;

&lt;p&gt;Injects a CSS rule like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.sc-a1234&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&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;ol&gt;
&lt;li&gt;The Component Renders with That Class&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Click me&lt;/p&gt;

&lt;p&gt;You never have to manage the class name yourself—the library abstracts that for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚡ Dynamic Styles
&lt;/h2&gt;

&lt;p&gt;You can create styles that react to props or themes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="s2"&gt;`
  background: &lt;/span&gt;&lt;span class="p"&gt;${(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;primary&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;gray&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;;
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On render, the library evaluates the JavaScript expression, injects a new rule with a unique hash, and updates the DOM.&lt;/p&gt;

&lt;h2&gt;
  
  
  📚 Theming Support
&lt;/h2&gt;

&lt;p&gt;Libraries like styled-components and emotion support theming out of the box. You define a theme object and wrap your app in a provider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ThemeProvider&lt;/span&gt; &lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;primaryColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;tomato&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ThemeProvider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then access theme values in styles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="s2"&gt;`
  color: &lt;/span&gt;&lt;span class="p"&gt;${(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;primaryColor&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;;
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This enables centralized design tokens (e.g., colors, spacing, breakpoints) across your app.&lt;/p&gt;

&lt;h2&gt;
  
  
  ✅ Benefits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Scoped styles by default (no global leakage)&lt;/li&gt;
&lt;li&gt;Dynamic styling using JS expressions&lt;/li&gt;
&lt;li&gt;Code co-location (styles + logic together)&lt;/li&gt;
&lt;li&gt;Theme-aware styling&lt;/li&gt;
&lt;li&gt;Removes need for class naming conventions (e.g., BEM)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🚫 Trade-Offs
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Adds runtime overhead (unless extracted at build time)&lt;/li&gt;
&lt;li&gt;Debugging can be harder (though devtools have improved)&lt;/li&gt;
&lt;li&gt;Requires tooling/bundler support (e.g., Babel plugin for styled-components)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🧪 Popular CSS-in-JS Libraries
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Library&lt;/th&gt;
&lt;th&gt;Notes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;styled-components&lt;/td&gt;
&lt;td&gt;Most popular; good developer experience&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;@emotion/styled&lt;/td&gt;
&lt;td&gt;Similar API, faster runtime&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;vanilla-extract&lt;/td&gt;
&lt;td&gt;Type-safe, zero-runtime CSS-in-JS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Stitches&lt;/td&gt;
&lt;td&gt;Modern alternative with build-time extraction&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  🧵 When to Use It
&lt;/h2&gt;

&lt;p&gt;CSS-in-JS shines in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Component-based architectures (e.g., React)&lt;/li&gt;
&lt;li&gt;Design systems with theme support&lt;/li&gt;
&lt;li&gt;Projects where dynamic styles or runtime customization are key&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It may be overkill for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Static websites&lt;/li&gt;
&lt;li&gt;Projects where global styles or traditional CSS files are sufficient&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  💡 Summary
&lt;/h2&gt;

&lt;p&gt;CSS-in-JS moves styles into JavaScript for better modularity, dynamic capabilities, and maintainability in modern web apps. Tools like styled-components and emotion streamline the process of defining, scoping, and applying styles while unlocking features like theming and prop-based styling.&lt;/p&gt;

&lt;p&gt;It's a powerful paradigm—but like all tools, it's best used where its benefits align with your project's needs.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>css</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Handling Input Streams in .NET Applications for Command Pipelines</title>
      <dc:creator>Vu Le</dc:creator>
      <pubDate>Tue, 13 May 2025 05:25:18 +0000</pubDate>
      <link>https://dev.to/levu74/handling-input-streams-in-net-applications-for-command-pipelines-2coj</link>
      <guid>https://dev.to/levu74/handling-input-streams-in-net-applications-for-command-pipelines-2coj</guid>
      <description>&lt;p&gt;When building .NET applications intended for use in console environments, it's essential to design your program to be flexible. One common requirement is to detect whether input is being provided via a command pipeline (i.e., from stdin) and, if not, to perform a default action. This article explores how you can inspect the input stream in your .NET application and adjust behavior accordingly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Command Pipelines in Linux
&lt;/h2&gt;

&lt;p&gt;In Linux, the pipe operator (&lt;code&gt;|&lt;/code&gt;) connects the output of one command to the input of another. For example:&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="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Hello, World!"&lt;/span&gt; | dotnet run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this command, the output of &lt;code&gt;echo&lt;/code&gt; is sent to your .NET application via standard input. Your application must determine whether such piped input is present in order to correctly process data or use fallback logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checking for Input in a .NET Application
&lt;/h2&gt;

&lt;p&gt;There are several methods to detect if there's data available on the input stream. Below, we discuss three common approaches.&lt;/p&gt;

&lt;h3&gt;
  
  
  Detecting Input Redirection
&lt;/h3&gt;

&lt;p&gt;A good workaround is to determine whether the standard input is redirected. .NET provides the &lt;code&gt;Console.IsInputRedirected&lt;/code&gt; property, which returns:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;true&lt;/code&gt; when the input is coming from a pipe or a file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;false&lt;/code&gt; when the input is from an interactive terminal session.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example: Conditional Input Handling&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Below is an example that demonstrates how to check for input redirection before attempting to read data. This approach avoids the blocking behavior when no piped data is provided:&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;if&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="n"&gt;IsInputRedirected&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="n"&gt;input&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="n"&gt;In&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ReadToEnd&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;"Received Input: "&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;else&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;"No input detected; proceeding with default action."&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;
  
  
  Integrating with Command Pipelines
&lt;/h2&gt;

&lt;p&gt;By combining these methods with Linux command pipelines, your .NET application can operate intelligently based on the source of its input. For instance, consider the pipeline:&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="nb"&gt;cat &lt;/span&gt;sample.txt | dotnet run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When data is piped into your application from &lt;code&gt;sample.txt&lt;/code&gt;, one of the methods above detects the input and processes it. If no data is piped, your application can execute alternative logic. This flexibility makes your application robust and adaptable to various runtime conditions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Detecting whether an input stream contains data is crucial when designing .NET applications that interact with command pipelines.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>cli</category>
    </item>
    <item>
      <title>Fast Static Website Deployment using Pulumi for C#</title>
      <dc:creator>Vu Le</dc:creator>
      <pubDate>Sat, 05 Apr 2025 04:55:12 +0000</pubDate>
      <link>https://dev.to/levu74/fast-static-website-deployment-using-pulumi-for-c-3i77</link>
      <guid>https://dev.to/levu74/fast-static-website-deployment-using-pulumi-for-c-3i77</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/pulumi"&gt;Pulumi Deploy and Document Challenge&lt;/a&gt;: Fast Static Website Deployment&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;A sample Pulumi project that demonstrates how to deploy a Blazor WebAssembly using Azure Static Web Apps. The project is designed to be simple and easy to understand, making it a great starting point for anyone looking to learn about deploying static web apps with Pulumi.&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%2F4z64cyau5p2z64hjaci4.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%2F4z64cyau5p2z64hjaci4.png" alt="Architecture Overview"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Live Demo Link
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://delightful-hill-0ee769c1e.6.azurestaticapps.net/" rel="noopener noreferrer"&gt;Link to Azure Static Web App&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It may not be available in the future, so I uploaded a recording here&lt;/p&gt;

&lt;p&gt;&lt;a href="https://raw.githubusercontent.com/levu74/my-blazor-pulumi-swa/refs/heads/main/docs/images/project-demo.gif" rel="noopener noreferrer"&gt;https://raw.githubusercontent.com/levu74/my-blazor-pulumi-swa/refs/heads/main/docs/images/project-demo.gif&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Repo
&lt;/h2&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/levu74" rel="noopener noreferrer"&gt;
        levu74
      &lt;/a&gt; / &lt;a href="https://github.com/levu74/my-blazor-pulumi-swa" rel="noopener noreferrer"&gt;
        my-blazor-pulumi-swa
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Fast Static Web App deployment using Pulumi&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;This repository contains a sample Pulumi project that demonstrates how to deploy a static web app using Azure Static Web Apps. The project is designed to be simple and easy to understand, making it a great starting point for anyone looking to learn about deploying static web apps with Pulumi.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Architecture Overview&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/levu74/my-blazor-pulumi-swa/docs/images/architecture-overview.png"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Flevu74%2Fmy-blazor-pulumi-swa%2Fdocs%2Fimages%2Farchitecture-overview.png" alt="Architecture Overview"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The diagram shows a complete deployment pipeline with the following components:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;GitHub Repository: Source code is stored in GitHub for version control&lt;/li&gt;
&lt;li&gt;Azure Pipelines: Handles CI/CD processes&lt;/li&gt;
&lt;li&gt;Azure Identity/Service Principal: Manages access to Azure resources and assigned to Azure Pipelines&lt;/li&gt;
&lt;li&gt;Azure Static Web App: Hosting platform for the Blazor application&lt;/li&gt;
&lt;li&gt;Azure Key Vault: Securely stores secrets including the Static Web App deployment token&lt;/li&gt;
&lt;li&gt;Pulumi: Infrastructure as Code (IaC) tool used to manage the deployment of the Azure resources&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Worklow&lt;/h3&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;Developers write code and push it to GitHub&lt;/li&gt;
&lt;li&gt;GitHub triggers Azure Pipelines…&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/levu74/my-blazor-pulumi-swa" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  My Journey
&lt;/h2&gt;

&lt;p&gt;As a .NET developer, I recently began using Pulumi to provision infrastructure. Although I'm new to Pulumi, I didn’t face many significant challenges thanks to my development background. The Pulumi SDK for C# made the transition easier, as it allows developers to use familiar language features while performing tasks typically handled by DevOps or platform engineers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting up the stack&lt;/strong&gt;&lt;br&gt;
I successfully set up a Pulumi stack and ran it locally without issues. The execution logs are clear and informative, which made it easy to understand what was happening during deployments. When I encountered issues, I was able to debug my Pulumi project using the &lt;code&gt;launch.json&lt;/code&gt; configuration in Visual Studio Code—this was a big help in quickly identifying and fixing problems.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"configurations"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pulumi"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"request"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"launch"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pulumi preview"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"preview"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"workDir"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"${workspaceFolder}/infra/pulumi/Blazor.Infra.Pulumi"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;CI/CD Pipeline Integration&lt;/strong&gt;&lt;br&gt;
One challenge I faced was integrating Pulumi into the CI/CD pipeline. The Pulumi CLI did not work properly with Azure Workload Identity, which caused deployment failures. I resolved this by switching to the Pulumi task available in the Azure DevOps Marketplace, which worked seamlessly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;task&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Pulumi@1&lt;/span&gt;
  &lt;span class="na"&gt;inputs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;azureSubscription&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;$(ado.azureServiceConnection)&lt;/span&gt;
    &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;up&lt;/span&gt;
    &lt;span class="na"&gt;cwd&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;infra/pulumi/Blazor.Infra.Pulumi&lt;/span&gt;
    &lt;span class="na"&gt;stack&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;$(environment)&lt;/span&gt;
    &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--yes"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Managing State&lt;/strong&gt;&lt;br&gt;
Pulumi’s approach to storing infrastructure state is helpful for visualizing changes over time. It allows me to track the history of deployed resources and view their outputs in a centralized and structured manner.&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%2F3ssx6unhm7kg298hf4nt.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%2F3ssx6unhm7kg298hf4nt.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Using Pulumi
&lt;/h2&gt;



&lt;p&gt;In this project, I leveraged Pulumi with C# to create and manage Azure infrastructure as code (IaC) for my Blazor application. As a .NET developer, Pulumi's C# SDK offered a familiar programming model while allowing me to define cloud resources with strongly-typed constructs.&lt;/p&gt;
&lt;h3&gt;
  
  
  Stack Architecture
&lt;/h3&gt;

&lt;p&gt;My &lt;a href="https://github.com/levu74/my-blazor-pulumi-swa/blob/62d01dbf5ee254ff0c4498c939e284e5d72557e5/infra/pulumi/Blazor.Infra.Pulumi/StaticWebAppStack.cs" rel="noopener noreferrer"&gt;StaticWebAppStack.cs&lt;/a&gt; creates several Azure resources:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Resource Group&lt;/strong&gt; - Container for all project resources&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Static Web App&lt;/strong&gt; - Hosting platform for my Blazor application&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key Vault&lt;/strong&gt; - Secure storage for deployment tokens&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key Vault Secret&lt;/strong&gt; - Storing the Static Web App deployment token&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Benefits of Using Pulumi
&lt;/h3&gt;
&lt;h4&gt;
  
  
  1. &lt;strong&gt;Native Language Experience&lt;/strong&gt;:
&lt;/h4&gt;

&lt;p&gt;Using C# meant I could apply my existing .NET skills:&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;staticWebApp&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;Az&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Web&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;StaticSite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;staticWebAppName&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="p"&gt;{&lt;/span&gt;
       &lt;span class="n"&gt;ResourceGroupName&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;resourceGroup&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&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="n"&gt;resourceGroup&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="n"&gt;Sku&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;Az&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Web&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Inputs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SkuDescriptionArgs&lt;/span&gt;
       &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="n"&gt;Tier&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Free"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Free"&lt;/span&gt;
       &lt;span class="p"&gt;},&lt;/span&gt;
       &lt;span class="c1"&gt;// ...&lt;/span&gt;
   &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. &lt;strong&gt;Secret Management&lt;/strong&gt;:
&lt;/h4&gt;

&lt;p&gt;I could programmatically retrieve and securely store tokens:&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;deploymentToken&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;staticWebAppSecrets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;secrets&lt;/span&gt; &lt;span class="p"&gt;=&amp;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;secrets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Properties&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;x&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="s"&gt;"apiKey"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;FirstOrDefault&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="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;staticWebAppTokenSecret&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;Az&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;KeyVault&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Secret&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"staticWebAppTokenSecret"&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="p"&gt;{&lt;/span&gt;
       &lt;span class="n"&gt;ResourceGroupName&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;resourceGroup&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="n"&gt;VaultName&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;keyVault&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="n"&gt;SecretName&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"swaDeploymentToken"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="n"&gt;Properties&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;Az&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;KeyVault&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Inputs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SecretPropertiesArgs&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="n"&gt;deploymentToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="n"&gt;ContentType&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"text/plain"&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;h4&gt;
  
  
  3. &lt;strong&gt;Using Stack Outputs for CI/CD integration&lt;/strong&gt;:
&lt;/h4&gt;

&lt;p&gt;I defined outputs to expose important information for CI/CD:&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="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"keyVaultName"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
   &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;Output&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;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;KeyVaultName&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;private&lt;/span&gt; &lt;span class="k"&gt;set&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;Using Pulumi's outputs for next deployment stage&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;script&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
      &lt;span class="s"&gt;pulumi stack select $(environment)&lt;/span&gt;
      &lt;span class="s"&gt;KEYVAULT_NAME=$(pulumi stack output keyVaultName)&lt;/span&gt;
      &lt;span class="s"&gt;echo "##vso[task.setvariable variable=keyVaultName;isOutput=true]$KEYVAULT_NAME"&lt;/span&gt;
    &lt;span class="na"&gt;displayName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Set&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;stack&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;outputs&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;as&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;variables"&lt;/span&gt;
    &lt;span class="na"&gt;workingDirectory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;infra/pulumi/Blazor.Infra.Pulumi&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;setOutputs"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. &lt;strong&gt;Stack for Environment-based configuration&lt;/strong&gt;:
&lt;/h4&gt;

&lt;p&gt;Using stack references for environment-specific configurations:&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;stackName&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Deployment&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;StackName&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;projectName&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Deployment&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;ProjectName&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;fullStackName&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;projectName&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;stackName&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. &lt;strong&gt;Integration with CI/CD&lt;/strong&gt;:
&lt;/h4&gt;

&lt;p&gt;Easily integrating with Azure Pipelines using the Pulumi task:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;   &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;task&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Pulumi@1&lt;/span&gt;
     &lt;span class="na"&gt;inputs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
       &lt;span class="na"&gt;azureSubscription&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;$(ado.azureServiceConnection)&lt;/span&gt;
       &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;up&lt;/span&gt;
       &lt;span class="na"&gt;cwd&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;infra/pulumi/Blazor.Infra.Pulumi&lt;/span&gt;
       &lt;span class="na"&gt;stack&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;$(environment)&lt;/span&gt;
       &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--yes"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2F9dcfs7we7to40lk4hozl.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%2F9dcfs7we7to40lk4hozl.png" alt="Azure Pipelines stages"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Pulumi's approach to IaC using familiar programming languages significantly improved my development workflow. Instead of treating infrastructure as a separate concern with its own syntax and tools, I could apply the same software engineering principles I use in application development to my infrastructure code.&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>pulumichallenge</category>
      <category>webdev</category>
      <category>cloud</category>
    </item>
  </channel>
</rss>
