Friday, 1 May 2009

Using pre-build events with SQL CE deployment

In a recent post I referred to the four dlls (sqlceer35EN.dll, sqlcese35.dll, sqlceme35.dll, sqlceqp35.dll) you need to carry around with your app to run a private installation of SQL CE. Drag them onto your project in your Visual Studio's Solution Explorer, set them as 'Content', and set them to copy to your output directory. Hey presto, there you have it.

BUT these four dlls are actually different for the 32 and 64 bit environments, so when you build for each platform you have to make sure you have the right ones. To automate this I used Pre-build events to copy the right ones in prior to build. 

Go to your project properties window and click on the 'Build Events' button. Here you're able to drop in code that gets stuff done prior to or after build. The syntax can include any command that is valid at the command line or in a .bat file, and this includes conditional statements that allow you to query certain project settings.

I'll cut to the chase, here's the code:

if $(PlatformName) == x64 xcopy /Y "C:\MyReferences\SQLServerCE\x64\*" "$(ProjectDir)"
if $(PlatformName) == x86 xcopy /Y "C:\MyReferences\SQLServerCE\x86\*" "$(ProjectDir)"

No comments:

Post a Comment

Comments are moderated, so you'll have to wait a little bit before they appear!