This article is a mirror article of machine translation, please click here to jump to the original article.

View: 30296|Reply: 1

[Source] Use JSC to generate a dll in JavaScript for C# calls

[Copy link]
Posted on 2020-12-2 12:47:18 | | | |
Requirements: When we simulate HTTP requests, the request parameters and request content may involve some algorithm content, the algorithm can be found from JavaScript, if we translate the js algorithm into the programming language we use (e.g., Java, C#), it is more difficult, usually the js content is compressed and confused, so if we directly translate js into a class library for us to call, it is very good.

Utilize Jurassic to execute js functions under .net
https://www.itsvse.com/thread-4303-1-1.html
Use JSC to generate the exe program in JavaScript

test1.js code is as follows:

Open the VS 2019 developer command and enter the following:

Try to run the main.exe program, we run the program through the cmd command, double-click directly, and the program will flash by, as follows:



Use JSC to generate a dll library of JavaScript

test.js code is as follows:

The command is as follows:

Create a new .NET 4 console project that references the common.dll class library

Then instantiate the object and call its method. The code is as follows:


As shown below:



You can use the ILSpy tool to view the generated dll source code, as shown in the figure below:



jsc program file path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\jsc.exe

Parameter:

Microsoft (R) JScript Compiler version 14.00.3752
for Microsoft (R) .NET Framework version 4.0.30319
Copyright (C) Microsoft Corporation. All rights reserved.

jsc [options] <源文件> [[options] <源文件>...]

                         JScript compiler options

                           - Output File -
  /out:<file> Specifies the name of the binary output file
  /t[arget]:exe Create console application (default)
  /t[arget]: winexe to create a Windows application
  /t[arget]: library creates a library assembly
  /platform:<platform> Restricts the platforms on which this code can be run; Must be x86, Itanium, x64, or Any CPU (default platform)

                           - Input File -
  /autoref[+|-] Auto-reference assemblies based on imported namespaces and fully qualified names (on by default)
  /lib:<path> Specifies the additional directory in which you want to search for references
  /r[eference]:<file list> References metadata from the specified assembly file
                           <file list>: <assembly name>[; <assembly name>...]

                           - Source -
  /win32res:<file> Specifies Win32 resource files (.res)
  /res[ource]:<info> Embed the specified resource
                           <info>: <filename>[,<name>[,public|private]]
  /linkres[ource]:<info> Links the specified resource to this assembly
                           <info>: <filename>[,<name>[,public|private]]

                           - Code generation -
  /debug[+|-] to issue a debug message
  /fast[+|-] disables language features to make code better generation
  /warnaserror[+|-] treats the warning as an error
  /w[arn]:<level> Set the warning level (0-4)

                           - Miscellaneous -
  @<filename> For more options, please read the response file
  /?                       Show help
  /help shows help
  /d[efine]:<symbols> Defines conditional compilation symbols
  /nologo does not display the compiler copyright mark
  /print[+|-] provides the print() function

                           - Advanced -
  /codepage:<id> Open the source file with the specified code page ID
  /lcid:<id> Use the specified LCID for messages and default code pages
  /nostdlib[+|-] does not import the standard library (mscorlib.dll) and changes the autoref default to off
  /utf8output[+|-] emits compiler output in UTF-8 character encoding
  /versionsafe[+|-] specifies a default value for members that are not marked as "override" or "hide"
(End)




Previous:ASP.NET Core (iii) Dynamically create instances using ActivatorUtilities
Next:Python uses http.server to open an http service
Posted on 2022-8-16 16:58:13 |
Learn to learn
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com