If you’re like me and often need to automate tasks in your work environment, you know how tedious it can be to create and manage scripts. Whether it’s copying files for deployments, installing services, or setting up Windows configurations, the traditional tools like Batch or PowerShell scripts can quickly become messy and hard to maintain.
Introducing DigaoRunner, a tool I developed to make scripting more efficient, readable, and reliable. Instead of relying on Batch or PowerShell, DigaoRunner allows you to write your automation scripts in C#, offering better structure, error handling, and customization.
Why DigaoRunner?
In my work, automating repetitive tasks is crucial. The typical way to automate things, such as copying files or setting up services, usually involves writing .BAT
, .CMD
, or PowerShell scripts. However, these traditional approaches have several drawbacks:
- Limited readability: They tend to be hard to read and maintain.
- Poor error handling: If something fails, the script often continues running, leading to incomplete or corrupted processes.
- Inefficient scripting language: Writing scripts in Batch or PowerShell can be cumbersome, especially when the task grows in complexity.
DigaoRunner solves these issues by allowing you to write scripts using C#, making the code clean, easy to understand, and better suited for handling errors.
What Can DigaoRunner Do?
With DigaoRunner, you can automate any kind of process you usually handle with traditional scripts, but with the power of C#. Whether you need to:
- Copy files
- Install services
- Execute external processes
- Read and manipulate files
- Configure system settings
DigaoRunner provides you with the tools to write clear and structured scripts, and you can even prompt users for input using predefined fields. This makes it perfect for those repetitive tasks where writing a full-fledged program is unnecessary but scripting is essential.
Example: Creating a Zip Package
Below is an example of a DigaoRunner script that generates a zip package for the DigaoRunner project itself:
@DIGAOSCRIPT
VERSION=1
TITLE=Create Digao Runner Package
@CODE
Echo("========================================================", Color.Cyan);
Echo("Generate Digao Runner zip package", Color.Cyan);
Echo("========================================================", Color.Cyan);
int ret;
string vsWhere = @"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe";
string sevenZip = @"C:\Program Files\7-zip\7z.exe";
string pathProject = @".\DigaoRunnerApp\DigaoRunnerApp.csproj";
string tmpBuildDir = @".\Temp_Build";
string packageFile = @".\DigaoRunner.zip";
string vsPath;
ret = RunProcessReadOutput(vsWhere, "/latest /property installationPath", ref vsPath);
if (ret != 0) Abort("Error getting Visual Studio installation path");
vsPath = vsPath.Split(Environment.NewLine).FirstOrDefault();
if (string.IsNullOrEmpty(vsPath)) Abort("Visual Studio path empty");
string msBuildExe = Path.Combine(vsPath, @"MSBuild\Current\bin\msbuild.exe");
if (Directory.Exists(tmpBuildDir)) Directory.Delete(tmpBuildDir, true);
if (File.Exists(packageFile)) File.Delete(packageFile);
Echo("Compile project");
ret = RunProcess(msBuildExe,
$"\"{pathProject}\" /clp:ErrorsOnly /t:Rebuild /p:PlatformTarget=x64 /p:Configuration=Release /p:OutputPath=\"{Path.GetFullPath(tmpBuildDir)}\"");
//using GetFullPath because MSBUILD internally uses current path as project folder path
if (ret != 0) Abort("Error compiling project");
Echo("Create zip file");
//RunProcess(sevenZip, $"a -sfx DigaoRunnerSetup.exe \"{tmpBuildDir}\"");
ZipFile.CreateFromDirectory(tmpBuildDir, packageFile);
Directory.Delete(tmpBuildDir, true);
Echo("Package successfully created!", Color.Yellow);
Getting Started with DigaoRunner
To start using DigaoRunner, follow these simple steps:
- Install .NET 8 Desktop Runtime (x64).
- Download the latest DigaoRunner release.
- Extract the files to a folder on your computer (e.g.,
C:\DigaoRunner
). - Open
DigaoRunnerApp.exe
and register.ds
files under the “More” menu, so scripts will automatically be associated with this program.
Now you’re ready to write and run your own C# scripts!
Customizing Scripts
DigaoRunner allows you to define variables, prompt for user input, and more, using a simple header in the script file. Here’s an example of how you can configure inputs:
@DIGAOSCRIPT
VERSION=1
TITLE=My Custom Script
$INPUT_FIELD={"Label": "Enter a value", "Type": "text", "Default": "Hello World"}
@CODE
Echo("You entered: " + GetField<string>("INPUT_FIELD"));
The script prompts the user to input a value before executing the code.
Conclusion
If you’re tired of struggling with Batch and PowerShell scripts, give DigaoRunner a try. It’s a more powerful, readable, and flexible way to automate your tasks, leveraging the full capabilities of C#. From error handling to user inputs, DigaoRunner makes scripting a breeze.
Start automating your processes today with DigaoRunner. It’s free!