home / skills / windmill-labs / windmill / write-script-csharp
This skill helps you craft C# scripts with a public static Main method, return types, and NuGet integration for quick automation.
npx playbooks add skill windmill-labs/windmill --skill write-script-csharpReview the files below or copy the command above to add this skill to your agents.
---
name: write-script-csharp
description: MUST use when writing C# scripts.
---
## CLI Commands
Place scripts in a folder. After writing, run:
- `wmill script generate-metadata` - Generate .script.yaml and .lock files
- `wmill sync push` - Deploy to Windmill
Use `wmill resource-type list --schema` to discover available resource types.
# C#
The script must contain a public static `Main` method inside a class:
```csharp
public class Script
{
public static object Main(string name, int count)
{
return new { Name = name, Count = count };
}
}
```
**Important:**
- Class name is irrelevant
- Method must be `public static`
- Return type can be `object` or specific type
## NuGet Packages
Add packages using the `#r` directive at the top:
```csharp
#r "nuget: Newtonsoft.Json, 13.0.3"
#r "nuget: RestSharp, 110.2.0"
using Newtonsoft.Json;
using RestSharp;
public class Script
{
public static object Main(string url)
{
var client = new RestClient(url);
var request = new RestRequest();
var response = client.Get(request);
return JsonConvert.DeserializeObject(response.Content);
}
}
```
This skill provides clear conventions and examples for writing C# scripts that run in the platform. It explains the required entry point, how to return values, and how to reference NuGet packages. Use this guidance to create scripts that can be packaged, metadata-generated, and deployed via the CLI.
A valid script must define a public static Main method inside any class; the method accepts typed parameters and returns either object or a concrete type. NuGet libraries are added with #r "nuget: ..." directives at the top of the file and standard using statements. Once scripts are written, you generate metadata and push deployments with the CLI so the platform can run them as webhooks, workflows, or UI actions.
Does the class name matter?
No. Only the public static Main method signature matters; the class name can be anything.
How do I add external NuGet packages?
Add them with #r "nuget: PackageName, Version" at the top of the file, then include using statements as usual.
What CLI steps are required to deploy a script?
After writing the script, run `wmill script generate-metadata` to produce .script.yaml and lock files, then `wmill sync push` to deploy.