AddInProcess.exe is main culprit in this case. So here is some background and explanation on some crude modifications that were made to make it work; maybe you could do it as appropriate for your scenario.
When the debug is kicked in the first time. AddInProcess.exe comes into existence. When the debug run ends, add-in process is still alive (When you kick the build after making changes notice process list it shows the addin process) hence when we do a build the copy operation of the dll fails. To work around this, the VstaDesigntimeIntegration.cs was modified as below.
On build begin just ensure that if the add-in process is alive it is killed so that the next debug session doesn’t load the old dll. To help in debugging and assist in state determination, the file copy operation was explicitly made in the code as below, InstallAddIn.js also might work after the addin-process fix but it hasn’e been verified. You might want to pick file paths below from project properties.
private void buildEvents_OnBuildDone(EnvDTE.vsBuildScope Scope, EnvDTE.vsBuildAction Action)
{
try
{
if (macroAddInProcess != null)
{
this.macroAddInProcess.Shutdown();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
if (dte.Solution.SolutionBuild.LastBuildInfo == 0)
{
// Build was successful.
}
else
{
MessageBox.Show(
"Macro project build failed.",
"ShapeAppCSharp",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
// Load Macros since they were unloaded in OnBuildBegin event.
// This will load the last good Macro AddIn if the built failed.
MessageBox.Show("Loading the macros in proc now as build done event complete");
MakeSureUpdatedAssembly();
this.application.VstaRuntimeIntegration.LoadMacrosInProcess();
}
private void MakeSureUpdatedAssembly()
{
try{
File.Copy(@"C:\Documents and Settings\Administrator\My Documents\ShapeAppCSharp\Macros\bin\Release\ShapeAppMacros.dll", @"C:\Documents and Settings\Administrator\My Documents\ShapeAppCSharp\MacroAddIns\ShapeAppMacros.dll", true);
}
catch(Exception ex)
{
MessageBox.Show("File.Copy failed");
MessageBox.Show(ex.Message);
}
}
The VstaMacroHelper.cs was also modified to do clean up on debug start
internal void StartDebugging()
{
//starts debugger, which loads macroaddin and executes selected macro
Thread t = new Thread(() =>
{
this.application.VstaDesignTimeIntegration.CleanupOnBuildBegin();
this.application.VstaDesignTimeIntegration.dte.Debugger.Go(false);
});
t.SetApartmentState(Thread.CurrentThread.GetApartmentState());
t.Start();
}
Introduced CleanUpOnBuildBegin in VstaDesigntimeIntegration.cs as below :
void buildEvents_OnBuildBegin(EnvDTE.vsBuildScope Scope, EnvDTE.vsBuildAction Action)
{
CleanupOnBuildBegin();
}
internal void CleanupOnBuildBegin()
{
// Unload the AddIn first because if we are debugging ShapeAppCSharp
// the AddIn PDB is locked and the AddIn could give build errors.
this.application.VstaRuntimeIntegration.UnloadCurrentMacroAddin(false);
MessageBox.Show("Now deleting the pdb");
// Make sure that the debugger's lock on the PDB file has been released by
// deleting the Macro AddIn PDB files, so that we can rebuild the project.
DeleteMacroPdb();
}
Posted
May 22 2009, 01:57 PM
by
BillL