You can easily write CSharpScript using the Zx function of ProcessX.
First of all, CSharpZxScript requires .NET5 SDK. It is recommended that you register Visual Studio 2019, which includes .NET5 as the default program to open the Solution. The easiest way to acquire and run CSharpZxScript is as a dotnet tool.
dotnet tool install --global CSharpZxScript
When the installation is complete, you can see help with the following command
cszx -help
Usage: CSharpZxScript <Command>
Commands:
Run, r
Edit, e
Inline, inl
ResetCache, rc
SettingsList, sl
SettingsAddPackage, sapa
SettingsRemovePackage, srpa
SettingsAddProject, sapr
SettingsRemoveProject, srpr
SettingsAddCs, sac
SettingsRemoveCs, src
install Add Run ZxScript and Edit ZxScript to the right-click menu of .cs
uninstall Remove right-click menu
help Display help.
version Display version.
Since the command operation is difficult, it is recommended to enter the following command and add it to the right-click Menu.
cszx install
You can create the .cs file you want to run and run it from the right-click menu
using System;
using Zx;
using static Zx.Env;
await run($"echo {"echo test"}");
await run($"echo {Environment.CurrentDirectory}");
Environment.Exit(1);
"echo test"
test.cs Directory
ExitCode 1
Please any key...
How to delete right-click Menu.
cszx rrc
To edit the script, select "Edit Zx Script" from the right-click menu. The default IDE set in .sln will be launched. And the code completion for C# works perfectly.
The settings apply to all scripts under the folder. In addition it is possible to set across multiple folders. Note that if a package with a different version is found at that time, the version of the child's folder will take precedence. The settings are saved as [ZxScriptSettings.json] in each folder
Can use the NuGet package.
Let's put System.Text.Json as an example
C:\Scripts>cszx sapa System.Text.Json 5.0.2
edit script.
C:\Scripts>cszx e test.cs
using static Zx.Env;
var strArray = new []{"A", "B", "C", "D", "E"};
await run($"echo {System.Text.Json.JsonSerializer.Serialize(strArray)}");
You can debug on the IDE.
C:\Scripts>cszx r test.cs
["A","B","C","D","E"]
How to delete
C:\Scripts>cszx srpa System.Text.Json
Can reference to csproj. This allows you to share your C # library with other projects. This means that you can use a Utility created in C # in a script.
You can register with an absolute path, but it is recommended to register with a relative path.
C:\Scripts>cszx sapr ../../Project.Core.csproj
How to delete
C:\Scripts>cszx srpr ../../Project.Core.csproj
Can reference to .cs You can easily add a class for your script. Similar to reference csproj, but simpler.
You can register with an absolute path, but it is recommended to register with a relative path.
C:\Scripts>cszx sapc ScriptCore.cs
How to delete
C:\Scripts>cszx srpr ScriptCore.cs