Package that loads automatically and puts messages to the output window

This simple package demonstrates how to automatically load a package created with VSXtra and use the Output window to display messages.

Points of Interest:

  • VSPackages created with VSXtra derive from the PackageBase class instead of Microsoft.VisualStudio.Shell.Package
  • XtraProvideAutoLoad attribute uses a type (UIContext.NoSolution) that is checked during compilation type. The original ProvideAutoLoad attribute accepts any GUID that is not checked at all.
  • You do not need to call base.Initialize() in the overridden Initialize method, PackageBase does it for you.
  • You can directly write to the General pane of the Output window through System.Console.

Package source code:

using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;
using VSXtra;

namespace DeepDiver.OutputWindowWithAutoLoad
{
  // --- Note, this is the full source code opf the package
  [PackageRegistration(UseManagedResourcesOnly = true)]
  [DefaultRegistryRoot("Software\\Microsoft\\VisualStudio\\9.0")]
  [InstalledProductRegistration(false, "#110", "#112", "1.0", IconResourceID = 400)]
  [ProvideLoadKey("Standard", "1.0", "OutputWithAutoLoad", "DeepDiver", 1)]
  [Guid(GuidList.guidOutputWindowWithAutoLoadPkgString)]
  [XtraProvideAutoLoad(typeof(UIContext.NoSolution))]
  public sealed class OutputWindowWithAutoLoadPackage : PackageBase
  {
    protected override void Initialize()
    {
      Console.WriteLine();
      Console.WriteLine("This package demonstrates how to use the Output window.");
      
      Console.Write("*** Boolean values: ");
      Console.Write(true);
      Console.Write("|");
      Console.WriteLine(false);
      
      Console.Write("*** Character values: ");
      Console.Write('H');
      Console.Write("|");
      Console.Write('e');
      Console.Write("|");
      Console.Write('l');
      Console.Write("|");
      Console.Write('l');
      Console.Write("|");
      Console.WriteLine('o');
      
      Console.Write("*** Integral values: ");
      Console.Write((byte)0xab);
      Console.Write("|");
      Console.Write((short)12345);
      Console.Write("|");
      Console.Write(123456789);
      Console.Write("|");
      Console.WriteLine(1234567890123456L);
      
      Console.Write("*** String values: ");
      Console.Write("Hello");
      Console.Write("|");
      Console.WriteLine("World");

      Console.Write("*** Floating point values: ");
      Console.Write((Single)Math.PI);
      Console.Write("|");
      Console.WriteLine(Math.E);

      Console.Write("*** Char arrays: ");
      var chars = new [] { 'H', 'e', 'l', 'l', 'o' };
      Console.Write(chars);
      Console.Write("|");
      Console.WriteLine(chars);
      Console.WriteLine("End of demonstration.");
      Console.WriteLine();
    }
  }
}

Output:

OutputWindow1.png

Last edited Aug 5, 2008 at 8:08 AM by INovak, version 8

Comments

No comments yet.