Visual Studio
Visual Studio
#visual-
studio
Table of Contents
About 1
Remarks 2
Versions 2
Examples 3
Installation or Setup 4
Examples 5
Remarks 9
Examples 9
Standard precondition 9
Examples 10
Examples 18
Code Lens 18
Snippets 18
Intoduction 18
1. Header 19
2. Snippet 20
2.1 Imports 20
2.2 Declarations 21
2.3 References 22
2.4 Code 22
Point of intrest 27
Entity Framework 28
Credits 29
About
You can share this PDF with anyone you feel could benefit from it, downloaded the latest version
from: visual-studio
It is an unofficial and free Visual Studio ebook created for educational purposes. All the content is
extracted from Stack Overflow Documentation, which is written by many hardworking individuals at
Stack Overflow. It is neither affiliated with Stack Overflow nor official Visual Studio.
The content is released under Creative Commons BY-SA, and the list of contributors to each
chapter are provided in the credits section at the end of this book. Images may be copyright of
their respective owners unless otherwise specified. All trademarks and registered trademarks are
the property of their respective company owners.
Use the content presented in this book at your own risk; it is not guaranteed to be correct nor
accurate, please send your feedback and corrections to info@zzzprojects.com
https://riptutorial.com/ 1
Chapter 1: Getting started with Visual Studio
Remarks
Visual Studio is an Integrated Development Environment (IDE) from Microsoft. It enables the
developer to work project orientated with various types of projects, including Windows Forms,
Console Applications, Office Plug-Ins, and Windows Universal Apps.
The IDE supports various programming languages, the most common being Visual C#, Visual
Basic, Visual F#, and Visual C++.
There are several editions of Visual Studio: Community (free), Express (free), Professional,
Enterprise, and Ultimate (However, not all are available for all versions).
Versions
1997-02-
97 Boston 5.0 N/A
01
1998-06-
6.0 Aspen 6.0 N/A
01
2002-02-
.NET 2002 Rainier 7.0 1.0
13
2003-04-
.NET 2003 Everett 7.1 1.1
24
2005-11-
2005 Whidbey 8.0 2.0, 3.0
07
2007-11-
2008 Orcas 9.0 2.0, 3.0, 3.5
19
2010-04-
2010 Dev10/Rosario 10.0 2.0 - 4.0
12
2012-09-
2012 Dev11 11.0 2.0 - 4.5.2
12
2013-10-
2013 Dev12 12.0 2.0 - 4.5.2
17
https://riptutorial.com/ 2
Version Supported .NET
Version Codename Date
number Framework versions
1) 20
2015-07-
2015 Dev14 14.0 2.0 - 4.6
20
2016-03-
"15" Preview Dev15 15.0 2.0 - 4.6.2; Core 1.0
30
2016-05-
"15" Preview 2
10
2016-07-
"15" Preview 3
07
2016-08-
"15" Preview 4
22
2016-10-
"15" Preview 5
05
Examples
https://riptutorial.com/ 3
Installation or Setup
Visual Studio can be downloaded and installed for free in Comunity edition from the Microsoft site
and can be also found in different versions. Just click on the Download button and run the
executable, then follow the instructions.
https://riptutorial.com/ 4
Chapter 2: Adding an extension
Examples
Adding an extension to visual studio using a `VSIX` file
If you have a vsix file, you can install it by running the file.
In Visual studio
https://riptutorial.com/ 5
https://riptutorial.com/ 6
https://riptutorial.com/ 7
Read Adding an extension online: https://riptutorial.com/visual-studio/topic/2257/adding-an-
extension
https://riptutorial.com/ 8
Chapter 3: Code Contracts
Remarks
In order to fully benefit from Code Contracts you need to install the extension for Visual Studio.
There's also a Code Contracts User Manual.
Examples
Standard precondition
using System.Diagnostics.Contracts;
using System.Diagnostics.Contracts;
using System.Diagnostics.Contracts;
return input;
}
https://riptutorial.com/ 9
Chapter 4: Connecting your visual studio
project to Github
Examples
Publishing your project to a github repository removing sensitive data
the steps in this example will use the following project structure as a demonstration
and we intend to export it to the "GHTuts" Repository [Note that the Repo doesn't exist yet on
github] but leave the "SensitiveProject" without publish as it contains some passwords, keys, etc..
1. First of all we make sure the source control plug in is set to "Git" in "Tools > Options > Plug-
in Selection"
https://riptutorial.com/ 10
2. If you can't see the "Team Explorer" tab, view it in visual studio like this
1. Go to your local solution folder and create a new file called ".gitignore.txt" [Note] this step is
only important if you have some sensitive information in your project,otherwise, let visual
studio create it for you
2. Now open the ".gitignore.txt" file and paste this in it, this is a template for ignoring common
visual studio files (check the links below)
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
https://riptutorial.com/ 11
[Oo]bj/
[Ll]og/
# NUNIT
*.VisualState.xml
TestResult.xml
# DNX
project.lock.json
project.fragment.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
https://riptutorial.com/ 12
*.cachefile
*.VC.db
*.VC.VC.opendb
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Click-Once directory
publish/
https://riptutorial.com/ 13
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
https://riptutorial.com/ 14
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# Microsoft Fakes
FakesAssemblies/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
3. Now add your sensitive project folder to the ".gitignore.txt" file at any line that doesn't contain
#, so just add it at the very end, and it should look something like this
https://riptutorial.com/ 15
4. Right click on the solution and choose "Add Solution to Source Control..."
5. Now you have a "LOCAL" git Repo on your pc , which VS will read from,but without a github
Repo, and you will see a small blue lock icon next to each file in the solution that was added
to git and a red circle at the ignored project
[Note]
for more information about .gitignore file, check these links
• https://help.github.com/articles/ignoring-files/
• https://github.com/github/gitignore
https://riptutorial.com/ 16
7. Go to the "Team Explorer" tab and then "Sync"
8. Now we create a repo from vs to github like this, press the "Get Started" button
9. Now fill in your information in github for the new Repo, then click "Publish"
10. Now when we go to github we see our local repo got published to github without our
sensitive project [Note]
the url of the repo will look something like this
https://github.com/<user name>/<repo name>
https://riptutorial.com/ 17
Chapter 5: Visual Studio tools
Examples
Code Lens
Code lens is a simple way to know what happens with the code. Here you could find an image with
the number of references of a method or class.
If you can't see the code lens please see this question: Missing CodeLens references count in VS
2015 Community edition
Snippets
Intoduction
Since Visual Studio 2005 can you make Intellisense Code Snippets. This allow you to generate
some code just by typing one keyword and press two times the tab key.
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/CodeSnippet">
<CodeSnippet Format="1.0.0"> <!-- format attribute is required -->
https://riptutorial.com/ 18
<Description></Description>
<Keywords>
<Keyword>abc<Keyword>
<Keyword>def<Keyword>
</keywords>
</Header>
</Snippet>
</CodeSnippet>
</CodeSnippets>
In the snippet tag, you have two required tags named Header and Snippet. You can find more
information in next headings. The number near the name are correspondents with the numbers in
the code above.
There can be zero or more CodeSnippet elements added into the CodeSnippets element.
1. Header
https://riptutorial.com/ 19
In the Header-tag, you can place some specific information about the snippet and what he does.
The important tags you can use inside this tag are:
Element Description
Is the shortcut, you can use for generating the code. Note that this can only
contain letters and numbers and must begin with a letter.
Shortcut Note: Remember also to give the snippet a good and unique name and
shortcut. Otherwise, it will give problems when you import the snippet into
Visual Studio.
Description Gives more information about the snippet if you need that.
Groups SnippetType elements. This element contain a text value and must be
one of the following values. Snippet types are merged with a forward slash.
2. Snippet
In the snippet tag, you can use three different tags. This can be:
• Imports
• Declarations
• Code (required)
• References
2.1 Imports
https://riptutorial.com/ 20
Importscontain the needed namespaces you need for the code. Use the import-tag inside this tag
and here you can place the needed namespaces each with the Namespace-tag.
2.2 Declarations
Declarations can be used for declaring some literals or objects into your code in the Code-tag. The
children are literals and objects.
Literals and objects define the literals and objects of the code snippet that you can edit.
Functionality are literals and objects are the same, but it has an additional type constraint.
In the snippets, there are some predefined literals. They are listed below:
Literal Details
$end$ Marks the location to place the cursor after the code snippet is inserted.
Represents text selected in the document that is to be inserted into the snippet
when it is invoked. Example, If you have:
2.2.2 Functions
Functions in the Literal- or Object-tag means that you can use a function for generating code
depending on another element. There are three functions that I know:
https://riptutorial.com/ 21
Function Description Language
Visual C#
Returns the name of the class that contains the
ClassName() and Visual
inserted snippet.
J#1
The Literal and Object tags can have some optional attributes.
Specifies whether or not you can edit the literal after the code snippet
Editable Boolean
is inserted. The default value of this attribute is true.
2.3 References
Groups reference elements that contains information about assembly references for the code
snippet. This can contain next elements:
• Assembly: Contains the name of the assembly by the code snippet (required)
• Url: Contains a website that gives more information about the assembly
2.4 Code
Code is the code you will generate between <![CDATA[ and ]]>. Place the ID of your literal between
dollar chars and Visual Studio will ask you for change these default value if the declarations are
filled in. Here, you've an example for C# and VB for the shortcut propfull.
https://riptutorial.com/ 22
<Literal>
<Id>propertytype</Id>
<Default>int</Default>
</Literal>
<Literal>
<Id>propertyname</Id>
<Default>myproperty</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[
private $propertyvalue$ $variablename$;
<Declarations>
<Literal>
<Id>variablename</Id>
<Default>_myproperty</Default>
</Literal>
<Literal>
<Id>propertytype</Id>
<Default>int</Default>
</Literal>
<Literal>
<Id>propertyname</Id>
<Default>myproperty</Default>
</Literal>
</Declarations>
<Code Language="VB">
<![CDATA[
Private $variablename$ As $propertyvalue$
In the required Language attribute, you can define your language where you are making the
https://riptutorial.com/ 23
snippet. You can find the languages you can use in the next table.
Attribute Description
Specifies the delimiter used to describe literals and objects in the code. By
Delimiter
default, the delimiter is $.
Specifies the kind of code that the snippet contains and, therefore, the location at
Kind
which a code snippet must be inserted for the code snippet to compile.
Value Description
method Specifies that the code snippet is a method body, and therefore, must be
body inserted inside a method declaration.
method Specifies that the code snippet is a method, and therefore, must be inserted
decl inside a class or module.
Specifies that the code snippet is a type, and therefore, must be inserted inside
type decl
a class, module, or namespace.
https://riptutorial.com/ 24
Value Description
Specifies that the snippet is a full code file. These code snippets can be inserted
file
alone into a code file, or inside a namespace.
Specifies that the snippet can be inserted anywhere. This tag is used for code
any
snippets that are context-independent, such as comments.
2. You can add the new made snippet into Visual Studio by pressing Control + K, Control + B or
go to "Tools" → "Code Snippets Manager...". This open next window:
https://riptutorial.com/ 25
3. Choose the language into the combo box for which language you've made the snippet. click
on "Import..." and choose the file you've made.
4. Click on "Finish". If the file name already has been used, Visual Studio go ask to override
the existing file. You've three options:
• Overwrite: Overwrites the file. You can use this option if you will edit an old snippet.
• Rename: Goes to rename the file to an unique name.
• Skip: Cancels the import. Renames the file to a unique name.
You could also add a new location with all the snippets you've made by clicking on the "Add..."
button on the first window and select the folder in the "select folder window". The advantage is
now when a new valid snippet is added in that folder, you can use this directly in Visual Studio.
Note: Test after importing your snippet for errors, so you don't have any problems when you use
https://riptutorial.com/ 26
the snippet. You can always remove or overwrite the snippet if there is an error.
Point of intrest
You can also see the documentation on MSDN for more information.
Got to Tools | Options | Source Control | Visual Studio Team Foundation Server
You can add separate overrides for 'Compare' and 'Merge' operations. Click on Add and select the
operation you want to override. You'd need to type the path to the tool you use, and the exact
arguments your tool expects. For example to use BeyondCompare, add the following Arguments "
%1 %2 /title1=%6 /title2=%7":
https://riptutorial.com/ 27
To Merge with BeyondCompare use the Arguments "%1 %2 %3 %4 /title1=%6 /title2=%7
/title3=%8 /title4=%9"
In a 2006 blog post MS employee James Manning surveyed the arguments as expected by
various tools: WinDiff, DiffDoc, WinMerge, Beyond Compare, KDiff3, Araxis, Compare It!,
SourceGear DiffMerge, TortoiseMerge and Visual SlickEdit. The post is a good starting point, but
be sure to check the up to date documentation of your tool.
It is highly recommended not to use for merge tools that are incapable of 3-way merges (e.g.,
WinMerge 2.x).
Entity Framework
Entity Framework allows you to create a model by writing code or using boxes and
lines in the EF Designer. Both of these approaches can be used to target an existing
database or create a new database.
Source and more information: Entity Framework documentation
https://riptutorial.com/ 28
Credits
S.
Chapters Contributors
No
Connecting your
4 visual studio project bigworld12
to Github
https://riptutorial.com/ 29