Showing posts with label visual studio. Show all posts
Showing posts with label visual studio. Show all posts

Wednesday, May 1, 2024

Customizing .editorconfig file

Summary: A few non-default settings in the .editorconfig file that will improve the code.
Before checking in code updates, I prefer the compiler output (and the Visual Studio Error List tab) to show no errors (obviously) or warnings. In most cases, the warnings are useful (I learned a few programming trick from some), but some (mostly, IntelliSense) warnings are a bit irritating, so I prefer to supress them. To allow my warning supression settings to be shared across the team, I put them in the .editorconfig file, which gets saved in the source control along with the project. The following settings override the defaults:
# Expression-level preferences
csharp_style_unused_value_expression_statement_preference = unused_local_variable:none

[*.cs]
# Primary constructors (mess up XML comment-based docs)
csharp_style_prefer_primary_constructors = false:suggestion

[*.cs]
# Indentation preferences
csharp_indent_labels = flush_left

[*.cs]
# IDE0058: Expression value is never used
dotnet_diagnostic.IDE0058.severity = silent

[*.cs]
# No need to use generated regex classes.
dotnet_diagnostic.SYSLIB1045.severity = none

Thursday, May 5, 2022

How to stop and start tracking file changes for Git

Summary: Git commands that let you stop and start tracking project file chages.

During application development, there may be situations when you want to make a change in a file (e.g. modify an application setting) without accidentally committing this change to source control. There may be better ways to do this, but one option is to tell Git to stop tracking the file before you make the the change that you do not commit to the repo. Say, there is an appsettings.Developement.json file that you want to stop and start tracking. This is how I do it.

Create two files stop-tracking-appsettings.bat and start-tracking-appsettings.bat files in the solution folder (PROJECT_FOLDER must be replace by the name of the project directory under the solution folder).

stop-tracking-appsettings.bat

@echo off
git update-index --skip-worktree PROJECT_FOLDER\appsettings.Development.json

start-tracking-appsettings.bat

@echo off
git update-index --no-skip-worktree PROJECT_FOLDER\appsettings.Development.json

Now you can either run these files from a console whenever you want to stop and start tracking file changes. Even better, in Visual Studio, you can create a custom tool menu option (e.g. Run batch file) that you can invoke by right clicking the file in the Solution Explorer and selectin the context menu option (see this Stack Overflow answer explaining how to set it up).

Tuesday, August 22, 2017

How to clean up BIN and OBJ folders in a Visual Studio solution

Summary: Some ideas on cleaning up intermediate and output folders in Visual Studio projects.
There may be better (and more elegant) ways of cleaning up the output (BIN) and intermediate (OBJ) folders generated by Visual Studio build process, but the following script is probably the easiest option you can use:

@echo off
rem Delete BIN and OBJ folders from the immediate folder and all subfolders.
rem

rem Switch to the script folder.
cd "%~dp0"

rem Use the following to suppress the 'File Not Found' message if no folders are found.
setlocal enabledelayedexpansion 
for /f "tokens=*" %%G in ('dir /B /AD /S bin 2^>nul') do rmdir /S /Q "%%G"
for /f "tokens=*" %%G in ('dir /B /AD /S obj 2^>nul') do rmdir /S /Q "%%G"

Notice that the script call setlocal enabledelayedexpansion to allow the 2^>nul redirection in the for loops (without it, it would output the "File Not Found" message if the folder and subfolders do not hold the "BIN" or "OBJ" folders. Also, make sure, you place the file in the root of the solution folder.

See also:
How to clean Visual Studio bin and obj folders
I want to delete all bin and obj folders to force all projects to rebuild everything

Thursday, March 5, 2015

Build API documentation with Sandcastle Help File Builder

Summary: How to build awesome API documentation using Visual Studio, XML code comments, Microsoft Markup Assistance Language (MAML), and Sandcastle Help File Builder (SHFB).
A couple of weeks ago, I gave this presentation to the Sacramento .NET User Group:


The presentation explains how to build first-class API documentation using Visual Studio, Sandcastle, and other tools and technologies. The goal of the presentation is to show how to build documentation with less effort and more fun.

The PowerPoint file (with links and notes) and the demo project can be found here: The demo project page outlines the dependencies and requirements for building the solution and using the assemblies.

If you run into any issues or have questions, please post a comment below or contact me directly.