Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I've been researching the CSharpCodeProvider
issue for days everywhere.
I have not been able to find any educational information anywhere.
What is it for, how is it used?
Can you help me with this?


I was able to extract this code snippet with my research, but it doesn't work.
What went wrong


V3 : I don't know how relevant, but I get such a warning, is it relevant?
[url=https://hizliresim.com/Q3LCT7][img]https://i.hizliresim.com/Q3LCT7.png[/img][/url]


What I have tried:

string Output = "Veryfy.exe";
     Dictionary<string, string> version = new Dictionary<string, string>();
     version.Add("CompilerVersion", "v2.0");
     CSharpCodeProvider codeProvider = new CSharpCodeProvider(version);
     ICodeCompiler codeCompiler = codeProvider.CreateCompiler();
     CompilerParameters cp = new CompilerParameters();
     cp.GenerateExecutable = true;
     cp.GenerateInMemory = false;
     cp.MainClass = "Veryfy.Program";
     cp.OutputAssembly =Output ;
     cp.ReferencedAssemblies.Add("system.dll");
     cp.ReferencedAssemblies.Add("system.windows.forms.dll");
     cp.CompilerOptions = "/target:winexe";
     CompilerResults cr = codeCompiler.CompileAssemblyFromSource(cp, Codes());
     foreach (CompilerError item in cr.Errors)
                 {
                     MessageBox.Show(item.ErrorText);
                 }
     }
     string Codes()
     {
         string code = @"
       //Codes
        ";
         code = code.Replace('*', '\"');
         return code;
     }
Posted
Updated 27-Nov-20 14:44pm
v3

Here's an article about it on CodeProject, but it is rather old (2005):
Compiling code during runtime[^]

A more modern alternative might be ScriptCS, the source code can be found on GitHub.
See: tools-for-interactively-writing-c-code-without-having-to-compile-it[^]
 
Share this answer
 
v2
Comments
Furkan Karagülle 27-Nov-20 16:36pm    
I have looked at these tutorials. They are old and not working for me as they have a superficial narrative rather than an experimental that is not fully explained.
Furkan Karagülle 27-Nov-20 20:06pm    
Would you look at v2
RickZeeland 27-Nov-20 23:39pm    
See the updated solution with ScriptCS.
Furkan Karagülle 28-Nov-20 2:09am    
The problem is that I have to compile like this. This is my thesis.
As with most "research type" questions, the place to start is Google: CSharpCodeProvider - Google Search[^]
There are Microsoft links to how to use it, and other links explaining what to use it for, like this one: Compiling code during runtime - Codeproject.com[^]

Start by reading a few articles on it, and see what you can discover. Then start using that to refine your searches to "fill in the gaps" in your understanding.
 
Share this answer
 
Comments
Furkan Karagülle 27-Nov-20 16:36pm    
I have looked at these tutorials. They are old and not working for me as they have a superficial narrative rather than an experimental that is not fully explained.
Furkan Karagülle 27-Nov-20 20:06pm    
Would you look at v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900