0

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

1

1 Answer 1

3

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.");
    }
}
Sign up to request clarification or add additional context in comments.

4 Comments

where can i find the generated exe ?
It will be in the Bin/Release folder of where you solution file is located.
the code executes but nothing happens ?! I can't see the file in the release folder
You need to make sure that you have set string workingDirectoryPath = "PathToYourSolutionFile", where "PathToYourSolutionFile" is the actual path of where your solution file is located. This is very important.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.