Currently in my project directory I have a folder called “Data” and in it I have two XML files that I use in my WPF application. I have set the XML files as “Resource” and the “Copy to Output Directory” option to “Copy Always”. However, the following code throws a DirectoryNotFoundException because the files aren’t being copied over to bin\debug when I build my application.
return new Game(XDocument.Load("Data/Game.xml").Root);
How do I make it so that everytime I build the files are moved over without having to do it manually everytime I change my XML?
Set ‘Build Action’ to None
When you set Build Action to Resource – it means, that VS will automatically pack this file into assembly as embedded resource. More about Resource Files on MSDN
And when ‘Build Action’ is None – Studio has nothing else to do, but to follow “Copy to Output Directory” command.