How to debug .NET source code in Visual Studio

When you’re using the Visual Studio debugger to step through your code, sometimes it’s useful to be able to step into the .NET source code. I had to do this recently to figure out why my ASP.NET Core code wasn’t behaving as expected. You can enable .NET source code debugging with the following steps: Now … Read more

Using Visual Studio props files

When you want multiple projects in a solution to use the same project settings (some or all), you can put the settings in a shared props file. There are two options: I’ll show both options below. Note: You can also use a combination of these two options. Option 1 – Use Directory.Build.props You can use … Read more

How to set multiple startup projects in Visual Studio

Since VS2019, you can set multiple startup projects in the solution’s properties. This is useful when you have multiple projects in the same solution that you want to start at the same time (with or without debugging). Before this, you’d have to set a project as the startup project, start it, then repeat with all … Read more

C# – How to treat warnings like errors

Warnings are easy to ignore and forget about, which isn’t good. They point out potential problems that you might want to fix. To make it easier to pay attention to warnings, you can treat them like errors. You can choose which warnings to treat like errors by using settings in the project file (or in … Read more

Implement Interface with auto properties in VS

When you add an interface to a class, you can right-click the class and use the Implement Interface quick action to automatically implement the interface. By default, it implements members that throw exceptions, even the getters and setters: This is fine for methods, but you’d expect it to generate auto properties instead of properties that … Read more

Visual Studio – How to use conditional breakpoints

Breakpoints cause execution to pause when you’re running the debugger. This is referred to as breaking, and it allows you to look at the current state of things for debugging purposes. In some cases, you may want to use a conditional breakpoint to only break execution when certain conditions are met (ex: break when name … Read more

Error MSB4226 Microsoft.TextTemplating.targets not imported

Problem You have a project that is using text templating (such as for auto-incrementing the version number) and you’re upgrading to a new version of Visual Studio. When you open the project, you get error messages about not being able to import the Microsoft.TextTemplating.targets project: Project “…\v16.0\TextTemplating\Microsoft.TextTemplating.targets” was not imported by “…SomeProject.csproj” at (7,3), due … Read more

Disable IntelliCode suggestions in Visual Studio

The IntelliCode completions feature (added in VS2022) suggests full line completions as you’re typing. It’s enabled by default. It shows a greyed out suggestion based on what it thinks you’re going to want. This is different from the regular modal popup that shows below the line you’re typing. Here’s what it looks like: If you … Read more

How to add .gitignore in Visual Studio

It’s important to add .gitignore to your git repository. This tells git which files in your source directory to not track. Without this, you end up pushing lots of unnecessary files to your repository – such as build output files. The simplest way to add .gitignore is by using Visual Studio. This initializes it with … Read more

Git – How to change filename casing

When you rename a file by changing its casing on Windows (ex: movie.cs -> Movie.cs), git will ignore the change. To change the casing, use the git mv command: This will rename the movie.cs file to Movie.cs on the file system and in the git repository, resulting in a rename change, which you can then … Read more

.NET – Copy files to a specified directory after the build

The simplest way to copy files post-build in a .NET project is to use the MSBuild Copy Task in the .csproj file, like this: Note: I’m using VS2019. My project is called NotesAPI. When I build, it logs the following messages: It copied the following build files into C:\Build\NotesAPI: In this article, I’ll explain the … Read more

How to enable the built-in .NET Analyzers

Previously you had to install and enable .NET Analyzers if you wanted to use it. Now, when you create a new project, it’s already installed and enabled by default (but you may want to change its settings). There are two main scenarios: If .NET Analyzers is already installed When you create a new project targeting … Read more

Class Diagrams missing in Visual Studio

Problem The Class Diagram item is missing in Visual Studio. Note: I ran into problem starting in VS2019. Solution For some reason this is not installed by default in Visual Studio, so we simply need to install it. 1. In Visual Studio click Tools > Get Tools and Features… 2. Close Visual Studio. 3. In … Read more

The referenced component could not be found

Problem When I open a C# project in Visual Studio, none of the references are loading. In the error list it says “The referenced component could not be found” for several references. Here’s a snippet showing just a few of the reference errors: The referenced component ‘System’ could not be found.The referenced component ‘Microsoft.CSharp’ could … Read more

Auto-increment build numbers in Visual Studio

You need to auto-increment your build numbers in order to easily tell which code you’re working with. In this article I’ll explain how to auto-increment your build numbers in Visual Studio. I’ll be using text templating to generate the Assembly Version. 1 – Choose a versioning scheme I’m going to be using the version scheme: … Read more

ReportViewer doesn’t appear in the toolbox in Visual Studio

Problem You’re trying to use the ReportViewer control in Visual Studio but it’s not in the toolbox. Other symptoms: Solution Note: Tested in Visual Studio 2017 and Visual Studio 2019. The exact instructions may have slightly different steps depending on which version of VS you’re using. There are two different problems to solve. First, you … Read more