简体   繁体   中英

Compile a WPF application from a source file using C#?

I recently created an application in WPF.

I want to be able to change the application Logo, The Form title and make other customizations from a Builder (winforms app) that compiles the WPF application from source file to Executable

Could someone please show a code example on how can I compile a WPF application using C# ? I know how to compile a .cs source file using CSharpCodeProvider but is it possible to use the CodeProvider to compile a WPF from source file ?

Anyhelp would be highly appreciated

You need to have a look at 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.");
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM