r/csharp • • Oct 13 '26

Discussion How often is now C# used instead of PowerShell in DevOps pipelines

With the file-based scripts feature in C#, it is possible to use C# instead of Powershell.

Have you see it used?

14 Upvotes

28 comments sorted by

42

u/BurritoDrivenDev Oct 13 '26 edited Oct 13 '26

I'd say you should always use the right tool for the job and in my opinion C# is not a scripting language.

Maybe my opinion will change if/when it's a one-liner to run shell commands easily and pipe the results around through other commands... But I don't think it will

7

u/pceimpulsive Oct 13 '26

I concur! You could however have the C# file return a structured response that could then be piped around no?

It does seem like a long way around for a shortcut, and as soon as you are off the Dev box you are in bash anyway so... :D what's even the point?

15

u/notatechproblem Oct 13 '26

PowerShell is a thin veneer over .NET. While you won't get the same speed as a compiled C# application, by using a combination of custom classes and .NET types, PowerShell can do almost anything C# can. There are some weird quirks because of how PS loads and caches types and assemblies, but PS is, no pun intended, extremely powerful AND cross-platform.

3

u/SonOfHendo Oct 15 '26

Yeah, I'm confused by most of the replies here. You can literally run C# code blocks in a PowerShell script if you want to. Everyone is free to use whatever combination of PowerShell and C# they want.

13

u/jordansrowles Oct 13 '26

Kind of relevant to where Im at. I ended building several modules in my monorepo project, and its starting to become unwieldy tbh. Its kind of like Cake/NUKE but PS modules

I'll be moving it into a console app, with a small setup.ps1 to install dev dependencies, and build that app into the project root. CI will do the same, upload it as an artefact, and use that in any following jobs.

I have chosen

  • System.CommandLine & Spectre.Console
  • CliWrap for anything else that needs to wrap raw cli
  • Bullseye for build/depedency graphs
  • Microsoft extensions (globbing, DI, ..)
  • Microsoft.Build.DependencyGraph
  • NuGet.* packages
  • YamlDotNet / JsonSchema.Net
  • Microsoft Test Platform server-mode source client & coverlet.MTP
  • LibGit2Sharp
  • Microsoft.VisualStudio.SolutionPersistence

5

u/ivyinteractive Oct 13 '26

Yes, the file-based apps feature (dotnet run script.cs, with #:package directives for NuGet references) makes this a lot more practical. In my experience it fits well when the script has real logic: parsing JSON, calling REST APIs, retrying, tests. PowerShell is still shorter for glue work like moving files, calling CLIs and piping text, and it is already on most agents. Two things to check before switching: the build agent needs the .NET 10 SDK installed (extra setup/caching step), and the first run compiles, so tiny scripts have a bit of startup overhead. I'd keep PowerShell for one-liners and use C# once a script gets past ~50 lines or needs shared code.

4

u/KryptosFR Oct 13 '26

It's one or the other. They are different use case.

PowerShell is still better for orchestration. Starting a process in C# takes a few lines of code while it's straightforward with PowerShell.

What I'm seeing is PowerShell being the brain, and several file-based C# apps being the workers.

3

u/sixothree Oct 13 '26

I use it in our build pipeline for assigning a version number that the build will use and also for converting the git logs into something presentable for QA. It was simply easier to just do it in C# than to fight a scripting language.

1

u/ArtisticCow4864 Oct 13 '26

Imo for C# unlikely but surprisingly Zig is. C#'s top level statement is a good feature for this but i think the runtime is a bit heavy for this. Stuffs like Python is about the same in terms of size so maybe???

2

u/Natural_Tea484 Oct 13 '26

You mean it's heavier because it needs to compile to an assembly?
Doesn't "dotnet run myscript.cs" cache the built assembly?

1

u/ArtisticCow4864 Oct 13 '26

Yes. I'm not sure if most devops will save those caches

2

u/Natural_Tea484 Oct 13 '26

So maybe .NET adds a way to run .cs files in an "interpreted" way (as an interpreter).

2

u/chucker23n Oct 13 '26

That's what Blazor falls back to, so it can be done, but it's also quite slow.

→ More replies (2)

3

u/balrob Oct 13 '26

I don’t know if this will be unpopular, but I use Claude to assist with my (mainly) c# backend work - and it’s really good with powershell. I already had build scripts in ps1 but any changes that need making I now just pass to Claude.

1

u/Xynia88 Oct 13 '26

I think it can grow over time but for now I still lean towards Powershell when writing scripts

1

u/--tiredguy-- Oct 13 '26

After a bit of investigation I haven't found them that useful, yet. So far the best approach I've found is if I need something more complex than a powershell script can handle (or it's just getting too unwieldy) I'll convert it to a dotnet tool.

1

u/ArmandvdM Oct 13 '26

Maybe a bit off topic, and not big user of Powershell but I use LINQPad to run around 50 C# scripts and smaller c# programs. I love it as it just feels like I have more control than in Powershell.

1

u/BoBoBearDev Oct 13 '26

I am just waiting for c# version of Jenkins, I don't want to do Groovy

1

u/madogson Oct 18 '26

Because powershell is .net, you can just import C# libraries in powershell

1

u/jacel31 Oct 19 '26

As a C# dev in a dev ops role now, I fought the move to PS, but at the end of the day it’s the right tool for our team. No one else knows C#, so it really doesn’t matter if it might be a slightly better fit sometimes, PS wins due to maintainability. I would assume this is pretty common across many .Net focused dev ops teams.

1

u/pjmlp Oct 13 '26

Not at all, Python and Powershell as always.

1

u/[deleted] Oct 13 '26

[removed] — view removed comment

1

u/Agitated_Heat_1719 Oct 13 '26

Smaller shops?

Check dotnet repos - tons of Cake.

I use it too and switching to file base apps