Unable to set break point for debugging in Visual Studio

Getting “The breakpoint will not currently be hit. No symbols have been loaded for this document.” in Visual studio whenever you try to debug?
There are a million solutions out there and every time it is a different issue.

Here is one way of sorting things out in VS2012:

Go to Tools -> Options -> Debugging -> Symbols.
Hit Empty Symbol Cache and select All Modules Unless Excluded.

Possibly will need to restart VS. And should work.

Generate T4MVC templates

Everybody is talking how good the T4 templates, but nobody tells you how to generates the bloody things.

In VS2012 if you open command window (View-> Other Windows -> Command Window) and execute
TextTransformation.TransformAllTemplates – that should do the trick.

If you would like a button for that – add Build Toolbar Panel and it should contain “Transform All Templates” button.

Or you can install Chirpy and configure it to do T4MVC for you on every build:

Entity Framework, Update-Database command gives “Object reference not set” error

If Entity Framework (version below 5.1) on your attempt to Update-Database gives you error of “Object reference not set”, change the default start-up project to MVC project, not anything else. And try the same thing again.
This reported to be fixed in the latest 5.x version of EF, but it is a little annoyance just now.

p.s. This can be eased with parameter: -StartupProject “helloMVC” when running Update-Database command

Visual Studio Code Snippets

Visual Studio Code snippets are handy way of increasing your speed of development.

User keyboard shortcuts
CTRL+K + X for code snippet
CTRL+K + S for Surround With snippet

Here are most of the described: http://msdn.microsoft.com/en-us/library/z41h7fat%28v=vs.100%29.aspx

Or you can download this Word document and print them out – the same information, only in printer-friendly view.

VS 2010 Build problem

Sometimes Visual Studio is playing silly buggers and does not let you rebuild your C# project.
For avoiding this follow the instructions:
Project properties => Build Events
in Pre-build event put this:
if exist “$(TargetPath)” move “$(TargetPath)” “$(TargetPath).delete.%random%”
in Post-build event put this:
del “$(TargetPath).delete.*”

Problem solved

Visual Studo 2010 Useful Shortcuts

  • **CTR + ALT + L **- move to Solution Explorer
  • Type (for example “try” or “for”) and hit Tab twice for code snippet auto-completion.
  • Ctrl + – and the opposite Ctrl + Shift + – Move cursor back (or forwards) to the last place it was. No more scrolling back or PgUp/Dwn to find out where you were.
  • Ctrl + I – Incremental Search
  • Shift+Alt+Enter window in focus in full screen mode. Hit it again, and you have all the panels back. ****
  • Ctrl + Alt + I – jump to Immediate Window
  • Tools -> Options -> Environment -> Keyboard. Type “Navigation” to get the shortcut to combo-box on top of the window.
  • Ctrl + Shift + , or Ctrl + Shift + . to zoom-in or zoom-out
  • Ctrl + M + M – collapse/expand current region
  • Ctrl + M + O – collapse  all regions
  • Ctrl + M + L – expand  all regions
  • CTRL+K + X – code snippet
  • CTRL+K + S – Surround With code snippet More shortcuts are here:

http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=13189 Or here: http://www.itscodingtime.com/post/Visual-Studio-2010-Keyboard-Mouse-Shortcuts.aspx

Visual Studo Shortcuts as in Eclipse

Using both Eclipse and Visual Studio can be a pain, when it comes to shortcuts.
In VS you can change shortcuts here: Tools -> Options -> Environment -> Keyboard

Change the following:
Delete line: Edit.lineDelete -> Ctrl + D
Comment line: Edit.CommentSelection -> Ctrl + /
Uncomment line: Edit.UnCommentSelection -> Ctrl + Shift + /
Goto Definition: Edit.GoToDefinition -> F3
Goto Navigation Bar: Window.MovetoNavigationBar -> Ctrl + #

To be able to move lines up and down like in Eclipse (alt + up; alt + down) you’ll need to create 2 macros:

    Sub MoveLineUp()
        DTE.ActiveDocument.Selection.Collapse()
        DTE.ActiveDocument.Selection.Cut()
        DTE.ActiveDocument.Selection.LineUp()
        DTE.ActiveDocument.Selection.Paste()
        DTE.ActiveDocument.Selection.LineUp()
    End Sub

    Sub MoveLineDown()
        DTE.ActiveDocument.Selection.Collapse()
        DTE.ActiveDocument.Selection.Cut()
        DTE.ActiveDocument.Selection.LineDown()
        DTE.ActiveDocument.Selection.Paste()
        DTE.ActiveDocument.Selection.LineUp()
    End Sub

then the same way you change shortcuts in VS, find “moveLineUp” and “moveLineDown” and assign Alt + UP and Alt + Down.
Alternatively install Productivity Power Tools that provide Edit.MoveLineUp and Edit.MoveLineDown

I’ll keep updating as it comes along.