DCSIMG
January 2011 - Posts - Shai Raiten

Shai Raiten

 Subscribe

January 2011 - Posts

TFS API Part 34– Build Basic Actions

TFS API Part 34– Build Basic Actions

In my previous post on on TFS API– Get Build Definitions and Build Details I’ve showed how to obtain Builds Definitions and Builds using TFS API.
In this post I' used the same project but I’ve added more functionality to the UI that will allow you to perform more actions on the Build item (Stop, Delete etc).

image

Download Demo Project

Step 1: Create Project and Add Reference

Create an WPF/WinForm application and add the following references:

First add reference for

  • Microsoft.TeamFoundation.dll
  • Microsoft.TeamFoundation.Build.Client
  • Microsoft.TeamFoundation.Build.Common.dll
  • Microsoft.TeamFoundation.dll

All files located under - c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\

Step 2: Connect to Team Foundation Server

(TFS API Part 20: Bye TeamFoundationServer and Welcome TfsTeamProjectCollection)

private TfsTeamProjectCollection server;
private IBuildServer buildServer;
private void btn_connect_Click(object sender, RoutedEventArgs e)
{
    TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false);
    tpp.ShowDialog();

    if (tpp.SelectedTeamProjectCollection != null)
    {
        server = tpp.SelectedTeamProjectCollection;
        server.EnsureAuthenticated();
        buildServer = (IBuildServer)server.GetService(typeof(IBuildServer));

        //QueryBuildDefinitions(String) Gets the build definitions for the specified team project.
        //QueryBuildDefinitions(IBuildDefinitionSpec) Gets a single build definition query result for a specified build definition specification.
        //QueryBuildDefinitions(IBuildDefinitionSpec[]) Gets the build definition query results for a specified array of build definition specifications.
        //QueryBuildDefinitions(String, QueryOptions) Gets the build definitions for the specified team project. The specified query options determine the amount of data that is retrieved in the query.
        // IBuildDefinition Interface -> http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.build.client.ibuilddefinition.aspx
        BuildDefinitions.ItemsSource = buildServer.QueryBuildDefinitions(tpp.SelectedProjects[0].Name);
    }
}

Step 3: Build Actions

Here is the list of some basic methods you can use for BuildDetail.

IBuildDetail build = Builds.SelectedItem as IBuildDetail;
//Delete the build and only the specified information.
//None          No delete options selected.
//DropLocation Delete drop location.
//TestResults Delete test results.
//Label          Delete the label.
//Details      Delete details.
//Symbols      Delete symbols.
//All          Delete all.

build.Delete(DeleteOptions.All); 
//Stops the build.
build.Stop();
//Starts polling by using the default interval of five seconds and no synchronization object.
//When events are handled by a visual Windows Forms component, the other overload should be used for this
//method and that component should be passed in as the synchronizingObject so that the event handlers
//are called on the same thread on which the component was created.
build.Connect();
//Stops polling the server.
build.Disconnect();
//Notifies the server that the build is complete and sets the status accordingly.
BuildStatus item = (BuildStatus)combo_status.SelectedItem;
build.FinalizeStatus(item);
//Blocks additional builds until this build is finished.
build.Wait();

//Retrieves the latest build data from the server with all details.
build.RefreshAllDetails();
 
Enjoy
Download Demo Project

Extending Visual Studio Setup Project – Part 2

Extending Visual Studio Setup Project – Part 2

In my last post on that subject Extending Visual Studio Setup Project – Part 1 I showed how to create and use the basic features in Visual Studio Installer, this is the second part and more advanced.

Download Demo Project

Run External Application during Setup

In this step I’ll show how to run an external application before the actual install process using “Installer Class”.
Create new WPF Application project called – “SetupHelper” and add additional Item of type “Installer Class” called – “MyInstallerHelper”.
The InstallerClass will allow you to override the following events:

  • Rollback
  • Install
  • OnAfterInstall
  • Commit
  • OnAfterRollback
  • OnAfterUninstall
  • OnBeforeRollback
  • OnBeforeUninstall
  • OnCommitted
  • OnCommitting
  • Uninstall
  • OnBeforeInstall

First add your code for “SetupHelper” wpf application, I’ve added code to show current processes and process title, but you can add whatever you want.
Now we need to add “SetupHelper” wpf app to our setup project, select the Setup Project and “Add Project Output” of SetupHelper.
Select the Setup Project and click on the “Custom Actions Editor” icon , on the install add new “Custom Action” and from the “Application Folder” pick “Primary output from SetupHelper (Active).
Now select the new Custom Action and in the “CustomActionData” add the following - /Run=SetupHelper.exe /WaitForExit=true

Back to MyInstallerHelper, override OnBeforeInstall and paste the code below in order to get the CustomActionData you wrote above:

protected override void OnBeforeInstall(IDictionary savedState)
{
    try
    {
        base.OnBeforeInstall(savedState);
        FileInfo fileInfo = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
        string sProgram = Context.Parameters["Run"];
        sProgram = Path.Combine(fileInfo.DirectoryName, sProgram);
        Trace.WriteLine("Install sProgram= " + sProgram);
        OpenWithStartInfo(sProgram);
    }
    catch (Exception exc)
    {
        Context.LogMessage(exc.ToString());
        throw;
    }
}

OpenWithStartInfo will run SetupHelper application and will pause the setup process while the SetupHelper is open.

void OpenWithStartInfo(string sProgram)
{
    ProcessStartInfo startInfo = new ProcessStartInfo(sProgram);
    startInfo.WindowStyle = ProcessWindowStyle.Normal;
    string[] ExcludeKeys = new string[] { "run", "WaitForExit" };
    startInfo.Arguments = ContextParametersToCommandArguments(Context, ExcludeKeys);
    Trace.WriteLine("run the program " + sProgram + startInfo.Arguments);
    Process p = Process.Start(startInfo);
    ShowWindow(p.MainWindowHandle, WindowShowStyle.Show); //otherwise it is not activated
    SetForegroundWindow(p.MainWindowHandle);
    BringWindowToTop(p.MainWindowHandle);
    Trace.WriteLine("the program Responding= " + p.Responding);
    if ((Context.IsParameterTrue("WaitForExit")))
    {
        p.WaitForExit();// Have to hold the setup until the application is closed.
    }
}

ContextParametersToCommandArguments Gets the CustomActionData arguments you added in the Custom Action.

public static String ContextParametersToCommandArguments(InstallContext context, string[] ExcludeKeys)
{
    ExcludeKeys = ToLower(ExcludeKeys);
    StringBuilder sb = new StringBuilder();
    foreach (DictionaryEntry de in context.Parameters)
    {
        string sKey = (string)de.Key;
        bool bAdd = true;
        if (ExcludeKeys != null)
        {
            bAdd = (Array.IndexOf(ExcludeKeys, sKey.ToLower()) < 0);
        }
        if (bAdd)
        {
            AppendArgument(sb, sKey, (string)de.Value);
        }
    }
    return sb.ToString();
}

public static StringBuilder AppendArgument(StringBuilder sb, String Key, string value)
{
    sb.Append(" /");
    sb.Append(Key);
    //Note that if value is empty string, = sign is expected, e.g."/PORT="
    if (value != null)
    {
        sb.Append("=");
        sb.Append(value);
    }
    return sb;
}
#region  "FS library methods"
public static string[] ToLower(string[] Strings)
{
    if (Strings != null)
    {
        for (int i = 0; i < Strings.Length; i++)
        {
            Strings[i] = Strings[i].ToLower();
        }
    }
    return Strings;
}
#endregion  //"FS library methods"
#region  "showWindow"

// http://pinvoke.net/default.aspx/user32.BringWindowToTop
[DllImport("user32.dll")]
static extern bool BringWindowToTop(IntPtr hWnd);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetForegroundWindow(IntPtr hWnd);

//from http://pinvoke.net/default.aspx/user32.SwitchToThisWindow
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, WindowShowStyle nCmdShow);

/// <summary>Enumeration of the different ways of showing a window using
/// ShowWindow</summary>
private enum WindowShowStyle : uint
{
    /// <summary>Hides the window and activates another window.</summary>
    /// <remarks>See SW_HIDE</remarks>
    Hide = 0,
    /// <summary>Activates and displays a window. If the window is minimized
    /// or maximized, the system restores it to its original size and
    /// position. An application should specify this flag when displaying
    /// the window for the first time.</summary>
    /// <remarks>See SW_SHOWNORMAL</remarks>
    ShowNormal = 1,
    /// <summary>Activates the window and displays it as a minimized window.</summary>
    /// <remarks>See SW_SHOWMINIMIZED</remarks>
    ShowMinimized = 2,
    /// <summary>Activates the window and displays it as a maximized window.</summary>
    /// <remarks>See SW_SHOWMAXIMIZED</remarks>
    ShowMaximized = 3,
    /// <summary>Maximizes the specified window.</summary>
    /// <remarks>See SW_MAXIMIZE</remarks>
    Maximize = 3,
    /// <summary>Displays a window in its most recent size and position.
    /// This value is similar to "ShowNormal", except the window is not
    /// actived.</summary>
    /// <remarks>See SW_SHOWNOACTIVATE</remarks>
    ShowNormalNoActivate = 4,
    /// <summary>Activates the window and displays it in its current size
    /// and position.</summary>
    /// <remarks>See SW_SHOW</remarks>
    Show = 5,
    /// <summary>Minimizes the specified window and activates the next
    /// top-level window in the Z order.</summary>
    /// <remarks>See SW_MINIMIZE</remarks>
    Minimize = 6,
    /// <summary>Displays the window as a minimized window. This value is
    /// similar to "ShowMinimized", except the window is not activated.</summary>
    /// <remarks>See SW_SHOWMINNOACTIVE</remarks>
    ShowMinNoActivate = 7,
    /// <summary>Displays the window in its current size and position. This
    /// value is similar to "Show", except the window is not activated.</summary>
    /// <remarks>See SW_SHOWNA</remarks>
    ShowNoActivate = 8,
    /// <summary>Activates and displays the window. If the window is
    /// minimized or maximized, the system restores it to its original size
    /// and position. An application should specify this flag when restoring
    /// a minimized window.</summary>
    /// <remarks>See SW_RESTORE</remarks>
    Restore = 9,
    /// <summary>Sets the show state based on the SW_ value specified in the
    /// STARTUPINFO structure passed to the CreateProcess function by the
    /// program that started the application.</summary>
    /// <remarks>See SW_SHOWDEFAULT</remarks>
    ShowDefault = 10,
    /// <summary>Windows 2000/XP: Minimizes a window, even if the thread
    /// that owns the window is hung. This flag should only be used when
    /// minimizing windows from a different thread.</summary>
    /// <remarks>See SW_FORCEMINIMIZE</remarks>
    ForceMinimized = 11
}
#endregion

Try It

Now Run the Setup project and you will notice that during the installation process your Setup Helper will pop up and prevent the Setup to continue until you will close the application.

image

After the setup is complete you will see you setup output as below

image

Summary

As you saw in this article Visual Studio Setup Project can be extended a lot more and this can be good for many applications.

Download Demo Project

Extending Visual Studio Setup Project – Part 1

Extending Visual Studio Setup Project – Part 1

One of the thing I hear all the time when companies talks for building reliable Windows Installer (MSI) for their product is –> Visual Studio Setup Project is not enough and we need much much more, my first response is – Wait, VS Setup project is not like Advanced Installer , InstallShield but still can do a lot more outside the box.

Setup projects are used to create Windows Installer (.msi) files, which are used to distribute your application for installation on another computer or Web server. There are two types of setup projects.

  • Standard setup projects create installers that install Windows applications on a target computer
  • Web setup projects create installers that install Web applications on a Web server.

In this article I’ll show how to extend your VS Setup Project and help to understand how VS Setup makes it easy for developers to build reliable Windows Installer (MSI) in Visual Studio. (All my screenshots will take from Visual Studio 2010.)

  1. Getting Started With VS Setup Project
  2. Adding New User Dialog and Deployments Conditions
  3. Run External Application during Setup

Getting Started

Open Visual Studio and create new Setup Project called – “DemoSetup”, the Setup project item can be found under “Other Project Types”-> ”Setup and Deployment” –> “Visual Studio Installer”.

Also create a WPF application called – “DemoWpfApplication”, we need some project to work with.

Two things need to be done in order to get the MSI ready for deployment.

  1. On the DemoSetup project Add Project Output from DemoWPFApplication. – Setup will automatically find all related dependencies.
  2. Modify Setup Project properties (See Picture Below)

* The Version Property is very important for various MSI, in order to identify old installation and overwrite existing files with a newer version. 

image

Adding New User Dialog and Deployments Conditions

Now, this is one of most common improvement users always want – Add an additional Dialog during the setup and add your own questions or input.
In this step I’ll show how to add conditions and add a new user Dialog, here is the Requirements: Add the following File (Dummy Files)

  • Blue.bmp,Red.bmp, Green.bmp
  • License.rtf
  • “Readme for 2000.txt”, “Readme for Windows 7.txt”
  1. First let add our Product License Agreement":

Select the Setup Project and click “User Interface Editor” iconimage, this will open a view showing all the dialogs the user will see during the Setup process.
Click “Add Dialog” and choose “License Agreement”, after adding this dialog view dialog properties and select the License.rtf file.

image

      2.     Add Deployment by Condition:

Add deployment condition for “Readme for 2000.txt”, “Readme for Windows 7.txt”, the propose is to copy each file only for specific operation system.
Select “Readme for 2000.txt” to see his properties, locate “Condition” and add this command – WindowsBuild = 2195 or VersionNT = 500
Now select “Readme for Windows 7.txt” and add this in the Condition property –WindowsBuild >= 7100 or VersionNT = 601
(More information on Operating System Property Values)
The condition will allow you to copy specific file depends on the user OS.

       3.     Add your User Choose condition

This step will show you how to add your own questions (using Radio Buttons) and allow the user to define a Favorite Color and use User choose as condition for deployment.
Add a new Dialog and choose “RadioButton(3 buttons)” add fill the information as below:

image

To add the condition you need to select each of the following files: Blue.bmp,Red.bmp, Green.bmp
and add the proper value in the condition property as follow - FAVORITECOLOR="Blue", FAVORITECOLOR="Red" etc.

Build the setup project and run it, select Green in “Favorite Color” and the result should look like:

image

TFS 2010 - Urban Turtle for a Better Scrum

Urban Turtle logo

TFS 2010 - Urban Turtle for a Better Scrum

If you doing Scrum in TFS 2010 this is an Add-on you can’t ignore!!! Urban Turtle is built by Pyxis Technologies and provides an awesome Scrum experience for TFS.

Urban Turtle will assist you with your Scrum process with a beautiful Interface and easy functionality though TFS 2010 Web Access.

Sounds Good? give it a try http://urbanturtle.com – You can download it for 30 days

Ream More from Brian Harry

Planning Board

  • Prioritize your backlog using drag-and-drop interface
  • Change to priority of a user story and the task will automatically follow
  • Easy filtering let's you focus on what you are doing
  • Plan your work with a simple drag-and-drop
  • Effortlessly add tasks to a user story

image

Task Board

  • Task board to view completed, ongoing and remaining work at a glance
  • Select or close a task in a second using drag-and-drop
  • Increase the efficiency of your Daily Scrum by providing transparency to your team
  • Sprint Burndown with live data to make sure you deliver what you are committed to
  • Makes impediment visible to easily eliminate it

image

TFS API Part 33– Get Build Definitions and Build Details

TFS API Part 33– Get Build Definitions and Build Details

Doing some major projects in WF under Team Build 2010 I decide it’s the right time to start writing about Build API in TFS 2010.

This part is very very basic and in later posts I’ll show some cool stuff in Build 2010 API.

image

Download Demo Project

Step 1: Create Project and Add Reference

Create an WPF/WinForm application and add the following references:

First add reference for

  • Microsoft.TeamFoundation.dll
  • Microsoft.TeamFoundation.Build.Client
  • Microsoft.TeamFoundation.Build.Common.dll
  • Microsoft.TeamFoundation.dll

All files located under - c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\

Step 2: Connect to Team Foundation Server

(TFS API Part 20: Bye TeamFoundationServer and Welcome TfsTeamProjectCollection)

private TfsTeamProjectCollection server;
private IBuildServer buildServer;
private void btn_connect_Click(object sender, RoutedEventArgs e)
{
    TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false);
    tpp.ShowDialog();

    if (tpp.SelectedTeamProjectCollection != null)
    {
        server = tpp.SelectedTeamProjectCollection;
        server.EnsureAuthenticated();
        buildServer = (IBuildServer)server.GetService(typeof(IBuildServer));

        //QueryBuildDefinitions(String) Gets the build definitions for the specified team project.
        //QueryBuildDefinitions(IBuildDefinitionSpec) Gets a single build definition query result for a specified build definition specification.
        //QueryBuildDefinitions(IBuildDefinitionSpec[]) Gets the build definition query results for a specified array of build definition specifications.
        //QueryBuildDefinitions(String, QueryOptions) Gets the build definitions for the specified team project. The specified query options determine the amount of data that is retrieved in the query.
        // IBuildDefinition Interface -> http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.build.client.ibuilddefinition.aspx
        BuildDefinitions.ItemsSource = buildServer.QueryBuildDefinitions(tpp.SelectedProjects[0].Name);
    }
}

Step 3: Get Builds From Build Definition

private void BuildDefinitions_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (BuildDefinitions.SelectedItem != null)
    {
        IBuildDefinition def = BuildDefinitions.SelectedItem as IBuildDefinition;
        //IBuildDetail Interface -> http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.build.client.ibuilddetail.aspx
        Builds.ItemsSource = def.QueryBuilds();
    }
}
Download Demo Project

Work Item Spell Checker Custom Control for VS 2010

Work Item Spell Checker Custom Control for VS 2010

A long time ago I published a free Work Item Custom Control for Visual Studio 2005/2008 to allow using Spell Check on work item fields.

Since Visual Studio 2010 comes with Spell Checker ability I left this project behind, over the last couple of months I got lots of requests from people to adjust this Control to 2010, Today I got a request from a customer that really needs it so here you go.

Follow the link below, download the setup file and install in on you computer.

Work Item Spell Checker Custom Control for Visual Studio 2010

Team System Spell Checker.JPG