2012-06-06 8 views
0

디스크의 다른 폴더에있는 .cs 프로그램을 컴파일하고 다른 프로그램을 사용하여 .dll 파일을 생성하고 싶습니다. cs 프로그램 또는 콘솔 응용 프로그램 또는 창 응용 프로그램. 당신이 뭔가 콘크리트 당신은 CS 파일에에서이 호출 할 수 있습니다다른 .cs 프로그램에서 디스크의 다른 폴더에있는 .cs 파일을 컴파일하십시오.

Process processCS= new Process(); 
processCS.StartInfo.WorkingDirectory = @"C:\<your code directory>"; 
processCS.StartInfo.FileName = @"C:\Windows\Microsoft .NET\Framework\version\csc.exe /out:yourdllname.dll yourcodefilename.cs"; 
processCS.StartInfo.CreateNoWindow = true; 
processCS.Start(); 
processCS.WaitForExit(); 

이 다른 CS 파일을 컴파일하려고 찾을 수없는 때까지 나는이 같은 아이디어 뭔가를 다음

using (StreamReader textReader = new StreamReader(@"path\Filename.cs")) 
{ 
    textFile = textReader.ReadToEnd(); 
    Console.WriteLine(textFile); 
} 
CodeDomProvider codeProvider = new CSharpCodeProvider(); 
ICodeCompiler compiler = codeProvider.CreateCompiler(); 
// add compiler parameters 
CompilerParameters compilerParams = new CompilerParameters(); 
compilerParams.CompilerOptions = "/target:library /optimize"; 
compilerParams.GenerateExecutable = false; 
compilerParams.GenerateInMemory = true;    
compilerParams.IncludeDebugInformation = false; 
compilerParams.ReferencedAssemblies.Add("mscorlib.dll"); 
compilerParams.ReferencedAssemblies.Add("System.dll"); 
// compile the code 
CompilerResults results = compiler.CompileAssemblyFromSource(compilerParams,  textFile); 
+2

무엇이 문제입니까? –

+0

여러분은 여기에서 모든 편집 작업을하면서 정말 엉망이되었습니다. –

+0

간단히 말해 C#에서'.cs' 파일을 컴파일하고 싶습니까? 그래서 작동하지 않는 것은 무엇입니까? –

답변

0

를 사용했습니다. 그렇게된다면 그렇게 그렇게하려면 다음 코드를 사용을 System32 디렉토리에있는 파일을 검색합니다 기본 프로세스에 의해

\ .... 확인 ...

ProcessStartInfo info = new ProcessStartInfo(@"C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe"); 
info.Arguments = @" /out:C:\ss\Class1.dll C:\ss\Class1.cs"; 
info.UseShellExecute = false; 
Process.Start(info); 

을 인수 내가 CS 파일의 경로를 준 C : \ ss \ Class1.cs와 같이 경로에 따라 줄 수 있지만 작은 경로를 명심하십시오.

+0

이 작동하지 않습니다. 지정된 경로를 찾을 수 없습니다. 3 행에서 는 무슨 뜻입니까? – user1379584

+0

디버그하고 경로 복용을 확인하고 그에 따라 경로를 변경하십시오 – Infinity

+0

파일 위치에 따라 경로를 변경하십시오.이 작업을 수행 할 수 있습니다 ... 지금 실행하지 않아도 컴퓨터에 Windows가 없습니다. 코드 ... 나는 집에 가서 그것을 할 수 있습니다 ... 당신이 기다려야 만 ...하지만 당신이 코드를 디버그하고 accrodingly 그것을 작동합니다 변경 – Infinity

관련 문제