Top visual-studio Questions

List of Tags
760
Herb Caudill

As a long-time Visual SourceSafe user (and hater) I was discussing switching to SVN with a colleague; he suggested using Git instead. Since, apparently, it can be used as peer-to-peer without a central server (we just have a 3-developer team).

I have not been able to find anything about tools that integrate Git with Visual Studio, though - does such a thing exist?

If not, can anyone report on their experiences using Git with Visual Studio?

Answered By: Jon Rimmer ( 631)

In Jan 2013, Microsoft announced that they are adding full Git support into all their ALM products. They have published a plugin for Visual Studio 2012 that adds Git source control integration.

Alternatively, there is a project called Git Extensions that includes add-ins for Visual Studio 2005, 2008, 2010 and 2012, as well as Windows Explorer integration. It's regularly updated and having used it on a couple of projects, I've found it very useful.

Another option is Git Source Control Provider.

382
Robert S.

When I start a new ASP.NET project in Visual Studio i can create a ASP.NET Web Application and new ASP.NET websites in Visual Studio creates new Website.

What's the difference between these two ASP.NET Web Application and ASP.NET Web Sites? Why would I choose one over other?

If I'm using Visual Studio 2005 instead of Visual Studio 2008 or Visual Studio 2010, is the answer different?

Answered By: Andreas Grech ( 285)

Website:

The Web Site project is compiled on the fly. You end up with a lot more DLL files, which can be a pain. It also gives problems when you have pages or controls in one directory that need to reference pages and controls in another directory since the other directory may not be compiled into code yet. Another problem can be in publishing.

If Visual Studio isn't told to re-use the same names constantly, it will come up with new names for the DLL files generated by pages all the time. That can lead to having several close copies of DLL files containing the same class name, which will generate plenty of errors. The Web Site project was introduced with Visual Studio 2005, but it has turned out not to be extremely popular.

Web Application:

The Web Application Project was created as an add-in and now exists as part of SP 1 for Visual Studio 2005. The main differences are the Web Application Project was designed to work similar to the Web projects that shipped with Visual Studio 2003. It will compile the application into a single DLL file at build time. In order to update the project it must be recompiled and the DLL file published for changes to occur.

Another nice feature of the Web Application project is it's much easer to exclude files from the project view. In the Web Site project, each file that you exclude is renamed with an exclude keyword in the filename. In the Web Application Project, the project just keeps track of which files to include/exclude from the project view without renaming them, making things much tider.

Reference: http://www.megasolutions.net/AspNet/difference-between-Web-Site-and-Web-Application-Project-27210.aspx

The article ASP.NET 2.0 - Web Site vs Web Application project also gives reasons on why to use one and not the other. Here is an excerpt of it:

  • You need to migrate large Visual Studio .NET 2003 applications to VS 2005? use the Web Application project.
  • You want to open and edit any directory as a Web project without creating a project file? use Web Site project.
  • You need to add pre-build and post-build steps during compilation? use Web Application project.
  • You need to build a Web application using multiple Web projects? use Web Application project.
  • You want to generate one assembly for each page? use Web Site project.
  • You prefer dynamic compilation and working on pages without building entire site on each page view? use Web Site project.
  • You prefer single-page code model to code-behind model? use Web Site project.

Web Application Projects versus Web Site Projects (MSDN) explains the differences between web site and web application projects. Also, it discusses the configuration to be made in Visual Studio.

What are your recommended extensions for Visual Studio 2010? (Please indicate if its free or not And also its purpose / function too)


Free:

Answered By: HexWrench ( 99)

Resharper (not free)

What is your favorite Visual Studio keyboard shortcut? I'm always up for leaving my hands on the keyboard and away from the mouse!

One per answer please.

Answered By: Glennular ( 181)

Ctrl + - and the opposite Ctrl + Shift + -.

Move cursor back (or forwards) to the last place it was. No more scrolling back or PgUp/PgDown to find out where you were.

This switches open windows in Visual Studio:

Ctrl + tab

Visual Studio solutions contain two types of hidden user files. One is the solution .suo file which is a binary file. The other is the project .user file which is a text file. Does anyone know exactly what data these files contain? I've also been wondering whether I should be adding these files to source control (Subversion in my case). If I don't add these files and another developer checks out the solution, will Visual Studio automatically create new user files?

Answered By: Fabio Ceconello ( 217)

These files contain user preference configurations that are in general specific to your machine, so it's better not to put it in SCM. Also, VS will change it almost every time you execute it, so it will allways be marked by the SCM as 'changed'. I don't include both, I'm in a project using VS for 2 years and had no problems doing that. The only minor annoyance is that the debug parameters (execution path, deployment target, etc.) are stored in one of those files (don't know which), so if you have a standard for them you won't be able o 'publish' it via SCM for other developers to have the entire development environment 'ready to use'.

Is it possible to find the number of lines of code in an entire solution? I've heard of MZ-Tools, but is there an open source equivalent?

Answered By: Ali Parr ( 100)

An open source line counter for VS2005, 2003 and 2002 is available here:

http://www.wndtabs.com/

There is also discussion of creating a line counting VS addin, complete with code on Codeproject, here

http://www.codeproject.com/KB/macros/LineCounterAddin.aspx

Also Slick Edit Gadgets have a nice line-counter, here:

http://www.slickedit.com/index.php?option=com_content&view=article&id=78&Itemid=90

and Microsoft Visual Studio Team System 2008 includes a good line counter.

Just remember though:

Measuring programming progress by lines of code is like measuring aircraft building progress by weight. Bill Gates

How can I limit my post-build events to running only for one type of build? I'm using the events to copy DLLs to a local IIS virtual directory but I don't want this happening on the build server in release mode.

Answered By: Joseph Daigle ( 211)

Pre- and Post-Build Events run as a batch script. You can do a conditional statement on $(ConfigurationName).

For instance

if $(ConfigurationName) == Debug xcopy something somewhere

Visual Studio is such a massively big product that even after years of working with it I sometimes stumble upon a new/better way to do things or things I didn't even know were possible.

For instance-

  • Crtl + R, Ctrl + W to show white spaces. Essential for editing Python build scripts.

  • Under "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\Text Editor" Create a String called Guides with the value "RGB(255,0,0), 80" to have a red line at column 80 in the text editor.

What other hidden features have you stumbled upon?

Answered By: shoosh ( 123)

Make a selection with ALT pressed - selects a square of text instead of whole lines.

In Visual Studio (2008) there a command to collapse/expand all the sections of code in a file?

Answered By: Bob ( 364)

CTRL + M + O will collapse all.

CTRL + M + L will expand all.

CTRL + M + P will expand all and disable outlining.

CTRL + M + M will collapse/expand the current section.

These options are also in the context menu under Outlining.

161
Ian Patrick Hughes

I feel ridiculous for asking this because it seems like it should be so simple, however I have been unable to discover an answer to this question.

I have a free standing set of files not affiliated with any C# project at all that reside in a complicated nested directory structure. I want to add them in that format to a different directory in an ASP.NET web application I am working on; while retaining the same structure. So, I copied the folder into the target location of my project and I tried to “add existing item” only to lose the previous folder hierarchy. Usually I have re-created the directories by hand, copied across on a one-to-one basis, and then added existing items. There are simply too many directories/items in this case.

So how do you add existing directories and files in Visual Studio 2008?

Answered By: Darren Kopp ( 155)

drag the files / folder from windows explorer into the solution explorer. it will add them all.