Visual Studio Productivity Power Tools for VS 2012

Well for starters let me assume you are a poor dev like me and don’t have access to Resharper! Well in case you do they have a lot of these features that are now available free of cost in Productivity Tools in VisualStudioGallery.msdn.microsoft.com.

Let me quickly show you some of the features that stand out pretty instantaneously .

1.PresentOn/Off – type this into the quick launch and lo you get the power of zoomit ūüôā

PresentOn

2.You can now edit a project file by right clicking on the project.

Edit Project

3.Browse to definition by pressing on control and left mouse click.

Definition

4.Email code snippets by using the same option in context menu.

Email

5.Now you can find duplicate code snippets by selecting the option “Find Matching clones in solution” in context menu.

Clones

Also there are other features like Auto Brace Completion,Open Command Prompt and HTML copy.
So go ahead and give it a download!!

Setup Load Testing in Visual Studio

Well most often MS doesn’t setup stuff .So you have to do it for yourself.Like for Load testing in VS test cases,
you have to configure the database “LoadTest2010” and the corresponding tables like LoadTestRun,LoadTestCase,…
Well this is how you can do it in case you stuck at it.

Browse to this folder and execute in command line else you can always run the script in Management Studio.

cd “C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE”

SQLCMD /S localhost\sqlserver -i loadtestresultsrepository.sql

Copying Directory or File in VSTS test cases

Well this one was pretty nasty I must admit.I didn’t know that I would lose some time on this one.And since I did I might as well blog about it.So here goes the problem statement.Have you faced the scenario wherein you had to copy some files under some folder in Unit tests in Visual Studio? This is because the test cases run under a folder called test results and each time you run it creates a new folder for that particular test case. Mind you before I start I must say that I have encountered this on the VS-2010 and not on the nascent versions of Visual Studio viz 2012.So here goes as to what you need to do to achieve the same.

1)First go the TestSettings file in VS 2010 which is directly under solution.
2)Go to Deployment section and check Enable deployment and add the directory that you want to add.

testsettings

3)Now is the trick part you have to edit the Test Settings file in Xml editor and go the tag under Deployment which has the required DeploymentItem and the attribute outputDirectory as follows.

deployment

4)Finally the worst part was now when you run the unit tests you will still now find it added.So to get it in working in VS 2010 you have to select the test list editor under the Test–>Windows menu in Visual Studio IDE.And then select your tests and hit run.Eureka… ooo still not there yet.The directory or file is still not out there!

5)Close your Visual Studio IDE and open it once again.(Age old trick works in the realm of WINDOWS).

So happy testing once again ūüôā

Tip for the day!

I was recently working with xmls and xsd’s and came across this wonderful utility called XSD.exe.Using this you can create classes or xmls from schema’s and viceversa as well.Wonderful aint it?
Example
Generate classes from a given xsd

C:\classfiles>xsd “C:\SampleServices\Item\Lookup.xsd” /classes
For more info go to the path where xsd is(mine is C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools or C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\x64.This location is for VS2010 as you would have already presumed) in the command prompt is and hit

$:\xsd /h

And did you know you can even generate schema for a type from a dll or exe.. Cool eh?!

Custom Configuration Designer!

There has many a time that i have posted on tools, that makes life so much simpler,in order that we can can have the extra time to fall in love with C#!So many of us hate to see Xml. Lets admit it ,not many are in awe of the beauty called xml and have burnt their fingers and are not comfortable with it.But next time when you hear that you have to create a custom configuration,don’t fear as we have tools in place to handle that.Thanks to the wonderful tool called Configuration Section Designer.I wouldn‚Äôt have ventured into it had not i made a silly mistake which took my entire day and i began to question the logic of creating all these with mere hands and why not get it automated?

You can install the Configuration Section Designer from here.Once you download the plug-in and install it ,it fits perfectly well with VS-2008. and VS-2010 folks ,your version is yet to be out.But once you have installed the Custom Configuration Designer you can see that you will get a project like the snapshot available for you to play around!

 

 

Once you have created the Custom Configuration ,you will get a default custom Section designer diagram which will be empty .Go to the properties and enter the values in Namespace and XmlSchemaNamespace as follows.

 

 

Once you are done naming your namespace as well as the xml schema namespace, you can go ahead and drag and drop the Config Section, Config Section Group, Configuration Collection  as well as Configuration Element.Here is sample that I have created.Its really simple isn’t it?

 

 

And you can add custom classes to the existing predefined system types for your elements as well as the attributes as well as mention if it required and to make a certain attribute Key for a Config Collection.And then all you need to do is build it .

 

Start a Windows Service Automatically after Install

Recently i came across a situation wherein i had to host a WCF service as a Windows Service.Only after i installed the service using InstallUtil ‚Äďi  ‚Äúassembly name‚ÄĚ,did i realize my folly that i had a misconception regarding the term ‚ÄúAutomatic‚ÄĚ.What i am referring to the ServiceInstaller.StartType property.The main intent of this property is to start the Service automatically on start of Windows.

Code Snippet
  1. this.serviceInstaller1.StartType =
  2.      System.ServiceProcess.ServiceStartMode.Automatic;

 

So what do i do in run the service while installation?All you need to do add the event AfterInstall for the ServiceInstaller and then call the ServiceController from the eventhandler to start the service.

Code Snippet
  1. [RunInstaller(true)]
  2.     public partial class ServiceInstaller : Installer
  3.     {
  4.         public ServiceInstaller()
  5.         {
  6.             InitializeComponent();
  7.             ServiceProcessInstaller processInstaller = new ServiceProcessInstaller();
  8.             ServiceInstaller serviceInstaller = new ServiceInstaller();
  9.             //Specifies the type of account that should be used for the service.
  10.             processInstaller.Account = ServiceAccount.LocalSystem;
  11.             //Specifies the name of the service that is installed.
  12.             serviceInstaller.DisplayName = "Josh Service";
  13.             //Gives the description of the Installed service.
  14.             serviceInstaller.Description = "this is a Win Service";
  15.             //It tells which is the service that should be installed.
  16.             serviceInstaller.ServiceName = "MyService";
  17.             //It specifies the Start type of the service.
  18.             serviceInstaller.StartType = ServiceStartMode.Automatic;
  19.             this.AfterInstall += new InstallEventHandler(ServiceInstaller_AfterInstall);
  20.             Installers.Add(processInstaller);
  21.             Installers.Add(serviceInstaller);
  22.         }
  23.  
  24.         void ServiceInstaller_AfterInstall(object sender, InstallEventArgs e)
  25.         {
  26.             ServiceController sc = new ServiceController("MyService");
  27.             sc.Start();
  28.         }
  29.     }

 

Trivia:

‚ÄúThe  service on local computer started and then stopped. Some Services stop automatically if they are not in use by another services or programs.‚ÄĚ

You are all used to debugging and would have most likely than not used the ‚Äúattach to process ‚ÄĚ to debug your service implementation.But what do you do when you get Errors or have to debug the Windows Service installer itself?Bingo, we can always write ‚ÄúSystem.Diagnostics.Debugger.Launch();‚ÄĚ in the OnStart() method and start debugging.Also you can write the errors to the EventLog or dump the Exception to a Log after putting in place a simple try catch!

Some links on the New Release Visual Studio 2010

Download the trial now!

visual studio 2010

visual studio 2010

 Customers can evaluate Visual Studio 2010 editions free for 90 days. After 30 days, customers must register the product to obtain a free key which extends the trial an additional 60 days. 

http://www.microsoft.com/visualstudio/en-us/download 

Download the training kit for DotNet Framework 4

http://www.microsoft.com/downloads/details.aspx?FamilyID=752CB725-969B-4732-A383-ED5740F02E93&displaylang=en

Learning videos for VS 2010

http://www.microsoft.com/learning/en/us/training/format-learning-snacks.aspx#vs10

Visual Studio 2010 Featured Content

http://msdn.microsoft.com/hi-in/vstudio/ff625297(en-us).aspx

Life runs on code!

http://www.microsoft.com/visualstudio/en-us/watch-it-live

Test drive for Visual Studio 2010

http://www.microsoft.com/visualstudio/en-my/download