How to hide the console?

Hello,
Make the app in C#, the dynamic compiler creates a software in the console.
The question how to compile this software as a form or hide whatever at startup could not see the console?

string source =
@"
namespace Program
{
 static void Main(string[] args)
{
}
}
";



 Dictionary<string, string> providerOptions = new Dictionary<string, string> 
 { 
 {"CompilerVersion", "v4.0"} 
};
 CodeDomProvider provider = new CSharpCodeProvider();
 CompilerParameters compilerParams = new CompilerParameters { OutputAssembly = "name.exe", GenerateExecutable = true };
 CompilerResults results = provider.CompileAssemblyFromSource(compilerParams, source);</string></string>


Maybe you need the settings written in "compilerParams" but what? Searched the Internet and found only how to compile, parameters, nothing was said
June 10th 19 at 14:28
2 answers
June 10th 19 at 14:30
Solution
Property CompilerOptions your CompilerParameters need to specify /target:winexe

Only it's only change the type of generated exe file. As in options VS
756783
And otobrazheniya forms you will need code similar to:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());

And loaded dependent assemblies that are required for Windows Forms
Thank you, you helped me. Can I ask another question?
Why when I enter the code
System.Net.HttpWebRequest httpReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(""$link$"");
 httpReq.AllowAutoRedirect = false;
 System.Net.HttpWebResponse httpRes = (System.Net.HttpWebResponse)httpReq.GetResponse();
 if (httpRes.StatusCode == System.Net.HttpStatusCode.OK)

in peremennoy source, that is, code that needs skompilirovana.
I have an error: ERROR The type or namespace 'Net' does not exist in the namespace 'System' (are you missing an assembly reference?)

I already introduced "compilerParams.ReferencedAssemblies.Add("System.Net.dll");" and used "using" still does not help. - carmel15 commented on June 10th 19 at 14:33
So WebRequest is system.dll and not System.Net.dll - candida_Upton commented on June 10th 19 at 14:36
June 10th 19 at 14:32
Solution
And what for such complexity, Compile in memory and create a class from an Assembly and calling a method via reflection.
here's an example:
streletzcoder.ru/osnovyi-kompilyatsii-i-vyipolneni...
well, or for Roslin:
www.tugberkugurlu.com/archive/compiling-c-sharp-co...

PS: Want will teach you to look in Yandex or Google, I found in two minutes.
Thanks for the reply, can another question to help?
Why when I enter the code
System.Net.HttpWebRequest httpReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(""$link$"");
 httpReq.AllowAutoRedirect = false;
 System.Net.HttpWebResponse httpRes = (System.Net.HttpWebResponse)httpReq.GetResponse();
 if (httpRes.StatusCode == System.Net.HttpStatusCode.OK) ...

in peremennoy source, that is, code that needs skompilirovana.
I have an error: ERROR The type or namespace 'Net' does not exist in the namespace 'System' (are you missing an assembly reference?)

I already introduced "compilerParams.ReferencedAssemblies.Add("System.Net.dll");" and used "using" still does not help. - carmel15 commented on June 10th 19 at 14:35
,
I already introduced "compilerParams.ReferencedAssemblies.Add("System.Net.dll");" and used "using" still does not help.

and at the same time did not try? everything works.
using Microsoft.CSharp;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
 class Program
{
 static void Main(string[] args)
{
 string source =
@"
using System.Net;

namespace App
{
 class Programm
{
 static void Main(string[] args)
{
 // HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(""http://localhost"");
}
}
}
";



 Dictionary<string, string> providerOptions = new Dictionary<string, string>
{
 {"CompilerVersion", "v4.0"}
};
 CodeDomProvider provider = new CSharpCodeProvider();
 CompilerParameters compilerParams = new CompilerParameters { OutputAssembly = "name.exe", GenerateExecutable = true };
compilerParams.ReferencedAssemblies.Add("System.Net.dll");
 CompilerResults results = provider.CompileAssemblyFromSource(compilerParams, source);
 if (results.Errors.Count > 0)
{
 Console.WriteLine("not ok");
}
else
{
 Console.WriteLine("All ok");
}
Console.ReadKey();
}
}
}</string></string>
- candida_Upton commented on June 10th 19 at 14:38
and so, too, was trying to do, it gives an error: ERROR The type name 'HttpWebRequest' could not be found. This type has been forwarded to assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken="b77ad265421s653'. Consider adding a reference to that assembly. - carmel15 commented on June 10th 19 at 14:41
,
HttpWebRequest is now in System.dll

compilerParams.ReferencedAssemblies.Add("System.dll");
- Josef commented on June 10th 19 at 14:44
well , now everything is clear, thank you) - carmel15 commented on June 10th 19 at 14:47
There is such a thing, mark as a solution this is a good thing thank you for the Toaster - Josef commented on June 10th 19 at 14:50

Find more questions by tags C#