My goal is to use a prebuild script to change the schema depending on the compiler configuration (Debug/Release/Others..).
I see that there are a number of solutions to change the schema in runtime using code, I took a different approach using a prebuild script to alter the edmx file. This isn't working and I'm wondering why this isn't working (I'm not so much looking for a better/different approach.)
My approach was this: In the prebuild event I added a script to alter the edmx file changing the string Schema="dbo" to Schema="dbo2".
In the postbuild event I added a script to return the file back (Schema="dbo2" to Schema="dbo").
I also set a conditional to deal with the compiler configuration:
if $(ConfigurationName) == Release
So it looks like this:
prebuild: if $(ConfigurationName) == Release setdbo2.bat
postbuild: if $(ConfigurationName) == Release setdbo.bat
I also tried dumping the contents of the edmx file in the bat files. I am sure that the prebuild script is changing the edmx file's schema correctly and that the postbuild is changing it back correctly. The bug that I am experiencing is when I build the schema change isn't reflected in the resulting assembly (it behaves as if there was no prebuild script). I know the prebuild script is running and this can be seen from the output of the build:
1> Completed setdbo2.bat
~~ **snip** ~~
Various stupid compiler warnings
~~ **/snip** ~~
1> myProject -> C:\myProject\bin\myProject.dll
1> Completed setdbo.bat
Before the snip if I dump the edmx file to the output screen I see that indeed the edmx file was altered in the manner I expected. However the myProjectDMO.ssdl file contained within the assembly still contains whatever the edmx had before the script ran.
If a completely remove the postbuild script (thinking that the ssdl might be generated/added after compilation) the ssdl is also not affected.
So it seems to me that the ssdl file is generated before the prebuild script is run.
Does anyone know if this is the case? And if so is there some sort of pre-prebuild script to deal with this?
--More information--
I found that I can set the verbosity of the output build window. From there I was able to get this:
1>------ Build started: Project: myProject, Configuration: Release Any CPU ------
1>Build started 6/4/2015 4:06:23 PM.
1>EntityDeployNonEmbeddedResources:
1>Skipping target "EntityDeployNonEmbeddedResources" because it has no outputs.
1>EntityDeployEmbeddedResources:
1> Processing 1 EDMX files.
1> Starting to 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 does get processed before the prebuild event. The issue does not seem to be related to in-memory caching of files.
The question now becomes is there a pre-prebuild script? Or would I have to start messing with tt files or other on-code-generation events?