2013-02-23 88 views
0

我最近在WPF中创建了一个应用程序。

我希望能够更改应用程序标识,窗体标题,并从一个Builder(WinForms应用程序)进行其他自定义,编译从源文件中的WPF应用程序的可执行使用C#从源文件编译WPF应用程序?

可能有人请显示的代码示例关于如何使用C#编译WPF应用程序?我知道如何使用CSharpCodeProvider编译.cs源文件,但是可以使用CodeProvider从源文件编译WPF吗?

Anyhelp将高度赞赏

+0

您正在寻找使用CSC.EXE是中包含的内容.NET框架的例子吗? http://msdn.microsoft.com/en-us/library/vstudio/78f4aasd.aspx – kenny 2013-02-23 15:34:23

回答

2

你需要看看MSBuild

using (System.Diagnostics.Process process = new System.Diagnostics.Process()) 
{ 
    string workingDirectoryPath = "PathToYourSolutionFile" 
    string resultsFileMarker = workingDirectoryPath + @"\DotNetBuildResult.txt"; 

    process.StartInfo.FileName = @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"; 
    process.StartInfo.Arguments = @"YourSolutionName.sln /nologo /fileLogger /fileloggerparameters:errorsonly;LogFile=""" + resultsFileMarker + @""" /noconsolelogger /t:clean;rebuild /verbosity:normal /p:Configuration=Release;Platform=x86"; 
    process.StartInfo.WorkingDirectory = workingDirectoryPath; 
    process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; 
    process.Start(); 
    process.WaitForExit(); 
    process.Close(); 
    process.Dispose(); 

    using (StreamReader resultsStreamReader = new FileInfo(resultsFileMarker).OpenText()) 
    { 
     results = resultsStreamReader.ReadToEnd(); 
    } 

    if (results.Trim().Length != 0) 
    { 
     System.Diagnostics.Process.Start(resultsFileMarker); 
     errorEncountered = true; 
     throw new Exception("Error were errors rebuilding the .Net WPF app - please check the log file that has just opened."); 
    } 
} 
+0

哪里可以找到生成的exe文件? – 2013-02-23 14:32:44

+0

它将位于解决方案文件所在的Bin/Release文件夹中。 – Willem 2013-02-23 14:42:38

+0

代码执行但没有任何反应?!我无法在发布文件夹中看到该文件 – 2013-02-23 15:15:48