Showing posts with label Visual Studio tip. Show all posts
Showing posts with label Visual Studio tip. Show all posts

05 November 2017

viewing c# language ver used in a project

Have you ever wondered what is the C# language version used in your C# .NET project. You might have not worried about it because the version of the C# version used depends on the .NET framework version you have used for the project. In this blog post let's see how to view and change the C# version for the project.

How to view & change c# language version

  • Right click on the .NET project in visual studio and choose Properties.
  • In the left navigation tree, click on the "Build" tab. And browse to the end of the screen and click on the "Advanced..." button.
  • By default Language Version is "default", meaning it uses major C# language version. In the case below as you can see in the image, "default" means "C# 7.0".
  • 25 October 2017

    with net-framework-4-6-2 now you can see variabe caused the NullRefereneException

    Today I was going though below .NET Blog post to know more detail on the framework 4.6.2 features.

    Out of many, I found a very useful feature. Now when we encounter NullRefereneException, it’s going to say which variable caused it. This will save a ton of time for sure while fixing object reference not set to an instance of an object.

    https://blogs.msdn.microsoft.com/dotnet/2016/08/02/announcing-net-framework-4-6-2/

    18 June 2017

    track active item in Visual Studio Solution explorer

    If you are working on a BIG solution in Visual Studio, then click the file tab doesn't highlight the file in Solution Explorer by default. This causes you manually going through & searching the solution explorer tree view to find the find file. This task can be daunting every time when you want to do this, especially when you are new to .NET solution and the solution is BIG with more projects added into it.

    This problem can be easily solved by enabling "Track Active Item In Solution Explorer" option. Post enabling Track Active Item In Solution Explorer and switch to any file tab in visual studio, the file will be automatically highlighted in the Solution Explorer. So it will become easy to find where in the Solution Explorer the file is located.

    How to enable this hidden gem "Track Active Item In Solution Explorer"

    1. Click "Tools" menu in Visual Studio and then select "Projects and Solutions" in tree view located in left hand side.
    2. Locate check box "Track Active Item In Solution Explorer", select the option and click OK button to save the changes.

    Visual Studio Tool Window showing Track Active Item In Solution Explorer option

    Track Active Item In Solution Explorer option
    Happy coding!

    14 June 2017

    GUID generator in Visual Studio

    While writing scripts at times you need to use GUID value as a constant value, etc. There are many options to generate GUID. You could write your own batch script to generate the GUID or you could use other program to generate a GUID.

    However if you are using Visual Studio IDE, there is readily an option available to generate the GUID.

    Steps to generate GUID in visual Studio

    1. On the tool menu, select CREATE GUID menu item. It opens up CREATE GUID window

    2. In the CREATE GUID window, click on the copy button to copy the generate GUID to clipboard
    3. If you want to generate one more GUID, click on the New GUID button

    Sample GUID generation output

     // {7154E924-A0AD-4042-A638-AE022911BEF2}
    IMPLEMENT_OLECREATE(<<class>>, <<external_name>>, 
    0x7154e924, 0xa0ad, 0x4042, 0xa6, 0x38, 0xae, 0x2, 0x29, 0x11, 0xbe, 0xf2);

    GUID window

    Generate-GUID-in-visual-Studio-IDE

    19 July 2015

    running an application as ADMIN always

    Often you are required to run an application as an Administrator, otherwise, the application might not start at all or it might not work to its full extent. On windows platform, few such examples include but not limited to Visual Studio, Internet Information Services (IIS), etc. To debug an application you need to start visual studio as an ADMIN and for IIS, you need to be an ADMIN even to open it.

    Sometimes it so happens that, you start Visual Studio (VS) and when you try to debug you get a warning saying, you cannot debug, because Visual Studio (VS) is not running as an ADMIN. Then you need to exit VS and start again as an Admin. So wouldn't be great if you able to start such app always as an ADMIN by default?.

    Below are the steps to run an application as an ADMIN always (on Windows 7 OS). You need to be an Admin on the System to do this changes!

    1. Locate the application EXE. Right Click on the EXE and open the Application Properties window.
    2. Select Compatibility tab and Click on the button, "Change Settings for all Users".
      Running application as ADMIN showing compatibility tab
    3. It opens up another window with options to manage "Compatibility for all users". Under Privilege section, check the option "Run this program as an Administrator" option and save the changes.

    After these changes, next time when you start an application, it will start by default an administrator, which definitely will save some time for you!

    14 May 2015

    breakpoint condition in visual studio

    Recently I was debugging a multithreaded application to root cause an unhandled exception in one of the for-each iteration on a thread. The for-each statement was being executed thousands of times, so it was too much to time to wait for the failing iteration to occur.

    To save my time a cool feature in the visual studio called Breakpoint condition came to rescue to exactly specify a condition on when the breakpoint needs to be hit. If the specified condition evaluates to true the breakpoint will be hit and allows you have debug further.

    foreach(Control control in controls){
    ProcessControl(control);
    }

    Steps to add a condition breakpoint

    1. In the above for each code, add a break point on the line which is invoking ProcessControl() method. And right click on the breakpoint to open the below menu.
    2. Click on the “Condition…” menu item. It will open the Break point condition windows. Enter your condition there. For the condition you can use any varibale which you can access in the line of code where you have put the breakpoint.
    3. When the breakpoint condition is met the breakpoint will be hit. Later you can debug as usual.