我最近在WPF中创建了一个应用程序。
我希望能够更改应用程序徽标,表单标题,并从构建器(winforms应用程序)进行其他自定义,将WPF应用程序从源文件编译为可执行文件
有人可以显示代码示例,了解如何使用C#编译WPF应用程序?我知道如何使用.cs
编译CSharpCodeProvider
源文件,但是可以使用CodeProvider从源文件编译WPF吗?
Anyhelp将受到高度赞赏
答案 0 :(得分:3)
您需要查看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.");
}
}