in

Platinum Bay

Peace, Love, and...

This Blog

Syndication


.NETicated

November 2007 - Posts

  • Browse With Resolutions – No Dice

    When browsing an ASP.NET website from Visual Studio, there is a menu option 'Browse With'. When you open the dialog, you can select a browser to view the document or site, as well as select what resolution you want to view it in.

    Awhile back I was trying to test an ASP.NET mobile application without an emulator. I wanted to be able to open IE using the Browse With command, and select a resolution like 320x240. So I set about to try and find a way to do it.

    I first searched through the Visual Studio configuration and XML files, as well as the registry. No luck. This evening I finally resorted to using Reflector, and crap! The resolutions appear to be hard coded in an enumeration inside Microsoft.VisualStudio.Shell.Interop.

    public enum VSPREVIEWRESOLUTION
    {
        PR_Default,
        PR_640x480,
        PR_800x600,
        PR_1024x768
    }

    Oh well, back to the Firefox Developer Toolbar with Resize functionality.

  • MSBuild Task for SharePoint - MakeCab

    I've been doing quite a bit of SharePoint lately, and I feel there is still too much repetitive, manual effort involved in creating SharePoint solutions. One has to first create an empty class library project, and then add the folder structure and feature.xml, elements.xml, manifest.xml and wsp.ddf files. Next you have to keep track of file locations, both inside the solution and in the feature directory, and write post-build events to handle creation and dev deployment.

    I have it in my mind to create a Visual Studio extensibility project to automate a lot of this stuff and provide visual designers to handle a lot of the grunt work. But that is a much larger task, so for now I am releasing my MakeCab task for MSBuild.

    For those who are not familiar, the Microsoft Build Engine (MSBuild) is the underlying engine for building .NET solutions. It is available both as a command line utility, and as the hosted build tool for Visual Studio. MSBuild uses project files (.*proj) as input and they are xml based. The xml structure mainly contains Items, Properties, Targets and Tasks.

    What I have written is a simple Task to execute MakeCab for a given .DDF file. The process is pretty simple: inherit from Microsoft.Build.Framework.Task and override the Execute method. Then I added a Required public property for the directive file input, and utilized that to create and run a System.Diagnostics.Process.

    public class MakeCab : Task
    {
        private string directivesFile;

        public
    override bool Execute()
        {
            try
           
    {
                Log.LogMessage("Executing MakeCAB for " + directivesFile);

                ProcessStartInfo si = new ProcessStartInfo("makecab");
                si.Arguments = "/f " + directivesFile;
                Process.Start(si);

                Log.LogMessage("Execution of MakeCAB succeeded for " + directivesFile);

                return true;
            }
            catch (Exception ex)
            {
                Log.LogMessage("Execution of MakeCAB failed for " + directivesFile +
                    ". Reason: " + ex.Message);
                Log.LogError(ex.Message);
                return false;
            }
        }

        [Required]
        public string DirectivesFile
        {
            get
           
    {
                return directivesFile;
            }
            set
           
    {
                directivesFile = value;
            }
        }
    }

    I also signed my assembly and created a post-build event to register it in the GAC. The final step was to add the necessary nodes into the project xml file…

    <UsingTask TaskName="PlatinumBay.MSBuild.MakeCab.MakeCab"
       
    AssemblyName="PlatinumBay.MSBuild.MakeCab, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9805384e45235b26" />
    <
    Target Name="MyMakeCab">
       
    <
    MakeCab DirectivesFile="wsp.ddf" />
    </
    Target>

    …and add my new target to the DefaultTargets attribute:

    <Project DefaultTargets="Build;MakeCab"
        
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    And that's it. Now when I build my project, my cabinet file gets created.

    You can download the bits from the downloads section.

    Download Source
    Download Compiled
     

  • Padding the ole Resume

    I found this list hanging on the wall at a friend's cube at work, and thought it was too funny to pass up.

    Top 11 Worst Resumes

    • Lead programmer of the SQL Slammer worm
    • As data analyst for the Dept. of Veterans Affairs, I often took work home
    • Spearheaded the 2005 deployment of my company's Token Ring network
    • Saved thousands of dollars in electricity by turning off the AC in the server room every night
    • Certified in OS/2 Server support and Apple Newton repair
    • Initiated personal project to find holes in corporate Web porn filter
    • Designed a document management system when working for Arthur Andersen on Enron audit
    • Successfully transferred $3.2 million in corporate funds to wife of former Nigerian oil minister
    • Improved MP3 download speeds by switching from Kazaa to BitTorrent
    • Set company record for most HIPAA compliance violations
    • Assisted NSA agents with installation of network taps at AT&T

    Originally from: http://www.networkcomputing.com/showitem.jhtml?articleID=189602342

    If you click through to the link above, the next article about calling Mom is funny.

  • Visual Studio External Tools for SharePoint Developers

    As a continuation of my previous post, let's take a look at external tools in Visual Studio, from a SharePoint perspective. External tools are commands that can be run from within the context of the Visual Studio environment. Accessed from the Tools menu, there are several external tools built into Visual Studio, including the ActiveX Control Test Container, Create GUID, and more.

    The Create GUID tool is extremely useful for SharePoint development, where Features, Solutions, etc. require unique GUID identifiers.

    Here are a couple External Tools I add for use in SharePoint development.

    Get Public Key Token and Blob

    Make sure the project is signed and built.

    Command: C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sn.exe
    Arguments: -Tp "$(TargetPath)"
    Use Output Window: True

    Or

    Command: C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\secutil.exe
    Arguments: -hex -s $(TargetPath)
    Use Output Window: True

    While this is the only command I set up and use regularly, there are many others than can be added. Check this post for some great feature deployment external tools:

    http://sharepointsolutions.blogspot.com/2006/10/automation-in-visual-studio-2005-for.html

  • Visual Studio Build Events for SharePoint Developers

    One of the extremely useful, yet under-utilized features of Visual Studio are the project build events. Build events are commands you can run before and/or after a project build. You can further specify that they run after a successful build or any build. Any command that can be run from the command line can be used as part of a build event. These include:

    • sn – strong name utility
    • copy and xcopy
    • makecab
    • conditional statements

    You could even run ipconfig or ping if you wanted to. To open up the build events page, go to your project's property pages, and:

    C# – Choose the Build Events tab.

    VB – Choose the Compile tab, scroll to the bottom and click the "Build Events…" button.

    Bang on the money, you say. Exactly, I say. But you ask, 'So I want to copy my compiled assemblies to the 12 hive, how do I know where my project assemblies are?' Ah, excellent question. A smart one aren't you? (If you're confused, rest assured that this sounded much better in my head in British English. Cheers.) But back on point, if you open up the build event dialog, and click on the Macros button, you will be presented with token variables for project and solution locations, extensions, and much more. Here are the macros available, along with values for a test throwaway project:

    These macros make it incredibly easy to build custom event scripts. Here are some common build event scripts I use with SharePoint projects:

    MAKECAB

    Runs the makecab utility for DDF files.

    cd "$(ProjectDir)"
    "C:\Source\Utilities\MAKECAB.EXE" /f "WSP.ddf"

    Recycle the Application Pool:

    %25systemroot%25\system32\iisapp.vbs /a "AppPoolName" /r

    Copy file to the 12 hive:

    cd "$(ProjectDir)"
    "TEMPLATE" "%25CommonProgramFiles%25\Microsoft Shared\web server extensions\12\TEMPLATE\" /ys

    Create a deployment directory:

    I use this command to take a bunch of SharePoint projects, and copy the outputs to a single directory.

    copy "$(ProjectDir)bin\deploy\" "$(SolutionDir)deploy\"

    Register an assembly in the GAC:

    @SET gacutil = "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin\gacutil.exe"
    %gacutil% /iF MyAssembly.dll

    Conditional Statements

    The question of whether conditional statements were possible was posed to me at a local user group I presented at. The answer is yes, sort of.

    Here's an example showing how to use the macros to evaluate the build type:

    if $(ConfigurationName)==Release goto Release
    if $(ConfigurationName)==Debug goto Debug

    :Release
    REM do something
    goto End

    :Debug
    REM do something
    goto End

    :End

    Build events provide a wonderful way to reduce or eliminate a lot of the manual steps in building, deploying and testing SharePoint solutions. Have fun!

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.