oleg-shilo / cs-script

C# scripting platform
http://www.cs-script.net
MIT License
1.57k stars 234 forks source link

Support `.csx` file extension? #344

Closed Xerxes-2 closed 8 months ago

Xerxes-2 commented 8 months ago

Description: When trying to create and run a .csx file using the C# Script execution engine, I encountered unexpected behaviour. The .csx file seems to be treated as VBScript instead of C# script, which leads to compilation errors.

My environment:

C# Script execution engine (.NET Core). Version 4.8.1.0.
Copyright (C) 2004-2020 Oleg Shilo. www.csscript.net (github.com/oleg-shilo/cs-script)

   CLR:             7.0.11
   System:          Unix 14.0.0
   Architecture:    x64
   Script engine:   /Users/xerxes2/.dotnet/tools/.store/cs-script.cli/4.8.1/cs-script.cli/4.8.1/tools/net7.0/any/cscs.dll
   Compiler engine: csc (/usr/local/share/dotnet/sdk/7.0.401/Roslyn/bincore/csc.dll)
                    -> dotnet (/usr/local/share/dotnet/dotnet)
   NuGet manager:   dotnet
   NuGet cache:     <not found>
   Custom commands:
   Global includes:

Reproduce:

  1. Run css -new test.csx. This creates a test.cs file instead of test.csx.
  2. Manually rename the file to test.csx.
  3. Execute the script with css test.csx.

Expected Behaviour:

  1. css -new foo.csx should create a .csx file
  2. The script should execute without errors.

Actual Behavior: I receive the following error:

Error: Specified file could not be compiled.

/Users/xerxes2/script/test.csx(0,0): error (0,0): vbc : error BC31030: Conditional compilation constant 'TRACE ^^ ^^ NETCORE;CS_SCRIPT' is not valid: Character is not valid.
/Users/xerxes2/script/test.csx(0,0): error (0,0): vbc : error BC2017: could not find library 'Microsoft.VisualBasic.dll'

It appears the script is being treated as VBScript rather than C# script.

Offer to Help: I understand that maintainers can be busy, and given that this seems to be a simple fix, I'm more than willing to create a PR to address this issue. However, I would appreciate some guidance on which project or directory I should focus on. If you can point me in the right direction, I'd be glad to assist and contribute to the project.

oleg-shilo commented 8 months ago

WOW. That is a weird one.

And, wow, your offer I greatly appreciated. Let me have a quick look at and I will be able to guide you.

oleg-shilo commented 8 months ago

I found that the problem was not so easy to track but easy to fix so I have just prepared the prerelease for you to test. Why prerelease? It's because of my system the problem also sows but it has slightly different symptoms compared to what you reported. Probably because you are 2 versions behind.

Can you please test the executable in your environment and let me know if it addresses the problem? And then I will promote it in a proper release.

Xerxes-2 commented 8 months ago

I found that the problem was not so easy to track but easy to fix so I have just prepared the prerelease for you to test. Why prerelease? It's because of my system the problem also sows but it has slightly different symptoms compared to what you reported. Probably because you are 2 versions behind.

Can you please test the executable in your environment and let me know if it addresses the problem? And then I will promote it in a proper release.

The .csx script works fine now. But css -new test.csx still create a test.cs file.

oleg-shilo commented 8 months ago

yep, I noticed that too but was fully focused on the compilation. good that I asked you re-test. I will address the creation of the file and rerelease. Cheers, have a good night

oleg-shilo commented 8 months ago

Done, you can get the latest release v4.8.5:

nuget.org

dotnet tool install --global cs-script.cli 

Chocolatey

choco install cs-script
Xerxes-2 commented 8 months ago

Thank you! The new version works well