我最近在 WPF 中创建了一个应用程序。
我希望能够更改应用程序徽标、表单标题并从将 WPF 应用程序从源文件编译为可执行文件的生成器(winforms 应用程序)进行其他自定义
有人可以展示一个关于如何使用 C# 编译 WPF 应用程序的代码示例吗?我知道如何使用编译.cs
源文件,CSharpCodeProvider
但是否可以使用 CodeProvider 从源文件编译 WPF?
Anyhelp将不胜感激
你需要看看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.");
}
}