Visual Studio 2012 Post Build Event – Run Batch – Validate Entity Framework Model ProviderManifestToken

Visual Studio 2013

June 3, 2015 | Posted in Visual Studio 2012, Windows

When entity framework models are refreshed from a SQL database, the ProviderManifestToken will change based on the version of SQL Server.

It was necessary to automate a process whereby every time the DAL built, I needed to verify that a refresh hadn’t inadvertently changed the ProviderManifestToken to an incorrect version.

To do this, I created a batch file (all edmx files must conform to SQL Server version 2005, and if they don’t, notify):



@echo off
@break off
@title Create folder with batch but only if it doesn't already exist - PROVIDER MANIFEST SEARCH
@color 0a

setlocal EnableDelayedExpansion

set shouldpause=0

if exist "C:\ProviderManifestTokens\" (
  rmdir "C:\ProviderManifestTokens\" /s /q


if not exist "C:\ProviderManifestTokens\" (
  mkdir "C:\ProviderManifestTokens\"  

set SOURCE_DIR=%cd%
set DEST_DIR=C:\ProviderManifestTokens

    if exist "%%F" (
    	set FILE_DIR=%%~dpF
    	xcopy /I /Y "%%F" "%DEST_DIR%"

if exist "C:\ProviderManifestTokens\" (

  chdir /d C:\ProviderManifestTokens\

  ren *.edmx *.txt

  for %%F in (.\*) do (
  find "ProviderManifestToken=""2005" %%F > nul
        if errorlevel 1 (		

		echo ----------------------------------------------------------
		echo Warning: File %%F contains incorrect ProviderManifestToken
		echo ----------------------------------------------------------
		set shouldpause=1

if not %shouldpause% == 1 (
	echo ----------------------------------------------------------
	echo Success: *.edmx files valid 
	echo ----------------------------------------------------------






The script essentially scans directories and sub directories for all edmx files, it then copies them to a folder on the root, changes file extensions from *.edmx to *.txt (so that I could perform string lookups) and then notify where the ProviderManifestToken wasn’t what I wanted it to be.

The only other bit is to add the following in to your project Build Events:

cd $(ProjectDir)
call CheckProviderManifestTokens.bat

The above is a Post Build event and is set to run Always.

Check your Output window for the results of the batch file.

Update: I ended up leaving the batch in the DAL where it was, and putting the post build event in to the main application project, as that project is the last to compile, therefore developers will see the results at the end in the output window.

The post build event changed everso slightly:

cd $(ProjectDir)\DalFolder
call CheckProviderManifestTokens.bat

Read More →

Setting A Windows Service Dependancy


November 21, 2013 | Posted in Windows

1. Open the registry editor:
Start -> Run -> regedit

2. Navigate to the specific service you are trying to delay:

3. If there is a “DependOnService” value, simply modify it and add the service you want to start before the one you are editing in the registry.

If no “DependOnService” value exists create one:
Right click service name -> New -> Multi-string value
Enter the name DependOnService then modify this new record and add the service you want to start before the one you are editing.

To verify you have the right service name to enter open up Services, right click the service in question, and choose properties. Use the Service name and not the Display name. For instance the IIS Admin Service name is “IISADMIN”.

4. The server will require a restart to apply the change. Once restarted you can open Services, right click the service you edited, choose properties, then the Dependencies tab and you will see the change.

Read More →

Scott Hanselman’s 2011 Ultimate Developer and Power Users Tool List for Windows


October 3, 2013 | Posted in Windows

Probably the most comprehensive list of useful utilities out there!

Thanks Scott.

Read More →