Vadim's Weblog

Never stop learning.

Archive for the ‘Visual Studio’ Category

Visual Studio 2010 RC is out.

Posted by Vadim on February 8, 2010

Finally VS 2010 RC is out.  It’s available to MSDN subscribers today, February 8th.  Everybody else will be able to download it on February 10th.

Posted in Visual Studio, VS2010 CTP | Tagged: | Leave a Comment »

Integrate FxCop 1.36 & VS 2008

Posted by Vadim on May 9, 2009

Update: Visual Studio Team System (VSTS) has Code Analysis feature.  It’s not FxCop but it does serve the same purpose and is built using the same engine as FxCop.  Unfortunately I’m working with VS Professional that doesn’t include Code Analysis.

FxCopI was looking for way to integrate FxCop 1.36 with Visual Studio   2008.  I even asked the same question on StackOverflow.  The only answer I got was a link to MSDN article.  I follow direction in the article but wasn’t successful.  I assume that if you have only one project and don’t have a solution it will work for you but it’s not my case.  I have many project in my solution.  However, the MSDN article got me going.  Let me present you my solution of integration.

Create FxCop project using FxCop GUI.

– Save the project file in the same directory where your solution is.
– Project name must be the file name of your solution (including .sln extension).  For example: If your solution file is MySolution.sln, the FxCop project name must be MySolution.sln.FxCop.

FxCop - Name project

Add FxCop to VS External Tools.

In Visual Studio select Tools->External Tools…  You should see the External Tools dialog box.

You must fill following fields:

Title: FxCop
Command: C:\Program Files\Microsoft FxCop 1.36\FxCopCmd.exe
Arguments: /c /p:"$(SolutionDir)\$(SolutionFileName).fxcop" /cXsl:"C:\Program Files\Microsoft FxCop 1.36\Xml\VSConsoleOutput.xsl"
Initial Directory: C:\Program Files\Microsoft FxCop 1.36
Use output window Must be checked

If you install FxCop in different location than C:\Program Files\Microsoft FxCop 1.36, you need to use your own path.


In case you want to grok the switches we use, you can read more about FxCopCmd options.

Run FxCop from Visual Studio.

We are done.  Now we just need to run FxCop.

Tools –> FxCop should analyze your code and because we checked “Use Output window” in External Tools dialog result should appear in VS output window.

FxCop - result

kick it on

Posted in FxCop, Visual Studio, VS2008 | 21 Comments »

Copy & Paste is broken in Visual Studio 2010 CTP

Posted by Vadim on November 9, 2008

I was astonished when I realized that copying & pasting a line in VS 2010 doesn’t works the same as in previous versions of Visual Studio.  I wasC_Key blogging more than a year ago about wonderful feature how to copy and paste in Visual Studio.

In previous versions you can copy a line by moving cursor anywhere on a line you want to copy and without selecting anything press Ctrl-C.  Then you can paste that  line anywhere by pressing Ctrl-V.  The line will be inserted above the line where the cursor is without breaking that line.

However, in VS 2010 CTP the same technique will not work despite that option to turn this feature on/off exists in Options dialog.  Just open this dialog by selecting Tools/Options and then select Text Editor/All Languages.  ‘Apply Cut or Copy commands to blank lines when there is no selection’ check box should be checked by default.


Actually in previous VS version I notice the same broken behavior with XAML files.

I really hope that Microsoft will make copy & paste work as before.  I’m so used to move line up or down with Ctrl-C and Ctrl-V keys.

kick it on

Posted in Tips And Tricks, Visual Studio, VS2010 CTP | Tagged: , | Leave a Comment »

Problem installing VS 2010 & .NET 4.0 CTP

Posted by Vadim on November 9, 2008

I thought it’s time for me to follow everyone and install Visual Studio 2010.  Microsoft provides us with Virtual PC image that includes Visual Studio 2010 and .NET Framework 4.0.  So I downloaded all 11 parts, each of them is 700 MB except the last 11th part which is 286 MB.

I’m at the next point to extract the virtual machine image.  I eagerly click on Accept button at the EULA screen.  Few minutes later I see the following error when it gets to part 2:

“Write error in the file VisualStudio2010CTP.vhd. Probably the disk is full”


After making sure that I have enough disk space, I Google.  I was very disappointed that this time so reliable Google fail me.

I was able to figure out the problem few minutes later.  The Virtual Machine hard drive image is 23Gb.  I tried to extract it to my external hard drive  that was formatted as FAT32.  The biggest file on FAT32 file system you can have is 4Gb.

So if you encounter the same error just extract the image to hard drive with NTFS file system.

Posted in CTP, Visual Studio | Leave a Comment »

Incremental search in Visual Studio

Posted by Vadim on October 18, 2008

When you’re writing code in VS environment, I bet that you often use Ctrl+F keystroke to display “Find and Replace” dialog box.

There’s a better way.  Next time you need to look for some text in your code, press Ctrl+I and start typing your search.  After the text is found, you can use F3 key to find a next occurrence.

As soon as you press Ctrl+I, you’ll see “Incremental Search:” labelIncrementalSearch on the left part of VS status bar.  Your search text will appear on the status bar as you type it.  If you mistype your search text, you can use Backspace key to correct wrong characters.

kick it on

Posted in Tips And Tricks, Visual Studio, VS2005, VS2008 | Tagged: , , | Leave a Comment »

Shortcut Key to Comment code in VS and SQL Server Management Studio

Posted by Vadim on October 16, 2008

When we learn any programming language, one of the firsCtrl+Ct thing  we discover is the syntax how to comment our code.  Some of you probably already have been using this shortcut key for awhile.

Select multiple lines of code and press Ctrl+K,Ctrl+C, and you hard work is going to be ignored. To reverse just press Ctrl+K,Ctrl+U

These keystrokes will comment/uncomment your code only with line comment like // in C# or — in SQL.  I’m not aware how to comment code with block comment (/**/) without using a plug-in for VS.

One more thing.  If you need to comment/uncomment a single line, you don’t need to select the whole line.  Just move the cursor to any position on the line you want to comment, and let you fingers press the magic combination.

If you like me (there’s nothing wrong to be different from me) and use ReSharper, than you would like to use Ctrl+Alt+/ with line comment and Ctrl+Shift+/ with block comment.

kick it on

Posted in .Net, Coding, ReSharper, Tips And Tricks, Visual Studio | Tagged: , , , | 5 Comments »

Jump between braces in Visual Studio.

Posted by Vadim on July 9, 2008

search_BraceHave you ever scroll, scroll, scroll to find the beginning of if else  statement?  In this post I’m not going to tell you that long methods and classes are evil.  Instead, I want to share with you how to move fast between open and close braces.

Put your cursor before or after the brace (your choice) and then press Ctrl+]. It works with either curly or round braces.  From now on you don’t need to play Where’s Waldo? to find that brace.

I’ve been using this trick since Visual C++ 4.0. 

kick it on

Posted in Tips And Tricks, Visual Studio | 22 Comments »

VS 2005 fails to load.

Posted by Vadim on May 23, 2008

On two different occasions I was asked to help when VS 2005 would not load.  We were able see only VS 2005 splash screen and that’s it.  In first case the CPU usage by devenv.exe was 25%.  To resolve this problem I launched VS in safe mode. 

C:\Program Files\Microsoft Visual Studio 8\Common7\IDE>devenv.exe /SafeMode

This prevents all third-party VSPakages from loading.  After that VS 2005 was loading properly all the time.

I believe that in both cases it happened after the developer installed an add-in.

Posted in Visual Studio, VS2005 | Leave a Comment »

How To: Create a ReSharper File Template.

Posted by Vadim on April 1, 2008

ReSharper is a wonderful tool that makes writing code much easier.  One of the features of this tool is ability to create templates.  With ReSharper you can create Live, Surround With, and File Template.  In this post I want to share with you how to create a File Template for MbUnit Test Fixture.

MbTest Template Selection After completion of this tutorial, you’ll be able to create an MbUnit Fixture by right clicking the test project and adding the test fixture.



Step 1: Open ReSharper – Options dialog.

Start Visual Studio and from menu bar select ReSharper – Options (you also can get there by pressing Alt-R + O).


Step 2: Create a new template.

  • In the left panel select File Templates under Templates section.
  • Then select User Templates in Available templates.
  • In this sample we’re going to create C# template, so select Class (C#) in Quick access list (it should be the first item in the list).
  • Last click on Create Template icon ReSharper Create Template icon to see Edit Template dialog box.

Step 3: Create and save MbUnit Test Fixture template.

  • In Name text box enter MbUnit Fixture.  It’s a name that will appear in the menu when you add a new test fixture.
  • In File name prefix text box enter MbTest.  It’s going to be a suggestion for your test file / class.

ReSharper Edit Template General 

ReSharper Template OptionsNext click on everywhere link next to the word Available to see the Template Options dialog box.  Select Only in projects for language radio button and chose C# projects including ASP.NET C#projects) from the drop-down control. Extension for created files leave as cs.

Now we are ready to create actual template.

Enter the code below into Template text.

   1: using MbUnit.Framework;
   3: namespace $NAMESPACE$
   4: {
   5:    [TestFixture]
   6:    [FixtureCategory("$CATEGORY$")]
   7:    [Author("Vadim Kreynin", "")]
   8:    public class $CLASS$ {$END$}
   9: }

I’m sure that you noticed $NAMESPACE$, $CATEGORY$, and $CLASS$.  These three are ReSharper variables.  You declare a variable by surrounding a word with $ sign.

The reason we created variables because we want to do something with them.

ReSharper has automatically created entries for our variables that looks like this:ReSharper Edit Template Variables

Click on Choose macro link and choose following options in Choose Macro dialog box.

Variable Available macro
$NAMESPACE$ Default namespace for current file
$CATEGORY$ Constant value
$CLASS$ Current file name without extension

Uncheck Editable Occurrence check box for NAMESPACE variable.

You can see that CATEGORY variable has a red link Constant value.  Click on it and enter Category in String value text box of Choose Parameter Value dialog box.

You’re done!  Click on OK button of Edit Template dialog box that should look like this: ReSharper Edit Template

Now you can start using this template.

Next time I’ll show how to create a Live Template for tests, test SetUp(s) and TearDown(s).


kick it on

Posted in .Net, MbUnit, ReSharper, Visual Studio, VS2005, VS2008 | 5 Comments »

Get Array type.

Posted by Vadim on September 5, 2007

Let assume that you have an int array.

int[] intArr = new int[] { 1, 2 };

If you try to get the type of the array, you’ll get int[] type.

Assert.AreEqual(typeof(int[]), intArr.GetType());

So far so good.  But what if code needs to perform different logic for array of ValueType and Reference Type elements.  We all know that int is a ValueType. However, array of int is not. So the if statement below will output ‘Reference Type’.

if (intArr.GetType().IsValueType)
    Console.Write("Reference Type");

Microsoft provided us with GetElementType method that returns the Type of the object encompassed by the array.

if (intArr.GetType().GetElementType().IsValueType)
    Console.Write("Reference Type");

The code above outputs ‘ValueType’ as expected.

Posted in .Net, C#, Coding, Visual Studio | Leave a Comment »