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

C# – IDE0060: Remove unused parameter

If you have a method with a parameter, and that parameter is not used in the method, then you’ll get the IDE0060 message telling you to remove the unused parameter. Here’s an example of code that would trigger this message: The encrypt parameter isn’t being used in the Send() method, triggering the IDE0060 message: IDE0060 … Read more

C# – Conditional compilation

You can exclude specific code from being compiled by using conditional compilation symbols. There are a few predefined symbols that support common scenarios – conditional compilation based on target framework (ex: .NET 5 vs .NET Core 3.1) and based on build configuration (Debug vs Release). In addition, you can add your own symbols to handle … Read more

How to enable the built-in .NET Analyzers

.NET Analyzers (which replaces FxCop) ships with the .NET 5 SDK. If you have the .NET 5 SDK installed, then you can enable .NET Analyzers by adding properties to the .csproj file. You can use this even if your project isn’t targeting .NET 5. If you don’t have the .NET 5 SDK installed, but want … Read more

C# – Duplicate ‘AssemblyVersion’ attribute

Problem You’re trying to add the AssemblyVersion attribute to your project, like this: And you get the following compiler errors: Error CS0579 Duplicate ‘AssemblyVersion’ attribute Error CS0579 Duplicate ‘AssemblyFileVersion’ attribute But you don’t see these attributes anywhere else in your project. Solution The problem is Visual Studio auto-generates the assembly info by default. To turn … Read more