visual-studio-2010visual-studiovisual-studio-addinsbuild-eventserror-list

Show ErrorList Windows in Visual Studio 2010 Addin


I have Win7 64 bits, Visual Studio 2010, and I have developed an Addin for Vs2010.

I try show messages in Error List Windows VS.
I use ErrorListProvider in OnBuildProjConfigDone build event for Addin

this._buildEvents.OnBuildProjConfigDone += new _dispBuildEvents_OnBuildProjConfigDoneEventHandler(_buildEvents_OnBuildProjConfigDone);

I get this error InvalidOperationException

The service 'Microsoft.VisualStudio.Shell.Interop.IVsTaskList' must be installed for this feature to work. Ensure that this service is available.

Connect

 public partial class Connect : IDTExtensibility2, IDTCommandTarget, System.Windows.Forms.IWin32Window, IOleCommandTarget

OnBuildProjConfigDone

void _buildEvents_OnBuildProjConfigDone(string project, string projectConfig, string platform, string solutionConfig, bool success)
{

// Omitted
 if (!resul)
 {
                project.DTE.ExecuteCommand("Build.Cancel");

                var errorListHelper = new ErrorListHelper();
                ErrorListProvider errorProvider = errorListHelper.GetErrorListProvider();
                var newError = new ErrorTask();
                newError.ErrorCategory = TaskErrorCategory.Message;
                newError.Category = TaskCategory.BuildCompile;
                newError.Text = "Cualquier mensaje de error aqui";
                errorProvider.Tasks.Add(newError);
 }
}      

ErrorListHelper

public class ErrorListHelper : System.IServiceProvider
{
    public ErrorListProvider GetErrorListProvider()
    {
        ErrorListProvider provider = new ErrorListProvider(this);
        provider.ProviderName = "Provider";
        provider.ProviderGuid = System.Guid.NewGuid();
        return provider;
    }

    public object GetService(Type serviceType)
    {
        return Package.GetGlobalService(serviceType);
    }
}

Suggestion by @JohnL: I put a breakpoint in my GetService method and Package.GetGlobalService is returning null.

Any suggestions?


Solution

  • Ryan Molden (MSFT) says:

    Package.GetGlobalService is relying on at least one MPF package (from the specific version of MPF you are referencing) having been loaded. Since you yourself are an AddIn not a Package you can't guarantee that in any way.

    You should pass something like new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider))) as the argument to ErrorListProvide

    Package.GetGlobalService is returning null.

    I use this code in my Addin. I test it and I get not error, and I can show errors and warnings in ErrorList Windows VS. I'll testing more for safely.

     public partial class Connect
        {
            ErrorListProvider _errorListProvider = null;
    
            void CreateErrorListProvider()
            {
                if (_errorListProvider == null)
                {
                    System.IServiceProvider serviceProvider = new ServiceProvider(_applicationObject as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
                    _errorListProvider = new ErrorListProvider(serviceProvider);
                    _errorListProvider.ProviderName = "custom Errors";
                    _errorListProvider.ProviderGuid = new Guid("xxxxxxxxxxxxxx");
    
                }
            }