简体   繁体   中英

How do you compile C# code using mono embedded in C++?

How do you compile .cs files using C++

I have searched all through Mono's documentation and can't find a way to just compile C# code from the embedded mono runtime in C++. I know how to open a C# .exe assembly file using the embedded mono functions from C++, but I can't seem to find a way to just compile a .cs file to the .exe from C++.

I have also managed to compile the .cs files by calling the mcs.bat file from the CreateProcessA() function that Windows provides, however this does not give me a way to log errors or even check if it succeeded in compilation etc. (It also feels like a hack and not the official solution). The main reason I need to do this is so that I can recompile C# scripts on the fly by detecting when the source code has changed and another subset of conditions.

Does anyone know of a way to properly compile C# files using the embedded Mono runtime? And where to find the documentation for this? Currently I've been using the documentation here: http://docs.go-mono.com/?link=xhtml%3adeploy%2fmono-api-assembly.html which provides enough information for the most part.

Linking Mono in a DLL

Also, if you're familiar with embedding mono, do you know how to use it in a dll? I've managed to successfully link and compile it within a console application, but when I try to compile it as a part of a dynamic library, I get unresolved external symbol errors (specifically functions with the prefix __imp*).

Lastly, I'm using mono to embed C# as a scripting language for my game engine, however I don't know if there is a better (smaller) solution that I can use. If you know of any better solution feel free to leave a recommendation.

The mono runtime is a "Runtime", only for running the code, but if you have installed the csc command then you can use this:

#include <cstdlib>
int main(){
   system("csc yourfile.cs")
   return 0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM