You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
6.9 KiB
6.9 KiB
marp | paginate | math | theme | title |
---|---|---|---|---|
true | true | mathjax | buutti | 1.5. Introduction to Visual Studio |
Introduction to Visual Studio
Overview
- Visual Studio An IDE (Integrated development environment) by Microsoft for Windows
- Used for C#, C++, etc
- There's a free Community edition
- Multiple versions released
- First version: 1997
- 2017, 2019, 2022...
Features
- Debug tools
- Build tools
- IntelliSense
- code completion aid
- automatic code generation
- GitHub Copilot and IntelliCode, AI-assisted code development in VS
- Git integration
- Testing tools
- Profiling and diagnostics tools
Visual Studio vs Visual Studio Code (VS VS VSC)
- Visual Studio is not to be confused with Visual Studio Code, a separate software by Microsoft
- Visual Studio is out of the box a full-blown IDE with many built-in features
- Visual Studio Code is more akin to text editors like Sublime Text, Atom etc.
- Most features like IntelliSense or code completion have to be installed via plugins
- While both can be used for many programming languages, for C# and ASP.NET Visual Studio is preferred due to its extensive debugging and build tools
Installing Visual Studio
- Download Visual Studio Community (the free version) here
- After launching the setup executable, you will be prompted to select the components to be installed along with VS
- For our purposes you will need ASP.NET and web development found in the Workloads tab
- Click Install in the lower right corner to begin installing VS and the required components
- After installing VS, you can skip the account creation portion
- Note: Installation size can be quite large (8 GB+) depending on which components are already installed on your system
Projects and solutions
- In Visual Studio, there are two key concepts, projects and solutions
- Here's Microsoft's documents for what they are and how to create them
- A project contains all files that are compiled into an executable application
- Source code, images, data files, etc
- Compiler settings, configuration files
- In C#, handled by the project file
.csproj
by MSBuild - Creating a new project
- A solution contains one or multiple projects
- Build information, Visual Studio window settings
- Files that aren't associated with a particular project
.sln
is the solution file,.suo
contains Solution User Options
Visual Studio UI
Default view in Visual Studio consists of three panels.
- Code editor
- Solution Explorer (CTRL+ALT+L) shows the files in the project
- Terminal (CTRL+Ö) for entering command line commands (e.g., for using Git)
Moving windows around
Error highlighting in Visual Studio 2022
- Visual Studio highlights errors in code automatically.
- Hovering on the red underline will show a hint for the error:
- All errors can be displayed by pressing the red X at the bottom:
Keyboard shortcuts
- CTRL+.
- If a type is missing, use this to add the needed using directive
- CTRL+R, then CTRL+R (seriously?)
- Rename variable
- Press Enter to confirm
- CTRL+C (without selecting), then CTRL+V
- Duplicate line
- ALT+Up, ALT+Down
- Move line up/down
- Visual Studio Default keyboard shortcuts
Gotchas
- Some actions are unavailable when your app is running
- Deleting files
- Adding new controllers
Exercise 1. Creating a console application
- Open Visual Studio 2022.
- Select Create a new project
- Type console to the search bar and select the following template:
Exercise 2. Running a console application
- To run your program, select Debug > Start Debugging, or press F5, or press the small ▶ sign next to your project name at the top
- The template project should now run and print
Hello World!
to the console.
- The template project should now run and print
- Try changing the code so that it prints something else!