Monday, March 8, 2010

Mind your Copy to Output Directory Setting on Writeable Files

I’m used to doing more web development so I sometimes forget that just because an application writeable file (.xml, .csv, .sdf, .txt, etc.) resides in the project root directory structure, doesn’t mean that is the actual file that is getting written to when developing WPF applications. Depending on the “Copy to Output Directory” setting, that actual file may or may not get copied to the bin/Debug folder which is where the executable program resides (when debugging).

The “Copy to Output Directory” setting options are:

  • Do not copy – If you use this option, but you make changes to the copy in the project directory, the changes will not get copied to the bin/debug directory which the executable uses at runtime.
  • Copy if newer – Be careful with this if you are sloppy about making changes in one location one time, and another the next. What changes are overwritten with each compile can be unpredictable.
  • Copy always – Caution: If you use this, understand that if you make manual changes to the copy in the bin/debug directory, your changes will be overwritten by the version in the project directory at the next compile of the project.

Local Database Cache example

I created a WPF application that stores data locally on the client in a SQL CE (.sdf) database which periodically synchronizes with a server based SQL Server database. Since SSMS 2005/SQL Profiler does not have the ability to connect to a SQL CE database to view the data in the .sdf file, I created a quick “diagnostic” Windows Forms client to peek into the local client database to view the data to make sure the WPF program was operating as expected. I pointed the “diagnostic” Windows Form connection string to the .sdf file in the project root directory, then started Copy Output Directorychanging the data using the WPF application. The Windows Form was not showing the data changing, but the remotely synch’ed server side SQL Server was. What’s going on here?

Oh yeah, that’s right… the Windows Form was looking into the original client database that was created with the local database cache Visual Studio project wizard at the project root - not the live copy that was running out of the bin/Debug directory (See the Solution window screenshot). After I figured that out, I changed the connection string on the “diagnostic” Windows Form app to look at the .sdf file in the bin/Debug folder. Then in order to avoid getting confused about the data I was looking at between the remote database and the local client side database I needed to make sure I understood when the .sdf file in the project root directory was going to get copied into the bin/Debug folder upon recompile via the “Copy to Output” settings on the .sdf file.

Monday, March 1, 2010

Edit Expression Encoder Job Output Templates in Blend

If you are like me and like Expression Encoder, you have probably already found the functionality that allows you to automatically create a web-based Silverlight player and html page wrapper to show off your fancy video editing prowess. Encoder comes with several Silverlight templates for audio only, video, and galleries of video. But what if the functionality they provide doesn’t suit your needs? Almost no problem, you can create a copy of the template and open it in Expression Blend in a few clicks, then customize the player as you see fit.

Click the Output tab in Encoder and select the template you wish to edit from the drop-down list. Click the tiny dot immediately to the right of the Template drop-down list.

Edit-Encoder-template-in-Blendjpg 

You will be presented options for editing the template or a copy of it in Expression Blend or Visual Studio. Depending on the template you choose and what specifically you want to change in the template, the customization can range from relatively simple to “WOW, maybe I’m being too picky about what I don’t like about the built-in template.”