Skip to content

Script merger for hosted scripts #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JayBeAl opened this issue Sep 20, 2021 · 14 comments
Closed

Script merger for hosted scripts #254

JayBeAl opened this issue Sep 20, 2021 · 14 comments

Comments

@JayBeAl
Copy link

JayBeAl commented Sep 20, 2021

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
Copy link
Collaborator

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
Copy link
Owner

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:

  • Roslyn does not allow namespaces
  • Roslyn compiles all user-defined classes as nested classes
  • Roslyn compiled assemblies cannot be referenced by other scripts (see CompileCodeWithRefs test). There is something strange there.

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
Copy link
Owner

oleg-shilo commented Sep 24, 2021

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 pushed a commit that referenced this issue Sep 26, 2021
- Issue #254: Script merger for hosted scripts
- Issue #252: System.NullReferenceException: Object reference not set to an instance of an object. (updated API doc)
- Issue #253: Supports both .Net Framework and .Net 5
@oleg-shilo
Copy link
Owner

Prerelease package v4.1.3.0-pre has been just published

@maettu-this
Copy link
Collaborator

maettu-this commented Sep 27, 2021

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
Copy link
Owner

@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
Copy link
Collaborator

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
Copy link
Owner

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

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

@oleg-shilo
Copy link
Owner

Done. All documentation is updated now.

@maettu-this
Copy link
Collaborator

Very good! I have just started reviewing the content.

@maettu-this
Copy link
Collaborator

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
Copy link
Collaborator

maettu-this commented Oct 25, 2021

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
Copy link
Owner

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
Copy link
Collaborator

maettu-this commented Oct 26, 2021

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.

oleg-shilo pushed a commit that referenced this issue Nov 4, 2021
- Updated `-speed` and `-code` with the complete support `-ng:*` switches
- Added `IEvaluator.IsCachingEnabled`. Ite as always available from the conctrete types implementing `IEvaluator` and now it is moved directly to the interface.
- Added `-servers:start` and `-servers:stop` command to control both Roslyn and csc build servers at the same time
- CSScriptLib: Native API `CacheEnabled` marked as obsolete
- Issue #258: Can not run scripts after installing VS2022
- Issue #257: Ability to catch AppDomain.UnhandledException in a not-hosted script (cscs)
- Issue #255: Relative path for cscs.exe -out option results in wrong output folder
- Issue #254: Script merger for hosted scripts
- Issue #253: Supports both .Net Framework and .Net 5
- Issue #252: System.NullReferenceException: Object reference not set to an instance of an object. (updated API doc)
- Added auto-generation of the CLI MD documentation with `-help cli:md`. To be used to generate GitHub wiki page during the build
- Fixed Debian packaging problem (`/n/r` needed replacement with `\n`)
oleg-shilo added a commit that referenced this issue Nov 14, 2021
### Misc

- Added auto-generation of the CLI MD documentation with -help cli:md. To be used to generate GitHub wiki page during the build
- Fixed Debian packaging problem (/n/r needed replacement with \n)
- Issue #253: Supports both .Net Framework and .Net 5

### CLI

- Updated -speed and -code with the complete support -ng:* switches
- Added -servers:start and -servers:stop command to control both Roslyn and csc build servers at the same time
- Issue #258: Can not run scripts after installing VS2022
- Issue #257: Ability to catch AppDomain.UnhandledException in a not-hosted script (cscs)
- Issue #255: Relative path for cscs.exe -out option results in wrong output folder
- Issue #254: Script merger for hosted scripts
- Issue #252: System.NullReferenceException: Object reference not set to an instance of an object. (updated API doc)

### CSScriptLib

- Native API CacheEnabled marked as obsolete
- Added IEvaluator.IsCachingEnabled. It is always available from the concrete types implementing IEvaluator and now it is moved directly to the interface.
@maettu-this maettu-this mentioned this issue Dec 1, 2021
59 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants