Archive for the ‘.NET’ Category

Visual Studio’s Rebuild vs. Build

Sunday, September 1st, 2019

Build of course, like most tools, only compiles files that have changed since the last time a compilation was performed.

Rebuild of course, like most tools, re-compiles all source files regardless of whether they have changed since the last successful compile or not.

Simple right?  Not exactly….there are some subtle undocumented differences.  If a configuration file such as an appsettings.json file exists in your project, it is normally meant to be copied to your output folder for use by the application when you run it.  If you update this file, and Build or run the project VS.NET does not update the file in the output folder.  This has bewildered me on more than one occasion.  Only when you perform a Rebuild on that project (or solution) does the newer file get copied to the output folder.

Some intellisense errors in the IDE code editor involving code from other assemblies are also only resolvable by performing a rebuild.  I don’t recall the specific circumstances, but suffice to say, when in doubt perform a Rebuild.

EF Core - Burning the Database to the Ground

Friday, February 1st, 2019

During development, you sometimes want to make database changes that a migration cannot handle.  One such example is changing the datatype of a primary key column from an int to bigint.  In such a case you may want to burn the database to the ground and have a single migration that creates all the database structures defined through the model to date.  Some developers routinely remove all migrations to “cleanup” the code.

The procedure to do so is different for EF vs EF Core, and if you don’t do it the right way, things can get screwed up and be hard to fix.  With EF Core the easiest way I have found to burn the database to the ground is to use the PMC command:

update-database 0

This is a little different than simply removing all the database tables from a SQL utility like SMS.  It actually removes all tables, but ensures that the __EFMigrationsHistory table is present with 0 rows.

Then you can create delete all the files in the Migrations folder of the C# project and create a new initial migration:

add-migration "Some Title"

and generate the new structures: