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

Wednesday, November 16, 2022

Visual Studio Debugging Windows: Watch, Locals, Autos, Immediate, Call Stack and Threads

The Watch Window

The Watch Window allows you to see value of variables and expressions while debugging. It’s kind of like the DataTip you get when hovering over a variable, except that you can write any expression you want. It’s available from Debug | Windows | Watch | Watch 1 or Ctrl + Alt + W + 1.

There are 4 watch windows in Visual Studio, which you can use in different contexts (Watch 1, Watch 2, etc.).

Any expression can be entered into the watch window. The same rules apply to expressions as to code. So if you write an illegal expression, you’ll see the same compiler error.

To add items to watch do any of the following:

  • Write them manually in a new row of the Watch window
  • Right-click on a variable choose “Add Watch” in the context menu
  • Right-click on a variable in the DataTip and choose “Add Watch”
  • “Add Watch” button from QuickWatch

When to Use the Watch Window:

While the DataTip and QuickWatch are more popular, the watch window is very useful when you need to re-evaluate the same variables and expressions multiple times. This happens if you hit the same breakpoint over and over again, or different breakpoints in the same class. The most common scenario is with a breakpoint inside a loop

The Immediate Window

The immediate window is available in the menu from Debug | Windows | Immediate or Ctrl + Alt + i. You can type in any expression and the immediate window will evaluate. It’s kind of like the Watch window, but it acts more like a command line window in Windows or Linux.

For me, the immediate window was always more convenient than the Watch or QuickWatch windows.

  • Like in command line interfaces, you can use the Up/Down arrow keys to paste previous expressions.
  • To clear the window, right-click on it and select “Clear All”.

Locals and Autos Windows

VS offers 2 automatic-watch tool windows: The Locals and Autos windows.

The Locals will show local variables of the current scope. It usually starts with this, which represents the current class.

The Autos window will show all variables used in the current line and in the previous line. These could be local variables, class members or static variables. The Autos also shows values returned from methods, which is useful at times

  • In both Locals and Autos, you can double click on any Value field and change the variable’s value. This will actually its value, causing a possibly unwanted side effect.
  • Search works same as in the Watch window.

Call Stack Window

One of the most useful tool windows is the Call Stack Window. It shows the chain of methods that called one another, up to the the currently debugged method

Threads Window

The Threads Window is the final tool window in what I call the Truly Vital Debugging Windows group. This window shows all the currently active threads, and allow to switch between them.

 

Sunday, June 05, 2022

How to build using command line from Visual Studio?

Here is how we can build using command line or terminal for Visual Studio using msbuild tool

1. Open Terminal from Visual Studio

2. On the terminal type msbuild to build current project 

msbuild /t:build

3. To clean here is the syntax

msbuild /t:clean

4. To Rebuild 

msbuild /t:rebuild

More examples

Examples:

MSBuild MyApp.sln -t:Rebuild -p:Configuration=Release

MSBuild MyApp.csproj -t:Clean

                             -p:Configuration=Debug;TargetFrameworkVersion=v3.5

For more detailed information, see https://aka.ms/msbuild/docs 


Friday, April 20, 2018

Duplicate Menu Items in Visual Studio

Recently I had a situation with Visual Studio 2010 where menu items where duplicated like 3-4 times. Looks like some configuration file was corrupted. I have tried to restore current settings and setup new settings but none worked out.

To resolve this I ran the following from command line

devenv.exe /safemode /setup

Once this ran, I restarted Visual Studio I could able to see Visual studio with default factory settings.

PS: If you have any personal settings done before you have to redo those settings again.

Monday, December 26, 2016

How to load Visual Studio without extensions

All versions of visual studio can be started with a set of arguments.

Using devenv.exe /SafeMode allows you to run any version of visual studio (devenv.exe) in SafeMode that will disable 3rd party plugins.

Using devenv.exe /ResetSettings will restore Visual Studio default settings

Run these commands from Command prompt in admin mode. For additional options refer MSDN for help.

Saturday, April 20, 2013

How to Remove Css Style from codebehind?

Here is how we can achieve this from codebhind in c#. Here is the sample code snippet I am here removing CssSytle from DIV but I works for any Control

   1: // Removing Div class when we have only transaction details
   2: divTransactionSummary.Attributes.Add("class", divTransactionSummary.Attributes["class"].ToString().Replace("prodiv", ""));
   3:               

Here “prodiv” is the class of div I have used in my aspx page for this DIV


Hope this helps!!

Tuesday, April 03, 2012

How to: Share Visual Studio Settings Between Computers or Visual Studio Versions

There's a real cool functionality that's built into Visual Studio that allows me to set up the Visual Studio environment just the way I like it, then I can export those settings out and then import them into another instance of Visual Studio. So say I have Visual Studio running on my development machine at work then I have a copy of Visual Studio on my laptop so that I can work at home or work on the weekends, or whatever. It'd be really cool if both of these environments matched. It's going to help productivity. It's going to make it easier for me just to live and get around. Well, first thing, if we go to Tools, Options I want to show you something. There's an Import-Export Settings and yours may look like this.

1

You will have to expand Environment and you will see Import Export Settings. Now it's going to tell you that I can use team settings files if I'm using a team server or I can automatically save my settings to this particular file. And if I click Browse I can jump out and put it wherever I would like, but you can notice by default here.

image

if I just click up here in the text box, the drop-down box, it's going to put it on C:\Users\nagasai\documents\Visual Studio 2010\Settings folder. And then I can give it a name, whatever I would like. So this is where I can work with that. Now, what's really cool is, if I go back to Tools you will notice down here we've been going to Options but right above Options is an Import and Export Settings, and so I will click on that and you will notice that I can export selected environment settings, or I can import. Well, let's say that I want to save the settings that I have out, so I click Next. And notice it says, What do you want to send out? I want all my Code Analysis, Database Tools, General Settings, my Team Foundation Server settings, and then notice on Options it's saying wait a minute. You've got some things here that you may want to go take a look at, and it is saying I may have some things on the Import-Export Settings that I need to go take a look at. This is warning me, notice up here, that it might expose intellectual property or other sensitive information, and so it's saying not to choose those and I can read F1, but for now we're just going to leave that alone. Actually, I'll just clear that for now, and I'll just choose Next and it's asking me, what do you want to name your settings file? And I will just call it MTL Exported VS Settings and I will tell it where to save those, and actually, just for the purpose of this I'll put it on the Desktop and I will click Save and then I will click Finish and notice my settings were exported out there.

3

Now if I minimize this and let me just make this easy on myself and go out to the Desktop, notice there are my exported files, so all I have to do is put that on a thumb drive, take it to another machine and import it into another Visual Studio instance and I will have everything there just like I wanted. Now, let me go back to something else. If you remember, I talked about this particular little guy right here that shows up the first time you start Visual Studio. Well, what if you chose something here that you don't like and now you want to go make a change to that? After the first time that you see this screen and you make a choice here and start Visual Studio you will never see this particular dialog box again. So what we're going to have to do to make changes to that, if you ever want to, is go into Import and Export Settings and you can tell it that you can Reset All Settings and you can say just Reset, and notice it's going to take you right back to that same screen with a couple of differences and I can say, you know what, just give me General Development Settings, or give me Visual Basic but let's say that we want to go back to General.

 

Now we just click Finish and it's resetting them and now when we start up we're going to see, in all of our projects and everything, General Settings out there.

image

image

So I hope this doesn't confuse you, but the way Microsoft did that with that screen, that dialog box popping up the first time and then never coming back, a lot of people are like, well, wait a minute. I don't like the choice I made. How do I get back to that and make changes on it? So, very easy to import and export settings so that you have the consistent environment across all your copies of Visual Studio. So, make sure that you use that to set up multiple copies so that you're the same everywhere you go

Hope this helps…Smile

Monday, June 06, 2011

Difference Between Add Service Reference And Web Reference?

Service References or WCF comes from VS 2008 and above with an extension as .svc and Web References are their from the beginning as .asmx.

The main difference between WCF service and Webservice while consuming, we need to add them in solution as reference to access them.

Add Web Reference is a wrapper over wsdl.exe and can be used to create proxies for .NET 1.1 or 2.0 clients. This means we are pointing to a WCF service you have to be pointing to an endpoint that uses basicHttpBinding.

Add Service Reference is a wrapper over svcutil.exe and also creates clients proxies (and additionally web.config entries). These proxies, however, can only be consumed by .NET 3.0+ clients.

Below image will show you how to add web reference from Service Reference. Right click theService References from solution explorer, then select advance button on Add Services windowyou will get to the form as in below image and then will be able to add Web Reference via Addweb Reference window..

image

But there is some things which changed in VS2010 about adding web references to a class library. So in VS 2010 you cannot add Web Reference directly.  Here is how you need to do it.

From Project -> Add Service Reference ..., (From Solution Explorer, Right Click on Project, From the drop down Menu, Select Add Service Reference)

image

This window will appear, Click advanced,

image

On Add Service Settings window, Now click on Add Web Reference

image

This will open add Web reference window from where we can add web service. Hope this helps. Good luck.

Saturday, March 12, 2011

Difference Between Build and Re-Build in Visual Studio .Net?

Build means compile and link only the source files that have changed since the last build, while Rebuild means compile and link all source files regardless of whether they changed or not. Build is the normal thing to do and is faster. Sometimes the versions of project target components can get out of sync and rebuild is necessary to make the build successful. In practice, you never need to Clean.

Build or Rebuild Solution builds or rebuilds all projects in the your solution, while Build or Rebuild <project name> builds or rebuilds the StartUp project. To set the StartUp project, right click on the desired project name in the Solution Explorer tab and select Set as StartUp project. The project name now appears in bold.

Build.BuildSolution F6 or CTRL+SHIFT+B Builds all the projects in the solution.
Build.BuildSelection SHIFT+F6 Builds the selected project
and its dependencies.

Hope this helps Smile

Thursday, January 06, 2011

assemblyBinding: Using Shared DLLs in .NET

How to Share DLLs in VS 2010. Recently I and my team had a problem working with a Shared DLL. Our developers are saving our project in different locations of our computer. Few are saving in D drive and few in E drive. So while getting latest solution from the Visual source safe some of us are having missing references problem with the DLLs when we have Shared DLLs in a location. So to resolve this we have created a folder in *\bin folder with name Shareddlls and placed all the Shared dls in that folder.

Once we have done this we need to add piece of code in web.config.

 <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="bin;bin/shareddlls" />
    </assemblyBinding>
  </runtime>

This worked perfectly for me. Microsoft rocks. When I first read that .NET assemblies could be "redirected" at runtime, I was stunned and a little bit suspicious. By using Assembly Binding Redirection you can redirect an assembly binding reference to another version of an assembly by using entries in the application or machine configuration files. You can redirect references to .NET Framework assemblies, third-party assemblies, or assemblies of your own application. Each version of the .NET Framework has a machine configuration file, and any redirection information in that file affect all applications running under that version of the .NET Framework.


Redirecting .NET Framework Assembly Binding


The .NET Framework assembly unification model treats all .NET Framework assemblies of a given version, and the runtime of that version, as a single unit. The redirections that occur with this model are the default behavior for the runtime.
There are several ways to instruct the runtime to load a .NET Framework assembly with a different version than that of the loaded runtime:



  • Add settings in the application configuration file.

  • Add settings in the machine configuration file.

  • Create a publisher policy file that is distributed with a component to specify which assemblies a component should use.

A binding redirection in an application configuration file for a unified .NET Framework assembly cancels the unification for that assembly. To redirect an assembly binding reference for an assembly that is not part of the .NET Framework, specify the binding redirection information in the application configuration file using the <assemblyBinding> element.

Tuesday, December 28, 2010

Working with the ASP.NET Global.asax file

The Global.asax file, sometimes called the ASP.NET application file, provides a way to respond to application or module level events in one central location. You can use this file to implement application security, as well as other tasks.

Overview

The Global.asax file is in the root application directory. While Visual Studio .NET automatically inserts it in all new ASP.NET projects, it's actually an optional file. It's okay to delete it—if you aren't using it. The .asax file extension signals that it's an application file rather than an ASP.NET file that uses aspx.

The Global.asax file is configured so that any direct HTTP request (via URL) is rejected automatically, so users cannot download or view its contents. The ASP.NET page framework recognizes automatically any changes that are made to the Global.asax file. The framework reboots the application, which includes closing all browser sessions, flushes all state information, and restarts the application domain.

 

Programming

The Global.asax file, which is derived from the HttpApplication class, maintains a pool of HttpApplication objects, and assigns them to applications as needed. The Global.asax file contains the following events:

  • Application_Init: Fired when an application initializes or is first called. It's invoked for all HttpApplication object instances.
  • Application_Disposed: Fired just before an application is destroyed. This is the ideal location for cleaning up previously used resources.
  • Application_Error: Fired when an unhandled exception is encountered within the application.
  • Application_Start: Fired when the first instance of the HttpApplication class is created. It allows you to create objects that are accessible by all HttpApplication instances.
  • Application_End: Fired when the last instance of an HttpApplication class is destroyed. It's fired only once during an application's lifetime.
  • Application_BeginRequest: Fired when an application request is received. It's the first event fired for a request, which is often a page request (URL) that a user enters.
  • Application_EndRequest: The last event fired for an application request.
  • Application_PreRequestHandlerExecute: Fired before the ASP.NET page framework begins executing an event handler like a page or Web service.
  • Application_PostRequestHandlerExecute: Fired when the ASP.NET page framework is finished executing an event handler.
  • Applcation_PreSendRequestHeaders: Fired before the ASP.NET page framework sends HTTP headers to a requesting client (browser).
  • Application_PreSendContent: Fired before the ASP.NET page framework sends content to a requesting client (browser).
  • Application_AcquireRequestState: Fired when the ASP.NET page framework gets the current state (Session state) related to the current request.
  • Application_ReleaseRequestState: Fired when the ASP.NET page framework completes execution of all event handlers. This results in all state modules to save their current state data.
  • Application_ResolveRequestCache: Fired when the ASP.NET page framework completes an authorization request. It allows caching modules to serve the request from the cache, thus bypassing handler execution.
  • Application_UpdateRequestCache: Fired when the ASP.NET page framework completes handler execution to allow caching modules to store responses to be used to handle subsequent requests.
  • Application_AuthenticateRequest: Fired when the security module has established the current user's identity as valid. At this point, the user's credentials have been validated.
  • Application_AuthorizeRequest: Fired when the security module has verified that a user can access resources.
  • Session_Start: Fired when a new user visits the application Web site.
  • Session_End: Fired when a user's session times out, ends, or they leave the application Web site.

The event list may seem daunting, but it can be useful in various circumstances.

A key issue with taking advantage of the events is knowing the order in which they're triggered. The Application_Init and Application_Start events are fired once when the application is first started. Likewise, the Application_Disposed and Application_End are only fired once when the application terminates. In addition, the session-based events (Session_Start and Session_End) are only used when users enter and leave the site. The remaining events deal with application requests, and they're triggered in the following order:

  • Application_BeginRequest
  • Application_AuthenticateRequest
  • Application_AuthorizeRequest
  • Application_ResolveRequestCache
  • Application_AcquireRequestState
  • Application_PreRequestHandlerExecute
  • Application_PreSendRequestHeaders
  • Application_PreSendRequestContent
  • {{{{code executed}}}}
  • Application_PostRequestHandlerExecute
  • Application_ReleaseRequestState
  • Application_UpdateRequestCache
  • Application_EndRequest

A common use of some of these events is for security. The Global.asax file is the central point for ASP.NET applications. It provides numerous events to handle various application-wide tasks such as user authentication, application start up, application error and dealing with user sessions etc. You should be familiar with this optional file to build robust ASP.NET-based applications.

Wednesday, May 26, 2010

Tips & Tricks : Visual Studio

Shortcuts Its fun and helpful. They are helpful for faster development and easy. Here are the few shortcuts that we use regularly.

Usage C# Key Description
View.ShowSmartTag CTRL + .  
Edit.ParameterInfo CTRL + SHIFT + SPACE  
Edit.Find CTRL + F Quick find
Edit.IncrementalSearch CTRL + I Incremental find
Edit.FindInFiles CTRL + SHIFT + F Find in files
Edit.Replace CTRL + H Quick replace
Edit.ReplaceInFiles CTRL + SHIFT + H Replace in files
Edit.GotoNextLocation F8 Go to next location (in search results)
Edit.GotoPrevLocation SHIFT + F8 Go to previous location (in search results)
Edit.FindNext F3 Repeat search
Edit.FindPrevious SHIFT + F3 Search previous
Edit.FindNextSelected CTRL + F3 Search for next with selected text
Edit.FindPreviousSelected CTRL + SHIFT + F3 Search for previous with selected text
     
View.NavigateBackward CTRL + - Go back to previous location (Browser-style)
View.NavigateForward CTRL + SHIFT + - Go forwards to next location
View.ViewCode F7 View code
View.ViewDesigner SHIFT + F7 View designer when in markup
View.ViewMarkup SHIFT + F7 View markup when in designer
     
Edit.CycleClipboardRing CTRL + SHIFT + V Cycle through Visual Studio clipboard
     
Edit.GotoBrace CTRL + ] Jump to opposing brace / XML tag
Edit.GotoBraceExtend CTRL + SHIFT + ] Select text to the opposing brace / tag
     
Edit.GotoFindCombo CTRL + / Jump to the find combo in the toolbar
     
Window.ShowEzMDIFileList CTRL + ALT + DOWN ARROW Show popup of all open files
     
Debug.Start F5 Start with debugger
Debug.StartWithoutDebugging CTRL + F5 Start without debugger
Debug.Restart CTRL + SHIFT + F5 Restart the program
Debug.StopDebugging SHIFT + F5 Stop debugger
Debug.RunToCursor CTRL + F10 Run to the cursor
Debug.ToggleBreakpoint F9 Set / remove breakpoint
Debug.DeleteAllBreakpoints CTRL + SHIFT + F9 Delete all breakpoints
Debug.EnableBreakpoint CTRL + F9 Enable a breakpoint
Debug.StepInto F11 Step into a method
Debug.StepOut SHIFT + F11 Step out of a method
Debug.StepOver F10 Step over a line
     
Tools.RecordTemporaryMacro CTRL + SHIFT + R Start recording a macro
Tools.PlayTemporaryMacro CTRL + SHIFT + P Playback a macro

 

If you want an even more comprehensive list of keyboard combinations, you can check out the following links, or go exploring in Tools > Options > Keyboard in Visual studio.

C# Keybindings

VB Keybindings

Tuesday, November 17, 2009

Visual Studio 2005/2008 tips & tricks

Check this URL for tricks and tips by which you can enhance your productivity and efficiency

Microsoft Code Analysis Tool .NET (CAT.NET)

CAT.NET is a snap-in to the Visual Studio IDE that helps you identify security flaws within a managed code (C#, Visual Basic .NET, J#) application you are developing. It does so by scanning the binary and/or assembly of the application, and tracing the data flow among its statements, methods, and assemblies. This includes indirect data types such as property assignments and instance tainting operations. The engine works by reading the target assembly and all reference assemblies used in the application -- module-by-module -- and then analyzing all of the methods contained within each. It finally displays the issues its finds in a list that you can use to jump directly to the places in your application's source code where those issues were found. The following rules are currently support by this version of the tool. - Cross Site Scripting - SQL Injection - Process Command Injection - File Canonicalization - Exception Information - LDAP Injection - XPATH Injection - Redirection to User Controlled Site

Click here to Download