in

Platinum Bay

Peace, Love and Visual Studio Team System

.NETicated

January 2008 - Posts

  • SOX 404: Compliance Not Found?

    This post has been updated and is now located here.

  • Visual Studio Tools and Add-Ins

    Thanks to everyone who attended my session at the Philly .NET Code Camp 2008.1. Here is a list of the tools I covered:

    Microsoft Tools

    Visual Studio SDK
    http://www.microsoft.com/downloads/details.aspx?familyid=30402623-93ca-479a-867c-04dc45164f5b&displaylang=en

    The Visual Studio SDK is the mothership of all Visual Studio add-ins. Among other things, it provides project templates to create add-ins and managed packages. It also adds DSL tools and text templating.

    Modeling Power Toys
    http://www.codeplex.com/modeling  

    If you do much modeling, check out these tools. I use the mover toy the most.

    Enterprise Library
    http://msdn2.microsoft.com/en-us/library/aa480453.aspx

    The Enterprise Library provides, you guessed it, a library of enterprise building blocks from cryptography to logging to caching. If you build apps a bit, check this out.

    Visual Studio Tools for Office Second Edition
    http://msdn2.microsoft.com/en-us/office/aa905543.aspx

    VSTO, as outlined in a previous post, is a set of tools for extending Microsoft Office. VSTO adds the necessary class libraries as well as project and item templates for developing Office solutions.

    Third-Party

    Resharper

    Quick Facts

     

    Supports:

    Visual Studio 2003, 2005

    Vendor:

    Jet Brains

    Price:

    From $149

    URL:

    http://www.jetbrains.com

    Seriously, I don't know how I live without this one. So many helpful features. Unfortunately, it doesn't yet support the .NET 3.5 language features.

    .NET Reflector

    Quick Facts

     

    Supports:

    .NET Framework versions 1.0, 1.1, 2.0, 3.0

    Vendor:

    Lutz Roeder

    Price:

    Free

    URL:

    http://www.aisto.com/roeder/dotnet/

    This is the tool everyone is talking about. Actually dive in and explore an assemblies source code. Great for debugging or simple curiosity.

    Clarius T4 Editor

    Quick Facts

     

    Supports:

    Visual Studio 2005, 2008

    Vendor:

    Clarius Consulting

    Price:

    Free

    URL:

    http://www.t4editor.net/

    Note:

    Text Templating requires the Visual Studio SDK

    If you are using text templating, which is part of the Visual Studio SDK, you need this add-in. It provides color coding and IntelliSense for .TT files.

    Postbuild

    Quick Facts

     

    Supports:

    .NET Framework versions 1.0, 1.1, 2.0, 3.0

    Vendor:

    Xenocode

    Price:

    From $499

    URL:

    http://www.xenocode.com/

    A fantastic tool for obfuscating .NET assemblies. If you're an ISV, you need this one.

    Project Line Counter

    Quick Facts

     

    Supports:

    Visual Studio 2002, 2003, 2005

    Vendor:

    Oz Solomon

    Price:

    Free

    URL:

    http://www.codeproject.com/KB/macros/linecount.aspx

    I'm a metrics geek. This tool counts how many lines of code there are in my project or solution.

    Smart Paster 2005

    Quick Facts

     

    Supports:

    Visual Studio 2003, 2005, 2008

    Vendor:

    Alex Papadimoulis

    Price:

    Free

    URL:

    http://weblogs.asp.net/alex_papadimoulis/category/5341.aspx

    Smart Paster provides several code editor context menus to paste clipboard text as a string, StringBuilder or a comment.

    Visual Local History 2005

    Quick Facts

     

    Supports:

    Visual Studio 2005, 2008

    Vendor:

    Samuel Lacroix

    Price:

    Free

    URL:

    http://www.codeplex.com/VLH2005

    Visual Local History has saved me many times.  It saves a backup copy of a file each time you save it.  I've used it more than once to restore something I deleted, saved, and closed.

    For more great tools and add-ins, check out Scott Hanselman's list.

  • Extending Outlook with VSTO SE

    The Everywhere Platform

    Other than Windows and its default applications such as Notepad and Internet Explorer, what one piece of software is on more desktops than any other? In most companies, the president, sales staff, support staff, office manager, and sometimes even the janitor have Microsoft Outlook installed. The question begs asking then, why do folks only think about email and their calendar when they think about Outlook? Part of the reason may lie in Outlook's COM underpinnings and the dissatisfaction of working with VBA.

    While Outlook is still a COM based platform, key advances have made it much more accessible for developers. Since Outlook 2003, Microsoft has provided a set of extensibility tools called the Visual Studio Tools for Office (VSTO). With the release of Visual Studio 2008 and VSTO Second Edition, developers now have powerful tools such as graphical designers and code templates to interact with Outlook's extensibility model.

    Outlook's History

    In 1997, with the release of Exchange Server 5.5, Microsoft replaced the Exchange client with Outlook.

    Outlook 97

    version 8.0

    Released January 16, 1997


    Outlook 98

    version 8.5

    Released June 21, 1998


    Outlook 2000

    version 9.0

    Released June 7, 1999

    VBA, COM

    Outlook 2002

    version 10

    Released May 31, 2001

    VBA, COM, PIA

    Office Outlook 2003

    version 11

    Released October 21, 2003

    VBA, COM, PIA, VSTO

    Office Outlook 2007

    version 12

    Released November 30, 2006

    VBA, COM, PIA, VSTO SE

    Table 1 - Source Wikipedia

    Back then, the only way to interact with Outlook was through custom forms. Microsoft then added extensibility through VBA and COM. Oh, these were the days. Weak types and Object return types. Yum! Like ASP.OLD, we got real sick of this really quick.

    PIA – Primary Interop Assemblies

    Starting with Outlook 2002, Microsoft started supplying managed assemblies to allow managed code developers to work with Outlook a little easier, and while it did make life easier, it was still no picnic.

    VSTO is Born

    Beginning with Outlook 2003, Microsoft started shipping the Visual Studio Tools for Office. VSTO provided a wrapper around the PIAs, and made it easier to interact with the Outlook object model. Microsoft has since shipped VSTO Second Edition (SE) for Microsoft Office 2007.

    Outlook 2007 Object Model

    The Outlook object model is largely contained within two assemblies:

    • PIA – Microsoft.Office.Interop.Outlook.dll
    • VSTO – Microsoft.Office.Tools.Outlook.dll

    To get started with the object model, you should be familiar with the following top-level classes:

    • Application
      Represents an Outlook application and is the highest-level class in the object model.
      • Explorer
        Explorer represents a window that displays the contents of a folder that contains items such as e-mail messages, tasks, or appointments.
      • Inspector
        Inspector represents a window that displays a single item such as an e-mail message, task, or appointment.
      • MAPIFolder
        The MAPIFolder class represents a folder that contains e-mail messages, contacts, tasks, and other items. Outlook provides 16 default MAPIFolder objects.
      • MailItem, AppointmentItem, TaskItem, ContacItem

    You can view interactive diagrams of the complete object model on MSDN: Outlook Object Model Reference

    VSTO SE and Visual Studio 2008

    VSTO SE for Visual Studio 2008 adds some neat designer templates, such as Ribbon and Form.

    Debugging Outlook Add-Ins

    Here are a couple tips for debugging Outlook add-ins. First, create a separate profile in Outlook. Next, set up the Debug properties for your project to open Outlook, and pass the profile switch.

    Lastly, there is a neat tool called OutlookSpy which can make Outlook debugging and development much easier.

    Developing for Multiple Outlook Versions

    One project is required for each version of Outlook you wish to target. An OO approach is best here; separate the business logic so it can be included in each project.

    Building a Ribbon Add-In

    Extending the Outlook ribbon is not unlike Windows Forms development. A ribbon view is displayed in the designer, and can be laid out using drag-and-drop. The designer hierarchy, and the underlying VSTO hierarchy is ribbon, tab, tab group, controls as seen in figure 1. The full range of controls can be found in the toolbox, including

    The one caveat of ribbon customization is finding the correct tab or tab group ID. To help, Microsoft has a set of Excel files for download which contain these IDs. The download can be found here:

    http://www.microsoft.com/downloads/details.aspx?FamilyID=4329D9E9-4D11-46A5-898D-23E4F331E9AE&displaylang=en

    After that, the rest is laying out the forms, and attaching to form elements and the Outlook object model.

    Ribbon IntelliSense Hack

    Note: In order to get Intellisense for the ribbon XML, copy the CustomUI file from
        C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas\1033\CustomUI.xsd
    to the Visual Studio schemas directory
        C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas\

    Building a Form Region Add-In

    Form regions, though similar to the earlier custom forms, are considerably more powerful. Form regions can be added to any inspector window and can help supplement information for the inspector item such as an email or calendar event.

    When adding a form region to a project, a wizard is displayed which provides options to create different types of form regions. You have the option to create a separate, adjoining or replacement region, or to replace all the regions in a given area. If you don't like the way the MailItem editor works, you could write your own by using the Replacement region option, and attaching your controls to the underlying object model.

    Learning about VSTO and Outlook add-ins opens up a world of possibilities for custom productivity tools, legacy systems integration, and ISV products.

  • Designing Windows Forms with Abstract Inheritance

    I got sick of Notepad a couple weeks ago, and set about to build a Notepad-like application with a couple sorely missing features like reload prompting, multiple undo levels, tabs, line numbers, more robust find and replace, recent files list, opacity, etc. It's a cool little project, titled DevNotepad, and is currently about 3,000 lines of code. It's fast too, which is very important for a Notepad replacement. The beauty of Notepad itself is its compact size and loading speed. More on DevNotepad later.

    Along the way though, I ran into a problem trying to visually design user controls which inherited from an abstract class. Out of the install (box), Visual Studio does not support this. If you were to try and visually design a form which inherits from an abstract class, you would get a message similar to the following:

    After digging through [your favorite search engine], I found it is possible to modify this behavior. The key is to provide a TypeDescriptionProvider attribute to the base abstract class:

    [TypeDescriptionProvider(typeof(SubstituteBaseUserControlProvider))]
    public abstract class BaseUserControl : UserControl
    ...

    If you don't have Reflector installed, TypeDescriptorProvider is in the System.ComponentModel namespace. The next step is to build the actual provider itself:

    internal class ReplaceOptionsPageProvider : TypeDescriptionProvider

       
    public ReplaceOptionsPageProvider()
           
    : base(TypeDescriptor.GetProvider(typeof(BaseOptionsPage)))
       
    {
        }

        public override Type GetReflectionType(Type objectType, object instance)
       
    {
           
    if (objectType == typeof (BaseOptionsPage))
               
    return typeof (ReplaceForm);

           
    return base.GetReflectionType(objectType, instance);
       
    }

       
    public override object CreateInstance(IServiceProvider provider, Type objectType, Type[] argTypes, object[] args)
       
    {
           
    if (objectType == typeof (BaseOptionsPage))
               
    objectType = typeof (ReplaceForm);

            return base.CreateInstance(provider, objectType, argTypes, args);
       
    }
    }

    The above code detects if the user control to be designed inherits from the aforementioned abstract class, and gives it a replacement to start designing from – a stand-in base class. Therefore, the final step is to build the stand-in user control, inheriting from the original abstract class:

    internal class StandInUserControl : BaseOptionsPage

    Once the code is in place, close any open designer windows, rebuild the project, and re-open the previously troublesome designer. You should be good to go.

    Hope this helps

  • Renaming and Copying Projects and Solutions

    A question was posed to me this evening about copying and renaming Visual Studio projects. It is a lengthy enough topic to explain, I thought I better write it down. So here goes:

    Renaming Projects

    Step 1: Renaming projects can be an interesting challenge for the uninitiated. It's not quite as simple as just renaming the project node in the Solution Explorer tool window. Renaming the project node doesn't change the assembly name or the root namespace or the physical project folder name. Let's take a look at how to do just that.

    When you rename a project, most likely you will want to rename the output assembly and/or the root namespace for the project. To do this, right-click on the project node and choose Properties. You can also double-click on the Properties (C#) or My Project (VB) node.

    If it is not already selected, click on the Application tab. You will see two textboxes at the top; Assembly name and Root namespace. Assembly name is the filename given to the project's output assembly. A class library with an assembly name of Class1 will output a DLL named Class1.dll. Root namespace is, as the name suggests, the root namespace used for the project.

    You may wish to change both the assembly name and root namespace when renaming a project.

    Step 2: Next, I usually like to rename the physical project folder. To do this, close the solution within Visual Studio (you may have to close Visual Studio as well) and browse to the project folder. An easier way to get to the project folder might be to open a project file, right-click on the file's tab, and choose Open Containing Folder, then closing the solution or Visual Studio if necessary.

    When you are at the project folder, rename it to match the new project name. Next, re-open the solution in Visual Studio. Visual Studio will complain that it can't load one or more projects.

    This is fine, click OK. You will notice that your project is grayed out. Select the unavailable project node, go to the Properties tool window, and you will see that the File path property is editable. Click the value to show the ellipsis, , and click the ellipsis button. The dialog should be in the solution path, so browse into the renamed project folder and select the project file (*.*PROJ). Now, right-click on the unavailable project node in the Solution Explorer tool window, and choose Reload Project. Now your project is renamed and re-integrated into the solution.

     

    Renaming Solutions

    The process of renaming solutions is much easier. Simply rename the solution in the Solution Explorer tool window, and rename to physical solution folder. After renaming the solution folder, I would recommend opening up the solution file (*.SLN) manually while you are there as Visual Studio's MRU (Most Recently Used) shortcut lists won't be updated.

    Copying Projects

    Copying projects into the same solution requires a bit more legwork, including digging into the project files (*.*PROJ) themselves. First, go into Windows Explorer, and make a copy of the project folder, giving it the new project name.

    Next, open up the solution file (*.SLN) in notepad. For our ClassLibrary1 solution, the solution file looks like:

    Microsoft Visual Studio Solution File, Format Version 9.00

    # Visual Studio 2005

    Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "ClassLibrary1", "ClassLibrary1\ClassLibrary1.vbproj", "{9ED830D5-77A8-453D-B1CF-02E310E45EB1}"

    EndProject

    We are interested in the Project section. Copy those two lines, starting with Project and ending with EndProject. Then paste the text below the EndProject in a new line. If I wanted to add ClassLibrary1 as a new project called ClassLibrary2, I would change those references on the second project lines. The result would look like:

    Microsoft Visual Studio Solution File, Format Version 9.00

    # Visual Studio 2005

    Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "ClassLibrary1", "ClassLibrary1\ClassLibrary1.vbproj", "{9ED830D5-77A8-453D-B1CF-02E310E45EB1}"

    EndProject

    Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "ClassLibrary2", "ClassLibrary2\ClassLibrary2.vbproj", "{9ED830D5-77A8-453D-B1CF-02E310E45EB1}"

    EndProject

    The final step is to go into the new project folder, ClassLibrary2, and rename the project file. In our case, to ClassLibrary2.vbproj.

    That's it. Open Visual Studio, and enjoy.

    Copying Solutions

    Again, copying solutions is much easier. Simply copy the solution directory (the one containing the .SLN file, give it a new name, and rename the solution file. If you wish, you may also want to rename the solution node in the Solution Explorer tool window.

    Conclusion

    It is possible to rename and copy projects and solutions, though it is a very manual process. I think it would be helpful to have an option to sync directory names with project and solution names in Visual Studio. If I find the time, I would like to build a Visual Studio add-in that does this and takes care of a lot of these manual steps automatically and intuitively.

  • Visual Studio – Text Editor Max Lines

    I decided to see how many lines of code Visual Studio supports. What I found I think it is quite enough - if you reach this boundary you have bigger problems. Visual Studio 2005 accepted approximately 2,094,048 lines before it, and Resharper, started acting goofy.

    When I tried to save the file, however, I got the following error message:

    I was also able to get to 377,599 columns before Visual Studio and Resharper starting going crazy.

    Just for kicks, I got up to 11,159,841 lines in Visual Studio 2008 before it and Resharper started seriously hindering by input.

  • Visual Studio – Design-Time Click Annoyance

    I have noticed from time to time when working in the Windows Forms designer that clicking back and forth between the designer pane and the properties grid can cause Visual Studio to think you double-clicked on a design item, and therefore create an event handler and switch to the code view. It is certainly annoying. I have recently found a way to prevent this.

    When working in the property grid, press Enter after inputting or changing a value. Now when you click back to the designer, Visual Studio won't go all goofy on you.

    Hope this helps

  • Opening Projects in Existing Solution

    Chalk this one up to 'did you know?' I certainly didn't – just saw this feature while working on another post actually.

    Say you have an existing solution open, and you want to open up another project. If you go to File | Open Project and select a project, the currently opened solution is closed. It is rather annoying sometime. Turns out, there is an option at the bottom of the dialog window to open the project within the existing solution. But who reads the directions anyway? I know for me at least, I tend to blur out on dialog boxes and do a little pattern matching based on what it appears to be.

    I can think of a couple scenarios where this dialog setting might be useful. For instance, as I was testing different __ComObject visualizer solutions, in different solutions, I had one core project I used for testing them. While I could in fact have created each project inside of the same solution, I found it helpful at the time, for a long forgotten reason, to keep them separated.

    Hope this helps

Powered by Community Server (Commercial Edition), by Telligent Systems
© Platinum Bay | Some Rights Reserved Creative Commons License

Disclaimer: The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Feel free to challenge me, disagree with me, or tell me I'm completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or annonymous comments) - so keep it polite, please.