Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

CsScript .NET plugin for TCC v36

Aug
2,799
144
Please find attached my first .NET plugin for TCC using the experimental support in Version 36.
Ref: .NET Plugins in TCC v36 - Looking for .NET Developers

I have been using the cscs.exe from the CS-Script scripting system to execute .csx and .cs scripts.
Ref: GitHub - oleg-shilo/cs-script.net-framework: A mirror of the oleg-shilo/cs-script repository of CS-Script for .NET Framework. A copy of the repo before the product migration on .NET 5

The CsScript plugin eliminates the need to use cscs.exe now.

The included template.csx works with both cscs.exe and the CsScript plugin.

Example usage:
Code:
E:\...\Release>plugin /l csscript.dll

E:\...\Release>which csscript
csscript is a plugin command (CsScript)

E:\...\Release>csscript template.csx
No arguments provided.

Today's Date: 2026-04-04
Current Time: 08:05:13

Circle with radius 5: Area = 78.54

E:\...\Release>csscript template.csx 10 20
Arguments received:
  args[0] = 10
  args[1] = 20

Sum: 10 + 20 = 30
Product: 10 * 20 = 200

String Examples:
  Original: 10
  Upper:    10
  Lower:    10
  Length:   2

Today's Date: 2026-04-04
Current Time: 08:05:21

Circle with radius 5: Area = 78.54

E:\...\Release>csscript template.csx Hello World!
Arguments received:
  args[0] = Hello
  args[1] = World!
Error: First two arguments must be integers

String Examples:
  Original: Hello
  Upper:    HELLO
  Lower:    hello
  Length:   5

Today's Date: 2026-04-04
Current Time: 08:05:29

Circle with radius 5: Area = 78.54

Template.csx
Code:
using System;
using System.Globalization;

/// <summary>
/// C# Script Template for CSSCRIPT Plugin Command
/// 
/// This is a template for creating .csx scripts to run via the CSSCRIPT plugin command.
/// 
/// USAGE:
///   CSSCRIPT template.csx
///   CSSCRIPT template.csx arg1 arg2 arg3
/// 
/// REQUIREMENTS:
///   - Script must have a Program class
///   - Program class must have a static void Main() or static void Main(string[] args) method
///   - Use Console.WriteLine() for output
///   - Use Console.Error.WriteLine() for error messages
///   - Return codes: Main() is void, so return via Environment.Exit() if needed
/// </summary>

class Program
{
        static void Main(string[] args)
        {
                try
                {
                        // Example 1: Print all arguments
                        if (args.Length > 0)
                        {
                                Console.WriteLine("Arguments received:");
                                for (int i = 0; i < args.Length; i++)
                                {
                                        Console.WriteLine("  args[" + i + "] = " + args[i]);
                                }
                        }
                        else
                        {
                                Console.WriteLine("No arguments provided.");
                        }

                        // Example 2: Parse numeric arguments
                        if (args.Length >= 2)
                        {
                                int num1, num2;
                                if (int.TryParse(args[0], out num1) && int.TryParse(args[1], out num2))
                                {
                                        Console.WriteLine(string.Format("\nSum: {0} + {1} = {2}", num1, num2, num1 + num2));
                                        Console.WriteLine(string.Format("Product: {0} * {1} = {2}", num1, num2, num1 * num2));
                                }
                                else
                                {
                                        Console.Error.WriteLine("Error: First two arguments must be integers");
                                }
                        }

                        // Example 3: String manipulation
                        if (args.Length > 0)
                        {
                                string text = args[0];
                                Console.WriteLine("\nString Examples:");
                                Console.WriteLine("  Original: " + text);
                                Console.WriteLine("  Upper:    " + text.ToUpperInvariant());
                                Console.WriteLine("  Lower:    " + text.ToLowerInvariant());
                                Console.WriteLine("  Length:   " + text.Length);
                        }

                        // Example 4: Work with dates
                        DateTime today = DateTime.Today;
                        Console.WriteLine("\nToday's Date: " + today.ToString("yyyy-MM-dd"));
                        Console.WriteLine("Current Time: " + DateTime.Now.ToString("HH:mm:ss"));

                        // Example 5: Simple calculation
                        double pi = 3.14159265359;
                        double radius = 5.0;
                        double area = pi * radius * radius;
                        Console.WriteLine("\nCircle with radius " + radius + ": Area = " + area.ToString("F2"));
                }
                catch (Exception ex)
                {
                        Console.Error.WriteLine("Error: " + ex.Message);
                }
        }
}

It would be appreciated if other users of TCC version 36.00.16 and above would please test this plugin.

TCC Versions prior to version 36.00.16 do not include the experimental .NET plugin support.

I used...
Code:
E:\...\DotNetPlugin>dotnet --version
10.0.100-preview.7.25380.108
...in the creation of this plugin.

I found the development of this .NET plugin much easier than using C++/CLI
Ref: GitHub - joec4281/MyPShell: Demonstration of a Take Command Console Plugin written in C++/CLI that allows running PowerShell Command and Files

Joe
 

Attachments

It loads, and provides a CSSCRIPT command. It seems to run the provided template.csx script, which displays the date and time, and a reasonable estimate of a circle's area.

But I'm afraid I'm too ignorant of C-sharp to give it any kind of in-depth testing....
 
I've cleaned up the CSScript.cs code,
and have placed the project in a GitHub repository,
for those interested.

Ref: Visual Studio Code for the Web
or
Ref: GitHub - joec4281/CSScript: A .NET Framework plugin for Take Command Console, to run simple C# scripts.

With the exception of calling TCC commands from C# code,
the template.csx will also work with the CS-Script cscs.exe interpreter.

Ref: GitHub - oleg-shilo/cs-script.net-framework: A mirror of the oleg-shilo/cs-script repository of CS-Script for .NET Framework. A copy of the repo before the product migration on .NET 5

1784660430042.webp


Joe
 
Back
Top