oleg-shilo / cs-script

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

Does not run with .NET 8? #350

Closed UweKeim closed 7 months ago

UweKeim commented 7 months ago

I've just updated my projects to .NET 8, pushed it to my GitLab instance which triggered a build pipeline that also uses cs-script. It runs inside a docker image mcr.microsoft.com/dotnet/sdk:latest.

Unfortunately this fails since the docker images was automatically upgraded to .NET 8.

Excerpt from the pipline log:

$ dotnet tool update --global cs-script.cli
Skipping NuGet package signature verification.
Tool 'cs-script.cli' was reinstalled with the latest stable version (version '4.8.7').
$ ~/.dotnet/tools/css -config:set:LegacyNugetSupport=false
You must install or update .NET to run this application.
App: /root/.dotnet/tools/css
Architecture: x[64](https://git.example.com/comp/repo/-/jobs/2978#L64)
Framework: 'Microsoft.NETCore.App', version '7.0.0' (x64)
.NET location: /usr/share/dotnet
The following frameworks were found:
  8.0.0 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Learn more:
https://aka.ms/dotnet/app-launch-failed
To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=7.0.0&arch=x64&rid=linux-x64&os=debian.12

My question:

Is it possible that you update cs-script to use .NET 8, please?

Or can I somehow tell cs-script to always use the latest available .NET version?

oleg-shilo commented 7 months ago

Hi Uwe,

I am not sure what exactly causing the problem there, but it looks like you cannot even run css. I just have installed .NET 8 over my .NET 7. And it seems like they still can coincide gracefully:

image

Recompilation of the script engine for .NET 8 is a valid approach but at the moment VS v17.8 supporting .NET 8 is not available and VS v17.7 generates the warnings so I am a little cautious.

image

I will build the new release as a preview so you can test it.

If it works well then I will publish it as a proper release on nuget.tools. BTW, I am very close to publishing it on WinGet as well

UweKeim commented 7 months ago

Thanks, Oleg.

Actually, VS 17.8 and .NET 8 is officially released since approx. 10 hours, so no need for preview anymore.

I also get similar errors locally now when using the dotnet tool installed version of cs-script, although it seems I still have the .NET 7 SDK installed:

C:\>dotnet --list-sdks
3.1.426 [C:\Program Files\dotnet\sdk]
6.0.202 [C:\Program Files\dotnet\sdk]
6.0.203 [C:\Program Files\dotnet\sdk]
6.0.320 [C:\Program Files\dotnet\sdk]
6.0.401 [C:\Program Files\dotnet\sdk]
6.0.402 [C:\Program Files\dotnet\sdk]
6.0.417 [C:\Program Files\dotnet\sdk]
7.0.114 [C:\Program Files\dotnet\sdk]
8.0.100 [C:\Program Files\dotnet\sdk]

Probably the lookup mechanism for the .NET SDK stops at the highest one (8) and thus fails to runs cs-script, too.

C:\>css
C# Script execution engine (.NET Core). Version 4.8.7.0.
Copyright (C) 2004-2023 Oleg Shilo. www.csscript.net (github.com/oleg-shilo/cs-script)

   CLR:             7.0.14
   System:          Microsoft Windows NT 10.0.22621.0
   Architecture:    x64
   Install dir:     <not integrated>
   Script engine:   C:\Users\ukeim\.dotnet\tools\.store\cs-script.cli\4.8.7\cs-script.cli\4.8.7\tools\net7.0\any\cscs.dll
   Compiler engine: dotnet (C:\Program Files\dotnet\dotnet.exe)
   NuGet manager:   dotnet
   NuGet cache:     C:\Users\ukeim\.nuget\packages
   Script cache:    C:\Users\ukeim\AppData\Local\Temp\csscript.core\cache
   Custom commands: C:\ProgramData\cs-script\commands
   Global includes: C:\ProgramData\cs-script\inc
oleg-shilo commented 7 months ago

LOL, just got the update VS update

UweKeim commented 7 months ago

If there could be a quick fix for this, I would be incredible thankful, as currently most of my builds fail, both locally and on my GitLab Docker runners.

oleg-shilo commented 7 months ago

Done. https://github.com/oleg-shilo/cs-script/releases/tag/v4.8.8.0

Please give me some time to prepare distros (choco and winget) and I will mark the release as "production". At the moment it is prerelease.

Note: DodtNdet.tool is already published.

oleg-shilo commented 7 months ago

This should get you going

UweKeim commented 7 months ago

My CI scripts do run again. Awesome! Thank you very much for your fast help!

UweKeim commented 7 months ago

Update:

Some of the CI scripts still fail:

...
  ZetaDeployer.ServerWebApi -> /builds/zeta/zeta-deployer/Source/ZetaDeployer.ServerWebApi/bin/Release/net8.0/publish/
$ ~/.dotnet/tools/css ${CI_PROJECT_DIR}/Deploy/Build/cicd-build.cs
Restoring packages...
Restoring packages...
Error: Specified file could not be compiled.
Could not find a part of the path '/root/.local/share/Temp/csscript.core/nuget/f6b73fb0-be87-41b1-8153-55918f08e2d1/publish'.

I'm getting the same when doing a local run of:

css -nuget:restore "c:\P\zeta-time-tracker\Source\do-build-all.cs"

It prints:

Restoring packages...
Restoring packages...
Error: Specified file could not be compiled.

Could not find a part of the path 'C:\Users\ukeim\AppData\Local\Temp\csscript.core\nuget\ba29c316-8cae-4a38-a5eb-623dc78ad788\publish'

I'm not sure what this is related to.

I've tried to delete the whole C:\Users\ukeim\AppData\Local\Temp\csscript.core folder. When running the script again, I do see a folder C:\Users\ukeim\appdata\local\temp\csscript.core\nuget being created but it is empty.

oleg-shilo commented 7 months ago

My CI scripts do run again. Awesome! Thank you very much for your fast help!

Great. Not a problem. BTW I found that the problem was caused by the default dotnet project template (used when executing scripts with the dotnet engine) was always targeting .NET 7. It was a mistake in the code and it ic corrected with the latest release. Executing scripts with csc engine was immune to this problem. BTW in my environment I had no problems because my config is set to -ng:csc.

. . .

Also wanted to thank you for your continuous support. Much appreciated.

oleg-shilo commented 7 months ago

css -nuget:restore "c:\P\zeta-time-tracker\Source\do-build-all.cs"

this is a pure nuget restoring problem. Can you send me the script with all nuget packages references. I will see if it is something that I can reproduce and debug

UweKeim commented 7 months ago

Thank you very much, Oleg!

I've assembled a small test script. The error seems to only occur with NuGet packages coming from our local NuGet server.

I'll send you an example script via email as it includes sensitive data to add the nuget source.

UweKeim commented 7 months ago

Could the issue be that https://github.com/oleg-shilo/cs-script/blob/master/src/cscs/NuGet.Core.cs#L543 hard-coded refers to net7.0 and my NuGet package only generates a net8.0 release in the "lib" folder?

image image

All working NuGet packages seems to omit other folders and not just net8.0 as mine does.

In addition, when searching through the code base, I do find several occurrences of net7 although I'm not quite sure which of them might cause issues:

https://github.com/search?q=repo%3Aoleg-shilo%2Fcs-script%20net7&type=code

oleg-shilo commented 7 months ago

Could be. BTW it is a problem in the code that you found. Restoring is done with the classic dotnet restore command and if the package is only available for net8 and your project is net7 then it will not .

Only two unintended cases of "net7" are still in code but only one (the first you mentioned) is engaged in the execution in your environment.

Let me fix it and send you the patch.

UweKeim commented 7 months ago

Thanks, Oleg. If possible an updated dotnet-tool release would be awesome since this is the way I'm consuming cs-script.

oleg-shilo commented 7 months ago

Yes publishing dotnet-tool is quick. I only want to ensure it works before I do it again. I am working on it right now. There is a good chance that net 7 is the leftover that makes that difference.

oleg-shilo commented 7 months ago

Here we go.

Just place the release manually on your system and test it to see if it addresses the issue.

cs-script.win.v4.8.9.0.zip

UweKeim commented 7 months ago

Just extracted the ZIP to "C:\Ablage\cs-script.win.v4.8.9.0", and changed my "run.cmd" to this:

PUSHD 
CD /d %~dp0 

@REM --

"C:\Ablage\cs-script.win.v4.8.9.0\cscs.exe" -config:set:LegacyNugetSupport=false

"C:\Ablage\cs-script.win.v4.8.9.0\cscs.exe" -nuget:restore "%~dp0\run.cs"

@REM --

POPD
EXIT /B 0

The output looks like this:

c:\Ablage>c:\Ablage\run.cmd

PUSHD

CD /d c:\Ablage\

"C:\Ablage\cs-script.win.v4.8.9.0\cscs.exe" -config:set:LegacyNugetSupport=false
set: LegacyNugetSupport: False

"C:\Ablage\cs-script.win.v4.8.9.0\cscs.exe" -nuget:restore "c:\Ablage\\run.cs"
Restoring packages...
Mapping packages to assemblies...
Compile: OK

POPD

EXIT /B 0

c:\Ablage>

Seems to indicate it is working, right?

oleg-shilo commented 7 months ago

yep, it does

oleg-shilo commented 7 months ago

Will publish it on nuget. Keep fingers crossed 🤞

oleg-shilo commented 7 months ago

done, let nuget to index it and it will be available shortly.

I will take a break now and will check tmr. Let me know how it worked out.

Will do the rest of publishing tmr.

UweKeim commented 7 months ago

Thanks for your continuous, awesome support, Oleg. Most of my DevOps activity over the last decade would have been much harder/impossible without you and your work ❤️.

Слава Україні!

oleg-shilo commented 7 months ago

Героям Слава! My friend.

UweKeim commented 7 months ago

My local scripts seems to work again, mit CI scripts seem to work again. I'm closing this for now.

oleg-shilo commented 7 months ago

Great. We did well. That was a quick turnaround.