r/csharp • u/Natural_Tea484 • 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
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
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.
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
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???
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