Jul 12, 2011

Treating XML files as Content

I like keeping a lot of my application settings in a plain old XML data file. I've found the way Visual Studio treats it Properties.Settings file to be more complicated than I like. The only thing I store there is the name of my xml application settings file. I mentioned in a previous post on using the MSI installer in Visual Studio that I keep my xml files set as content and this generated some feedback about exactly how do to that, prompting this blog.

The Solution Explorer is the place to be.

SNAGHTML1493aa6dThe easiest thing to overlook is that the properties on a particular file can vary depending on where you click on it. For instance if you open an XML file and click on its tab or inside its content you will see a property dialog similar to the one shown at the left. You be justifiably confused about not being able to find the property for setting the file as content.

SNAGHTML148f0587Instead you need to use the Solution Explorer and click on the .xml file there.  You'll notice the Property dialog changes and now you have a Build Action property which you can set to Content and a Copy to Output Directory property to control how and when the copy happens. Most of the time I keep this set to Copy always because I want changes I make in the design environment to propagate to the application I run while Debugging.

About Me

My photo
Tod Gentille (@todgentille) is now a Curriculum Director for Pluralsight. He's been programming professionally since well before you were born and was a software consultant for most of his career. He's also a father, husband, drummer, and windsurfer. He wants to be a guitar player but he just hasn't got the chops for it.