2

I am coding a C# Winforms application where the user can create and run their own dynamic scripts using the CSharpCodeProvider class.

I have this working successfully with simple code (as a string), and multiple class files (external files), yet am not sure on how to load a whole C# project and successfully compile and invoke the code.

I have done some research and cannot find the required information, such as a tutorial or some example code.

I am using a WinForms application, with a simple form and button as an example of a C# project to compile and invoke.

Can someone please tell me the source files that I need to add to get a whole C# project compiling and invoking correclty? Do I need to include the .resx as well as the .Designer.cs files? Also, are there specific referenced assemblies that I need to add?

Simon
  • 7,991
  • 21
  • 83
  • 163
  • 2
    I think you just have to emulate `msbuild` in your application. How visual studio compiles the code? It just calls `csc.exe` with specific parameters. Watch these parameters and use `Process.Start` to do the same thing. – Alex Zhukovskiy Jan 29 '16 at 07:56

1 Answers1

0

A CSharp project file is an MSBuild build script.

If you are essentially allowing your users to create their own macros or scripts as extensions for your product, you shouldn't worry about using a .csproj file. What you are doing is fine for that purpose.

If you want to go beyond macros and scripts, and allow your users to create and share plugins as DLLs, then you should probably give them a template project and advise them to use Visual Studio Community Edition to create the DLLs.

Ben
  • 34,935
  • 6
  • 74
  • 113