Prebuild script in Visual Studios to change Entity framework database schema isn't working -


my goal use prebuild script change schema depending on compiler configuration (debug/release/others..).

i see there number of solutions change schema in runtime using code, took different approach using prebuild script alter edmx file. isn't working , i'm wondering why isn't working (i'm not looking better/different approach.)

my approach this: in prebuild event added script alter edmx file changing string schema="dbo" schema="dbo2".

in postbuild event added script return file (schema="dbo2" schema="dbo").

i set conditional deal compiler configuration:

if $(configurationname) == release

so looks this:

prebuild: if $(configurationname) == release setdbo2.bat

postbuild: if $(configurationname) == release setdbo.bat

i tried dumping contents of edmx file in bat files. sure prebuild script changing edmx file's schema correctly , postbuild changing correctly. bug experiencing when build schema change isn't reflected in resulting assembly (it behaves if there no prebuild script). know prebuild script running , can seen output of build:

1>  completed setdbo2.bat ~~ **snip** ~~ various stupid compiler warnings ~~ **/snip** ~~ 1>  myproject -> c:\myproject\bin\myproject.dll 1>  completed setdbo.bat 

before snip if dump edmx file output screen see indeed edmx file altered in manner expected. myprojectdmo.ssdl file contained within assembly still contains whatever edmx had before script ran.

if remove postbuild script (thinking ssdl might generated/added after compilation) ssdl not affected.

so seems me ssdl file generated before prebuild script run.

does know if case? , if there sort of pre-prebuild script deal this?

--more information--

i found can set verbosity of output build window. there able this:

1>------ build started: project: myproject, configuration: release cpu ------ 1>build started 6/4/2015 4:06:23 pm. 1>entitydeploynonembeddedresources: 1>skipping target "entitydeploynonembeddedresources" because has no outputs. 1>entitydeployembeddedresources: 1>  processing 1 edmx files. 1>  starting process input file 'myprojectdmo.edmx'. 1>  finished processing input file 'myprojectdmo.edmx'. 1>  finished processing 1 edmx files. 1>prebuildevent: 1>  if release == release setdbo2.bat 

the edmx file processed before prebuild event. issue not seem related in-memory caching of files.

the question becomes there pre-prebuild script? or have start messing tt files or other on-code-generation events?

the a solution edit file "obj\release\edmxresourcestoembed\myprojectdmo.ssdl" instead of edmx.

i'm sure on internet can find reason not that, seem work. visual studios should build in few more hooks avoid hacks this.

under projects > build events > pre-build event command line

if $(configurationname) == release launchsed.bat 

launchsed.bat launches cygwin executes

find ./ -type f -exec sed -i 's/dbo/newschema/' {} \; 

that's not great answer. since cygwin required. have built custom sed command windows. program takes 3 inputs: file path, string replaced, string replace said string with.

winsed obj\release\edmxresourcestoembed\mydmofile.ssdl "schema=""dbo""" "schema=""newschema""" 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -