问题
I use an XML file in App_Data in conjunction with a Repeater on the main page of an intranet application allow me to display messages to users when they logon about application status, maintenance, etc. To test the functionality, it would be nice to have the file in the App_Data folder under development, but if I do this it copies it over the file on the production server when I publish the application. Is there anyway I can prevent this from happening short of going to a Web Deployment project (and will that solve my problem)?
回答1:
In Visual Studio 2005, I see a checkbox labeled "Include files from the App_Data folder", which defaults to checked. Have you tried publishing with that checkbox unchecked?
EDIT: Seeing as how that checkbox isn't available for your project, I would look into using the VS2005 Web Deployment add-on for visual studio. I haven't used it myself but the features to customize publishing between debug and release mode looks promising.
回答2:
To avoid that problem I would also deploy to a local "staging" location, essentially a folder on my desktop. Once the files were compiled and deployed there by Visual Studio I would delete the files I wasn't interested in (in your case App_Data) and then either XCopy or using Windows Explorer to copy the files to the web server.
Other than something similar to that, I know of no way to make Visual Studio itself omitted those files/folder on deployment.
回答3:
Another approach is to have a "debug" file and a "production" file..
Stream xml;
#if DEBUG
xml = File.Open("debug.xml");
#else
xml = File.Open("release.xml");
#endif
Compiling in DEBUG mode will use the debug file, compiling in release mode will use release file.
来源:https://stackoverflow.com/questions/212494/is-there-a-way-to-keep-files-in-app-data-from-overwriting-newer-files-when-publi