Visual Studio.
NET
Contents
Visual Studio IDE........................................................................................................ 2
Application Anatomy............................................................................................... 2
General Anatomy................................................................................................. 2
Working with Application......................................................................................... 4
Windows.................................................................................................................. 4
Features.................................................................................................................. 5
Intelligent Code Editor.......................................................................................... 5
Debugging Tools................................................................................................... 5
Version Control Integration................................................................................... 5
Project Templates................................................................................................. 5
Extensions and Customizations............................................................................5
Collaborative Development.................................................................................. 6
Performance Profiling........................................................................................... 6
Testing Tools......................................................................................................... 6
Advanced Language Support............................................................................... 6
Cloud Integration................................................................................................. 6
Mobile Development............................................................................................ 6
Code Analysis....................................................................................................... 6
Data Tools............................................................................................................. 6
DevOps Integration.............................................................................................. 7
Commands.............................................................................................................. 7
Build and Run....................................................................................................... 7
Debugging............................................................................................................ 7
Code Navigation................................................................................................... 7
Editing.................................................................................................................. 7
Find and Replace.................................................................................................. 7
Visual Studio IDE
Visual Studio is a comprehensive integrated development environment (IDE) from
Microsoft, used for developing various types of applications.
Application Anatomy
The anatomy of a Visual Studio application varies based on the type of application
being developed (e.g., console app, Windows Forms app, WPF app, ASP.NET web
app, etc.).
General Anatomy
Solution (.sln file) : The solution file is the container for one or more projects. It
manages the projects and their dependencies.
Project (.csproj file for C# projects) : Each project file contains information
about the files in the project, references to assemblies, and other settings.
Source Files (.cs) : These are the code files where the application logic is written.
They typically include:
Program.cs: Entry point of the application, containing the Main method.
Other class files defining various classes, interfaces, and enums used in the
application.
References : Assemblies and NuGet packages that the project depends on.
Properties : Contains the AssemblyInfo.cs file and other project-specific settings.
Resources : Resources like images, strings, and other embedded files
Configurations : Configuration files like app.config or web.config for application
settings.
What is a nuget package?
A NuGet package is a single ZIP file with the .nupkg extension that contains
compiled code (DLLs), related metadata, and other resources needed by projects
that use these packages.
NuGet packages are used in .NET development to distribute reusable code,
manage dependencies, and share components between projects and teams.
Here are some key points about NuGet packages:
1. Distribution: They are used to distribute reusable code in the .NET ecosystem.
Developers can share their libraries and tools with others via NuGet packages.
2. Installation: NuGet packages can be easily installed, updated, and managed in Visual
Studio or via the command line. The NuGet client tools provide the ability to produce
and consume these packages.
3. Dependencies: When you install a NuGet package, any dependencies it has are also
installed, ensuring that all necessary components are available.
4. Package Sources: Packages are typically hosted on the NuGet Gallery (nuget.org), but
they can also be hosted on private repositories.
5. Versioning: NuGet packages use semantic versioning, which helps manage
dependencies and ensures compatibility.
6. Usage: You can use NuGet to install packages in your .NET projects by using the
NuGet Package Manager in Visual Studio, the dotnet CLI, or the NuGet CLI.
Add package:
Tools / Nuget package manager console: Install-Package Newtonsoft.Json -
Version 13.0.3
Cli: dotnet add package <PackageName>
Reading configuration
Reading values from the app.config file in a C# console application is a common
task.
ConfigurationManager.AppSettings["Setting1"]
For .NET framework, Add Reference to System.Configuration: If you encounter
an error indicating that ConfigurationManager is not recognized, you may need to
add a reference to System.Configuration.
Using System.Configuration.ConfigurationManager in .NET Core or .NET
5/6/7+
In .NET Core or later, the approach is slightly different as ConfigurationManager is
not directly available. You can use the Microsoft.Extensions.Configuration
package instead.
appsettings.json:
{
"Setting1": "Value1",
"Setting2": "Value2"
}
using System;
using Microsoft.Extensions.Configuration;
using System.IO;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");
IConfiguration configuration = builder.Build();
string setting1 = configuration["Setting1"];
string setting2 = configuration["Setting2"];
Console.WriteLine("Setting1: " + setting1);
Console.WriteLine("Setting2: " + setting2);
Console.ReadLine();
}
}
}
Working with Application
Adding project
Adding new Item
Break points
Setup the startup project
Intellisense
Windows
Solution Explorer
Open Solution Explorer: Ctrl + Alt + L
Solution Explorer: Manage files and projects within your solution.
Properties Window
Open Properties Window: F4
Properties Window: View and edit properties of selected items.
Output Window
Open Output Window: Ctrl + Alt + O
Output Window: Display build, debug, and other messages.
Error List
Open Error List: Ctrl + \, Ctrl + E
Error List: View and navigate errors, warnings, and messages.
Task List
Open Task List: Ctrl + \, T
Task List: Track tasks and comments in your code.
o Adding Task List Comments in Your Code
TODO: Use this to mark tasks you need to complete.
HACK: Use this to mark code that is a temporary
workaround.
UNDONE: Use this to mark tasks that need to be undone.
Toolbox
Open Toolbox: Ctrl + Alt + X
Toolbox: Access controls and components for designing UI.
Immediate Window
Open Immediate Window: Ctrl + Alt + I
Immediate Window: Execute commands and evaluate expressions during
debugging.
Quick Watch Window
Watch Window: Monitor the values of variables and expressions.
Call Stack
Open Call Stack Window: Ctrl + Alt + C
Call Stack: View the sequence of function calls during debugging.
Features
Here are some of the key features and functionalities of Visual Studio that make it a
powerful tool for developers:
Intelligent Code Editor
Code Completion and IntelliSense: Provides suggestions and auto-
completions for variables, methods, and objects.
Syntax Highlighting: Differentiates keywords, variables, and other code
elements with colors.
Refactoring: Easily rename variables, extract methods, and apply other
refactoring to improve code structure.
Debugging Tools
Breakpoint Management: Set breakpoints to pause execution and inspect the
state of the application.
Watch and Immediate Windows: Evaluate expressions and variables in real-
time during debugging sessions.
Call Stack Analysis: View the sequence of function calls leading to a specific
point in the code.
Version Control Integration
Git and GitHub: Integrated support for Git, allowing for seamless version
control operations within the IDE.
Azure DevOps: Integration with Azure DevOps for source control, continuous
integration, and delivery.
Project Templates
Quick Start: Numerous templates for various project types, including web,
desktop, mobile, cloud, and more.
Custom Templates: Create and use custom project templates to streamline
the development process.
Extensions and Customizations
Marketplace: Access to a wide range of extensions that add new features or
integrations.
Custom Settings: Tailor the IDE experience with custom themes, key bindings,
and workspace settings.
Collaborative Development
Live Share: Real-time collaborative editing and debugging with peers.
Code Reviews: Integrated tools for conducting and managing code reviews.
Performance Profiling
Performance Tools: Identify performance bottlenecks in code with detailed
performance analysis and profiling tools.
Memory Diagnostics: Detect and diagnose memory usage issues.
Testing Tools
Unit Testing: Built-in support for running and managing unit tests.
Test Explorer: Organize and run various types of tests, including unit,
integration, and UI tests.
Advanced Language Support
Multi-Language Support: Comprehensive support for multiple programming
languages, including C#, VB.NET, F#, C++, Python, JavaScript, and more.
Advanced Language Features: Use of modern language features and
frameworks, such as .NET Core, ASP.NET, and Azure Functions.
Cloud Integration
Azure Integration: Simplified deployment to Azure services, including App
Services, Functions, and Storage.
Cloud-based Development: Tools for developing, testing, and deploying cloud
applications.
Mobile Development
Xamarin Integration: Tools and libraries for developing cross-platform mobile
applications using C# and .NET.
Emulators and Simulators: Built-in support for testing applications on various
mobile device emulators and simulators.
Code Analysis
Static Code Analysis: Automated code review for potential errors, code
quality, and adherence to coding standards.
o Code Analysis: Visual Studio includes built-in code analysis tools
for .NET languages, which can help detect and correct a wide range of
coding issues. These tools are based on .NET Compiler Platform
(Roslyn) analyzers.
o SonarLint is best for real-time static code analysis to catch issues
early.
o CodeMaid focuses on cleaning and organizing code to enhance
readability and maintainability.
o ReSharper provides a comprehensive suite of tools to boost
productivity, including code analysis, refactoring, and navigation,
specifically for .NET developers.
Data Tools
SQL Server Data Tools: Tools for designing, building, and deploying SQL
Server databases.
Entity Framework Tools: Support for ORM frameworks like Entity Framework
for database management.
DevOps Integration
Continuous Integration/Continuous Deployment (CI/CD): Integrate with
pipelines for automated build, test, and deployment processes.
Docker and Kubernetes: Tools for containerization and orchestration with
Docker and Kubernetes.
Commands
Build and Run
Build Solution: Ctrl + Shift + B
Run (Start Debugging): F5
Run (Start Without Debugging): Ctrl + F5
Debugging
Step Into: F11
Step Over: F10
Step Out: Shift + F11
Toggle Breakpoint: F9
Continue: F5
Code Navigation
Go to Definition: F12
Find All References: Shift + F12
Quick Actions and Refactoring: Ctrl + .
Navigate Backward: Ctrl + -
Navigate Forward: Ctrl + Shift + -
Editing
Comment Selection: Ctrl + K, Ctrl + C
Uncomment Selection: Ctrl + K, Ctrl + U
Format Document: Ctrl + K, Ctrl + D
Format Selection: Ctrl + K, Ctrl + F
Find and Replace
Find: Ctrl + F
Replace: Ctrl + H
Find in Files: Ctrl + Shift + F
Replace in Files: Ctrl + Shift + H