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
@cls

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
set FILENAMES_TO_COPY=*.edmx

for /R "%SOURCE_DIR%" %%F IN (%FILENAMES_TO_COPY%) do (
    if exist "%%F" (
    	set FILE_DIR=%%~dpF
    	set FILE_INTERMEDIATE_DIR=!FILE_DIR:%SOURCE_DIR%=!
    	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 ----------------------------------------------------------
)

exit

 

 

 

 

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

Be the first to comment.

Leave a Reply

*


fourteen + 12 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>