This topic is now archived and is closed to further replies.

Hosting the CLR (.Net)

This topic is 5577 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve been reading about hosting the CLR, and how to setup it and create domains, then load some .Net assemblies. I also read a little bit about Reflection.Emit which I believe how you would hook-in a custom scripting language. I''m kinda lazy though, I would rather not go through all the trouble of making a custom compiler & language if I can just have clients use C#. Is there anything in the framework to compile .cs source files? Or do you have to buy Visual Studio and use it''s compiler? I see there''s a new VSA .Net SDK (comparable to the old VBA SDK), does anyone know how much this beast cost? What are the viable options for integrating .Net scripting into a game (or other non-multi-billion dollar software)? ... Ah cool, I was looking for this Friday: NI Measurement Studio for .Net

Share this post

Link to post
Share on other sites
I guess it''s kind-of a stupid question - I''m looking for a way to compile C# code without Visual Studio.

Everything I read about requires the end-user to buy a license for it.

Seems the simplest thing to do is make a Visual Studio .Net Add-In. The VSI/VSIP/VSA look like they cost a small fortune.

Share this post

Link to post
Share on other sites
Magmai, take a look at this: This is a class I wrote to use as a scripting engine in a project I am working on. It uses the Microsoft.*.Vsa namespaces to support JScript.NET as a scripting language. All these classes are in the framework, so theres no extra download. However, the documentation is sort of sparse.
I am sort of tired now, but the class should be fairly well commented. If you have any questions, just post them and I''ll take a look tomorrow.

"When you know the LORD you have no need for masturbation!"

Share this post

Link to post
Share on other sites

System.CodeDom.Compiler.ICodeCompiler compiler = new Microsoft.CSharp.CSharpCodeProvider().CreateCompiler();
System.CodeDom.Compiler.CompilerResults results;
System.Reflection.Assembly compiledAsm;

//this compiles from a string...
results = compiler.CompileAssemblyFromSource(new System.CodeDom.Compiler.CompilerParameters(),
@"namespace test { public class myTest { public int Foo; } }");

//results.Errors - all compile errors...
//results.CompiledAssembly...if compilation is successful the assembly to late-bind to
compiledAsm = results.CompiledAssembly;

//or this to compile from a file
results = compiler.CompileAssemblyFromFile(new System.CodeDom.Compiler.CompilerParameters(), @"C:\script.cs");


[edit: a line of code was too long, broke into two lines]

[edited by - Magmai Kai Holmlor on September 3, 2002 2:23:37 PM]

Share this post

Link to post
Share on other sites
Now, if you could help me limp along here; I know you use #using to access .Net stuff in C++, but how do you figure out what to #use?

You have to have a #using <mscorlib.dll>, but what/where do I find what to add to access CodeDOM?

#using <System.CodeDOM.dll> doesn't work...
nor does #using <Microsoft.CSharp.dll> or #using <Microsoft.CSharp.CSharpCodeProvider.dll>

Ahh nevermind, it appears everything is brought in by #using <System.dll>

[edited by - Magmai Kai Holmlor on September 3, 2002 2:56:12 PM]

Share this post

Link to post
Share on other sites
To answer this in general: READ THE DOCUMENTATION.

When I look at the description of a class, it tells me at the lower end of the page:

(a) which namespace the class resides in and
(b) which dll contains the class.


Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)

Share this post

Link to post
Share on other sites