Welcome!

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

SignUp Now!

How to use/run C# code from TCC via PSHELL

Aug
2,799
144
Using my cs2ps1.btm file,
you can run your C# code from TCC via PShell.

Ref: Write/Run your C# code in a .btm file

In this example,
I have copied the cs2ps1.btm file to test.btm

On the initial run,
you will require the Microsoft C# compiler to be available to create the .NET .dll.

After that,
the .dll will be used instead of being re-compiled.

Example use:
Code:
R:\>copy u:\cs2ps1.btm test.btm
U:\cs2ps1.btm => R:\test.btm
     1 file copied

R:\>test.btm
Microsoft (R) Visual C# Compiler version 4.14.0-3.26229.7 (2b68181e)
Copyright (C) Microsoft Corporation. All rights reserved.

Days in month (2026 5) 31
1001
GetUserName: jlcav
GetUserName: jlcav
ShellTray: 65676
Days in month (2026 5) 31
Lambda: 10+12+13+14+14+18+20+21+24+30+46+50
Name                           Value
----                           -----
PSVersion                      5.1.19041.7291
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.7291
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

R:\>test.btm
Days in month (2026 5) 31
1001
GetUserName: jlcav
GetUserName: jlcav
ShellTray: 65676
Days in month (2026 5) 31
Lambda: 10+12+13+14+14+18+20+21+24+30+46+50
Name                           Value
----                           -----
PSVersion                      5.1.19041.7291
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.7291
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

R:\>

After copying cs2ps1.btm to myfile.btm,
add your C# code,
and run myfile.btm to execute your C# code.

Note well the following switches in the code;
Code:
useDLL
rebuildDLL

If you make changes to your C# code,
make sure to either set rebuildDLL=Y,
or the better method,
delete the generated .NET .dll before running your modified C# code again.

Joe
 
Back
Top