Note that there are some explanatory texts on larger screens.

plurals
  1. POExecute JavaScript from within a C# assembly
    text
    copied!<p>I'd like to execute JavaScript code from within a C# assembly and have the results of the JavaScript code returned to the calling C# code.</p> <p>It's easier to define things that I'm not trying to do:</p> <ul> <li><p>I'm not trying to call a JavaScript function on a web page from my code behind.</p></li> <li><p>I'm not trying to load a WebBrowser control.</p></li> <li><p>I don't want to have the JavaScript perform an AJAX call to a server.</p></li> </ul> <p>What I want to do is write unit tests in JavaScript and have then unit tests output JSON, even plain text would be fine. Then I want to have a generic C# class/executible that can load the file containing the JS, run the JS unit tests, scrap/load the results, and return a pass/fail with details during a post-build task.</p> <p>I think it's possible using the old ActiveX ScriptControl, but it seems like there ought to be a .NET way to do this without using SilverLight, the DLR, or anything else that hasn't shipped yet. Anyone have any ideas?</p> <p>update: <a href="http://blogs.msdn.com/brada/articles/239857.aspx" rel="nofollow noreferrer">From Brad Abrams blog</a></p> <pre><code>namespace Microsoft.JScript.Vsa { [Obsolete("There is no replacement for this feature. " + "Please see the ICodeCompiler documentation for additional help. " + "http://go.microsoft.com/fwlink/?linkid=14202")] </code></pre> <p>Clarification: We have unit tests for our JavaScript functions that are written in JavaScript using the JSUnit framework. Right now during our build process, we have to manually load a web page and click a button to ensure that all of the JavaScript unit tests pass. I'd like to be able to execute the tests during the post-build process when our automated C# unit tests are run and report the success/failure alongside of out C# unit tests and use them as an indicator as to whether or not the build is broken.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload