Debugging Code After Batch File Reinstall of Plugin

66 views Asked by At

I have a windows forms app that is developed as a plugin for another application. When the parent application starts, the plugin is loaded.

For debugging, the manual process is to:

  1. Make code changes
  2. Rebuild the setup project
  3. Uninstall the application
  4. Re-Install the application
  5. Start debugging (note, VS has "start external program" set on the project and starts the parent application for the plugin at this point)... I have the modules set to load and at this point I can hit new breakpoints on any code changes and debug normally.

The problem starts when I try to add some automation. I wrote a method to prompt the developer on application start if they want to uninstall/build/reinstall the project before continuing debugging. If they choose 'yes' a batch file is created that performs those operations and then the developer is prompted to start debugging again.

PROBLEM HERE: Even though the project has been uninstalled/built/reinstalled, when the developer starts debugging again, the symbols are out of sync, the new code changes get skipped and breakpoints put on the new code are not hit.

How do I make it so (in code) that when the debugger is restarted, it recognizes the code changes and allows for debugging the new code?

Here is my method for performing the work described above:

public static void AskDeveloperIfRebuildReqd()
{
    //app was already rebuilt, just continue with debugging
    if (!Properties.Settings.Default.PromptForDebugRebuild)
    {
        Properties.Settings.Default.PromptForDebugRebuild = true;
        Properties.Settings.Default.Save();
        return;
    }
    
    DialogResult dr = MessageBox.Show("Do you want to rebuild and re-install the plugin for debugging?", "Rebuild?", MessageBoxButtons.YesNo);
    
    if (dr == DialogResult.Yes)
    {
        //--these are relevent directories--
        string projectPath = Environment.CurrentDirectory.Substring(0, Environment.CurrentDirectory.IndexOf("bin"));
        string solnPath = System.IO.Path.GetFullPath(System.IO.Path.Combine(projectPath, @"..\"));
        string setupProjectPath = string.Format("{0}MyDomain.MyProject.Setup", solnPath);
    
        //--these are paths to files used below--
        string solnFile = string.Format("{0}MyDomain.MyProject.sln", solnPath);
        string setupProjectFile = string.Format("{0}\\MyDomain.MyProject.Setup.vdproj", setupProjectPath);
        string msiInstallFile = string.Format("{0}\\Debug\\MyApp.msi", setupProjectPath);
    
        string batFile = string.Format("{0}rebuild.bat", solnPath);
    
        //--these are batch functions--
        //quiet uninstall bat command
        string batUninstallFn = string.Format("MsiExec /uninstall \"{0}\" /quiet", msiInstallFile);
        string batBuildFn = string.Format("devenv \"{0}\" /Project \"{1}\" /Build \"Debug\"", solnFile, setupProjectFile);
        string batInstallFn = string.Format("MsiExec /i \"{0}\" /quiet", msiInstallFile);
    
        //delete the contents of the bat file
        using (System.IO.FileStream fs = new System.IO.FileStream(batFile, System.IO.FileMode.Open)) { fs.SetLength(0); }
    
        //write the batch functions into the file
        using (System.IO.StreamWriter sw = System.IO.File.CreateText(batFile))
        {
            sw.WriteLine(batUninstallFn);
            sw.WriteLine(batBuildFn);
            sw.WriteLine(batInstallFn);
        }
    
        //run the batch file to uninstall/build/reinstall
        System.Diagnostics.Process.Start(batFile).WaitForExit();
    
        Properties.Settings.Default.PromptForDebugRebuild = false;
        Properties.Settings.Default.Save();
    
        MessageBox.Show("Project has been rebuilt, restart debugging", "Restart Debugging");                     
    }
    else
    {
        Properties.Settings.Default.PromptForDebugRebuild = true;
        Properties.Settings.Default.Save();
    }
    
    return;
}

Here's an image of how debugging looks with a newly added string after the above method runs

enter image description here

If I had done the process manually as shown in the steps in the first part of the question, I would be able to see the value for this string.

0

There are 0 answers