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. There are … Read more

How to bind controls to an object data source in a WinForms App (.NET Core) project

Mapping classes to UI controls manually is probably the most tedious thing you can do in coding. In order to minimize this coding effort, you can bind your controls to an object data source. In this article, I’ll show how to do this in a WinForms App (.NET Core) project. First, I’ll show step-by-step how … Read more

Visual Studio – Share a file between multiple projects

When you want to share a file between multiple projects, instead of duplicating the file’s contents, you can add a link to the existing file. You can link any type of file, but it’s most commonly done with config / source files. Here’s an example of adding appsettings.json as a linked file: In the project … Read more

Visual Studio – How to make the Implement Interface quick action generate auto properties

When you use the Implement Interface quick action in Visual Studio, it generates all members that throw exceptions, even the property getters and setters: This is fine for methods, but not for properties. You’d expect it to generate auto properties. Instead, it generates getters/setters that you then have to go clean up. Fortunately, this behavior … 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

Visual Studio project templates without minimal API and top-level statement

Devs want the option to create new projects in Visual Studio without all of the minimalist stuff that was recently added (top-level statement, minimal API). At the very least, these features should be optional instead of being the default without a way to opt-out (to be fair, minimal API is optional). What I typically do … Read more

How to make the build Up-to-date Check ignore your text template generated output

When you build a project / solution in Visual Studio, the Up-to-date Check feature will determine if the project needs a full rebuild or if it’s already up-to-date. There are many factors it checks – mainly, did the source code change since last time? Surprisingly, one thing that triggers a full rebuild is text template … Read more

Microsoft.TextTemplating.targets was not imported due to the file not existing

Problem You have a project that is using text templating 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 to the file not existing. The error … Read more

How to turn off IntelliCode completion suggestions in Visual Studio

Visual Studio 2022 has a feature called IntelliCode completions that 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 IntelliSense modal popup that shows below the line you’re typing. Here’s what it … Read more