oleg-shilo / cs-script

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

Script merger for hosted scripts #254

Closed JayBeAl closed 2 years ago

JayBeAl commented 3 years ago

Hello Oleg,

first of: thank you for your continued work on the cs-script project, I am using it to host scripts in a desktop application to provide a scripting interface for users. I am going with the Roslyn compiler so that users won't need an additional SDK. For ease of mantainance I´d like to deploy scripts with multiple files, which is not natively possible with the Roslyn compiler according to your documentation. However, I have seen that you have included script merging in the CLI version of CS-Script. Is there any reason why this feature is only available in the CLI version? Do you plan to include this script merger in the hosting version as well?

maettu-this commented 2 years ago

Came across @JayBeAl's issue by accident and would like to express the same need.

My hosting application is used in a testing environment with almost a thousand test script files. They are available in a Visual Studio solution. Each top-level script has its own namespace. css_import (934 occurences) as well as css_reference (20 occurences) is used to combine the top-level and helper scripts into larger scopes.

The largest scope consists of approx. 500 files. The top-level Device imports all of them. The files implement the vendor specific command sets of a family of devices. Many scripts use that Device.

Another scope consists of approx. 100 files. Each file implements a specific test of a compliance regulation. 6 top-level scripts sequentially run the tests, depending on regulation variant.

In both cases, a single blob or not using namespaces would be totally unmaintainable.

oleg-shilo commented 2 years ago

It's a difficult one. Roslyn has quite a few critical limitations so I made the decision not to overinvest as the value would be very limited.

There is no workaround for these limitations:

But, if your hosting scenario is not impacted by these limitations then indeed multi-scripting can be achieved.

I am actually working on it :)

oleg-shilo commented 2 years ago

Done. Will release it as a pre-release so can be tested before going fully public.

var dependencyScript ="calc.cs";

File.WriteAllText(dependencyScript, @"using System;
                                      public class Calc
                                      {
                                          static public int Sum(int a, int b)
                                          {
                                              return a+b;
                                          }
                                      }");

dynamic script = new_evaluator.LoadCode($@"//css_inc {dependencyScript}
                                           using System;
                                           public class Script
                                           {{
                                               public int Sum(int a, int b) => Calc.Sum(a ,b);
                                           }}");

var result = script.Sum(7, 3);
oleg-shilo commented 2 years ago

Prerelease package v4.1.3.0-pre has been just published

maettu-this commented 2 years ago

Good to see the css_* directives also with Roslyn, even though the Roslyn limitations still are a no-go for my hosting application. I ask you to also update the documentation accordingly. In the past, https://github.com/oleg-shilo/cs-script/wiki/Choosing-Compiler-Engine mentioned something about the css_* support of the different engines. Also, CSScript.chm listed them:

Help on css_

And as stated at the top of the above link, the content is yet partial only. If you like, I would be available for reviewing the content and giving suggestions on the missing pieces of information, especially regarding hosting, where currently nothing is stated about css_* directives.

oleg-shilo commented 2 years ago

@maettu-this sorry for getting back to you with such a delay.

You are right I will need to update that article with the new support for //css_*. Though that CSScript.chm is legacy documentation for CLI only. So it is not exactly suitable for describing hosted scenarios. Meaning that it needs to be done on the wiki.

Yes, it would be great if you can scan the document for obvious gaps. The original documentation was for .NET Framework editions of both CS-Script CLI and hosted library.

Since CS-Script has switched to the .NET5 edition the documentation needs to be reviewed and updated where required (e.g. gaps). All wiki docs that are not reviewed yet are marked as partial.

Finding time is very challenging for me :( I am struggling to allocate enough time to maintain all me OSS projects. So I oscillate between all of them. Now I am mainly on WixSharp. But CS-Script will be the very next.

maettu-this commented 2 years ago

Easy, no need to hurry, I fully understand the time constraints such OSS projects mean. Not seeing css_ directives in the documentation just makes me uneasy sometimes, knowing that in my environment tons of them are around. Not being able to upgrade my hosting application to .NET 5 for this reason would mean a nightmare to me... But I guess as long as the CodeDom engine is still around I should be safe.

Just let me know once content is ready to be reviewed. I will then look at it thoroughly and report my findings.

oleg-shilo commented 2 years ago

I gave it an extra push and started updating the documentation.

The wiki pages that are already processed are marked with (+) image

oleg-shilo commented 2 years ago

Done. All documentation is updated now.

maettu-this commented 2 years ago

Very good! I have just started reviewing the content.

maettu-this commented 2 years ago

I thought to propose changes directly in .md. But I don't know how to create a PR for the wiki, nor I am able to push to a branch of it:

Failed to push the branch to the remote repository. See the Output window for more details.
Pushing branches/maettu_this_review_1
Error encountered while pushing branch to the remote repository: Git failed with a fatal error.
Git failed with a fatal error.
unable to access 'https://github.com/oleg-shilo/cs-script.wiki.git/': The requested URL returned error: 403

Failed to push the branch to the remote repository. See the Output window for more details.

Maybe you can give me a hint, or I will try finding a solution tomorrow. If it is not possible, I will just zip to files and attach them here, but not really ideal...

maettu-this commented 2 years ago

According to e.g. https://stackoverflow.com/questions/10642928/how-to-pull-request-a-wiki-page-on-github, PR are not supported on the wiki and would require some sort of workaround. Let me know which way you perfer: zip/attach here, share via dropbox or the like, grant access to the wiki's git (branches only) and you can merge, have me clone the wiki to my account and you can merge from there,...

Somewhat strange, that GitHub doesn't support an easy collaboration model on the wiki...

oleg-shilo commented 2 years ago

There is a simpler way :) I added you as a collaborator. The invite is in your inbox You will be able to push your branch on wiki repo and I will do the merger. If for whatever reason it does not work you will be able to update wiki directly as well.

maettu-this commented 2 years ago

Alright, you should now see branches/maettu_this_review_1. It's just a first shot to try the process. The changes yet only involve spell check and whitespace. Please review and merge as you agree. When ready again, I will carefully read through the content of all pages and check for semantics.

PS on trailing whitespace: I am aware that markdown supports two spaces = line break. But a) I think this feature should be avoided and b) it didn't seem consistently used in the wiki markdown. Still, proposing to take a close look at the proposed changes.