Skip to content

jmarolf/getting-started

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VS and You

This is a resource for getting started with Visual Studio in devdiv!

This repo contains a trimmed down .NET console app from our csharp tutorial docs. We'll use it to demonstrate the got-to-know features of Visual Studio.

Table of Contents

Resources

Getting Started

Learning .NET

Source Control

git checkout -b dev/alias/branch-name origin/master

  • github (where all the open source is) -> fork model (more about that here)

git checkout -b branch-name upstream/master

Installation

image

Developer command prompt

image

  • Where it is
    • Searchable from the start menu
    • Script is located under C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat
  • What is does
    • Puts a lot of tools (msbuid.exe most importantly) on your path.
    • Tells build scripts which visual studio you want to use to build
  • Why you need it
    • Ensures that all the tools can be found
    • Allows you to have multiple versions of Visual Studio installed at once

Using Visual Studio

New Project Dialog

image

  • Clone code
    • Can be used to clone a git repository if you need it
  • Open project
    • Probably the most used button :) opens an existing project
  • Open folder
    • Allows you to open a folder. Not as useful as open project for .NET
  • Create project
    • UI to help you create a new project

Solution Explorer

image

  • Not a file view, shows 'projects'
  • Scope to this
    • "I do not need to see all these other things right now, I need to focus"
  • Search and filter (CTRL+;)
    • "I know the file I am looking for is in this view"
  • Right click menu de-confuse-o-tron
    • Build / Rebuild / Clean
      • "Make sure I am in a sane state"
    • Run Tests
      • "Run all the tests in this project"
    • Set as startup project
      • "This is the thing I want to launch in the debugger"

Code Editor

Basics

image

  • Multi-instance
    • You can open as many visual studios as you want!
  • Find: (CTRL+F)
    • When all else fails just search all the code files for the string 'goo'
  • Intellisense: (CTRL+space)
    • Shows what is valid in certain contexts. also suggests names, offers snippets and is an all-around swell guy
  • Copy/cut line (CTRL+c/CTRL+v)
    • Remove blank lines or delete large section of text
    • Move line (ALT+up/ALT+down)
      • Use with copy/paste line to save some typing
    • Line numbers
    • Go to line (CTRL+g)
      • "Build log says the exception occurred on line xxx in file yyy"
    • Add/remove bookmark (CTRL+k,CTRL+k)
  • CTRL+Q
    • Search for anything if you know the name
  • Rename (CTRL+R,CTRL+R)
    • Safely rename a class. method, anything (can even rename the file for you!)
  • Multi-cursor (CTRL+d)
    • For complex replacements and edits (replace BankAccount with BankBuilding for example)
  • Code fixes (CTRL+.)
    • Should be able to fixup errors and generally save time
  • Build (CTRL+Shift+B)
    • Compile all your changes and write them to disk

Important General Tool Windows

image

  • Error List (CTRL+shift+M)
    • Filtering categories
      • "Only show me errors please"
    • Checkboxes for error codes
      • "I want to fix this specific error everywhere first"
    • Searching
      • "How many errors are about variable 'goo'?"
  • Output Window (CTRL+shift+U)
    • For when real problems happen
      • "I am going to copy and paste this into and email and ask for help"
  • Bookmarks window (no short cut by default, use CTRL+Q)
    • "Let me keep track of interesting places in the code"
  • Task list (CTRL+,T)
    • "Lets make sure I don't forget to do this before I submit a pull request"

Controlling Views and Windows

image

  • Split window
    • For when the method is just too long and you need to see two parts at once
  • Duplicate window (CTRL+K,O)
  • Pin tab
    • This tab is better and more important than the others
  • Window layout
    • Save and load custom window layouts
  • Vertical tabs
    • You get more space for code

Symbol Navigation

image

  • Go to: (CTRL+T)
    • Navigates you to anything you type (uses fuzzy matching)
    • "There should be a test named 'Parser Test' somewhere"
  • Go to definition / Peek: (F12/ALT+F12)
    • "Where was this first created / declared?"
  • Go to implementation: (CTRL+F12)
    • "Take me to the place where the functionality lives"
  • Go to base: (ALT+HOME)
    • "Take me up a level"
  • Find-all-references: (Shift+F12)
    • "Show me everyone that reads or writes to this"

Tools, Options

image

  • Settings de-confuse-o-tron (CTRL+,)
    • Full Solution Analysis
      • Always analyze everything vs. just the current document
    • Intellisense for un-imported types
      • Intellisense can complete even more things
    • De-compiler
      • I want to see how this is implemented

Solving Problems in Visual Studio

Debugging

Setup

image

  • Symbols
    • you need 'em
    • with the microsoft symbol server (http://symweb) you should be able to debug into anything!
  • Default setting you should use
    • Enable "Just My Code"
      • makes debugging faster
      • turn this off if you want to debug things that are not in your solution or project
    • Enable source server support
      • Allows you to use the microsoft symbol servers
    • Enable Source Link support
      • Allows you to get symbols for open source projects
    • Suppress JIT optimization
      • Due to the way VS is architected some breakpoints will not be hit unless this in on

Basic

  • Add/Remove Breakpoint (F9)
  • Debug (F5)
    • Big green 'play' button
    • Launches whatever is set as the 'Startup Project'
  • Step Over (F10)
    • "Go to the next line"
  • Step Into (F11)
    • like go-to-implementation earlier
    • "Let me see what is happening inside this method"
  • Move execution pointer
    • Just click and drag and its like it never happened!
    • Great if you accidentally stepped over something you meant step into
  • Run To Cursor (CTRL+F10)
    • No need to set a breakpoint!
    • "Ok now I want to keep running the program past this loop until I get here"
  • Restart (CTRL+shift+F5)
    • "I want to quickly restart this debug session"
    • Faster than stopping debugging and restarting
Watch Window (CTRL+ALT+W)

image

  • Expression evaluator
    • Type in anything and the debugger will evaluate it for you!
    • You are able to watch the values change as you step through your program
  • Search
    • Search by name or value!
  • Pin
    • Make it easier to keep track of deep inner variables
Call Stack Window (CTRL+ALT+C)

image

  • View a list of methods and the order they called each other in
  • Jump to different methods
Breakpoints Window (CTRL+ALT+B)

image

  • See all your breakpoints in one place
  • Able to toggle them to "inactive" without deleting them

Advanced Debugging

image

  • Only stop your program when a condition is met
  • "I want to know when in this loop the value is set to null"
Exception Settings (CTRL+ALT+E)

image

  • Even with "Just My Code" turned on some debugging sessions can take a while to get started
  • Turning off breaking on exceptions until your breakpoint is hit can save time
"Just My Code"
  • By default only loads code that was built by you
  • Necessary to turn this off if you want to step into code from other teams

image

  • Allows you to inspect values quickly in the editor

  • Drag them around to track multiple values at once

  • Modules Window (CTRL+ALT+U)

Testing

Run tests from editor (CTRL+R,T)

image

  • Place your cursor on any class or method to run tests

Debug tests from editor (CTRL+R,CTRL+T)

  • Place your cursor on any class or method to run tests

Run from codelens

image

Test Explorer (CTRL+E,T)

  • Run options

    • You can choose to run all tests or just a few you select
    • Filter tests
      • If you have a lot of tests you can just show tests that have failed
    • Grouping

    image

Test output

image

  • If tests aren't running for some reason you can go to the output window (CTRL+shift+U) and look for the Tests category in the drop-down.

About

how to get started

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages