Monday, January 13, 2014

How to build a solution using c# code in .NET 4.5 and retrieve the build result


Following is the code using which you can perform automated compilation of visual studio solutions through C#. First of all let’s retrieve the executing assembly path to write the output log of build activity performed using C#.
//retrieve assembly execution path
string assemblyExecutionPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string logFilePath = assemblyExecutionPath.Remove(assemblyExecutionPath.LastIndexOf("\\") + 1) + "build.log";
Let’s create a collection to hold the output –
OutputHeaderRow = new List<string>();
OutputItemRow = new List<string>();
Let’s say the path of the solution to build using C# code is present in following variable - string artifactPath = @"C:\Kunal_AppDev\New folder\Test Data Solution\ MySolution.sln"
Following is the remaining complete code –

Monday, January 6, 2014

How to log on to TFS as different user

Sometime you may have to login to TFS with different user; however TFS by default picks up the user logged in to windows or previous connection details. I am using VS2012 currently hence will explain the process using VS2012 IDE only. Look at the following screenshot. When you click on Connect option in Team Explorer window by default you get connected to the required server with credentials you have used to log on last time and you are not prompted to change the login user.



This will force to ask new credentials when TFS is opened for connection.

Go to Control Panel (Start -> Control Panel).Click User Accounts. Click Credential Manager.

Wednesday, December 4, 2013

C# Events – Concepts and Caveats – Part 4

I hope you have gone through the Part 1 to 3 of C# events.
C# Events – NullReferenceException –
If you raise an event without handlers then you get this exception – Object reference not set to instance of an object. Look below screenshot. I have commented the registration of event from Fielder class and similarly for Fan class. Also commented null check from Ball class from event raising code –

 


 
The exception is reported because none of the objects have added their event handlers to an event BallInGround, hence it will be null. Therefore it is always necessary to check null condition before raising an event.

Friday, November 29, 2013

C# Event – Understanding C# events – Part 3


Before going further it is really important to go through the Part 1 and Part 2.
AS discussed in Part 2, I will create an application based on Events. So create BallEventArgs  class as shown below –
public class BallEventArgs : EventArgs
    {
        public int Height { get; set; }
        public int Length { get; set; } 

        public BallEventArgs(int h, int l)
        {
            Height = h;
            Length = l;
        }
    }

Create Ball class as hown below with event declaration –
public class Ball
    {
        //declare event BallInGround
        public event EventHandler BallInGround; 

        /// <summary>
        /// method used for raising the event BallInGround
        /// </summary>
        /// <param name="e">BallEventArgs object</param>
        public void OnBallInGround(BallEventArgs e)
        {
            if (BallInGround != null)
            {
                BallInGround(this, e);
            }
        }
    }

Add a Fielder class as shown below –