One of my clients asked me this morning how to get files into the build output directory so they are available for tests or as resources during run-time. There are a few answers to this question.
1. You could add a post-build even in your project file to copy the specific file(s) to the output directory. There is even a variable to help specify the OutDir. This is the bruit-force method and I don't recommend it.
2. An easier way is to right-click on the specific file and select Properties from the context menu. Then, in the Copy to Output Directory option, select Copy if newer. This is the built in method that provides what my client thought he wanted.
3. Finally, in ASP.NET it's possible to embed files into an assembly and reference them during run-time. This is what the client really wanted because it's more secure and easier to ensure all resources are available as an assembly is copied around to various execution environments. In short, you have to mark the file as an embedded resource, add a WebResource attribute to your code, and then use a special function to open the file. Here's a post explaining the use of the WebResourceAttribute in .NET and another post giving a little better code example of WebResourceAttribute.
Posted by: David O'Hara | 2008.01.25 at 12:25 AM