Add-Ins in Visual Studio

Common Error

If you get the error Unable to copy file "obj\Debug\MyAssembly.dll" to "bin\MyAssembly.dll". The process cannot access the file 'bin\MyAssembly.dll' because it is being used by another process, here's how to fix it.

Add the following text to the pre-build event command line (found in Project Properties).

{copytext|div1}
if exist "$(TargetPath).locked" del "$(TargetPath).locked"
if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"

Walkthrough


public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst,
    ref Array custom)
{
    InitAddIn(application, connectMode, addInInst);
}
//-------------------------------------------------------------------------------------------------
public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
{
    if (disconnectMode != ext_DisconnectMode.ext_dm_UISetupComplete)
    {
        DeleteToolbar();
    }

}
//-------------------------------------------------------------------------------------------------
public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref 
    vsCommandStatus status, ref object commandText)
{
    if(neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
    {
        bool bEnabled = true;
        bool bHidden = false;

        QueryStatus(commandName, ref bEnabled, ref bHidden);
        status = (vsCommandStatus)(
            vsCommandStatus.vsCommandStatusSupported 
            | 
            (bEnabled? vsCommandStatus.vsCommandStatusEnabled : 0)
            |
            (bHidden? vsCommandStatus.vsCommandStatusInvisible : 0)
            );
        return;
    }
}
//-------------------------------------------------------------------------------------------------
public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, 
    ref object varOut, ref bool handled)
{
    handled = false;
    if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
    {
        Execute(commandName, ref handled);
    }
}