Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does "Copy if newer" not copy a file when the file is updated?

I have a solution in Visual Studio Express that looks like this:

The LogicSchema class in C# that will parse a specified XML file at run-time. The following is in the main method of Program.cs:

LogicSchema ls = new LogicSchema(
    XDocument.Load(
        "schemas\\C#Schema.xml",
        LoadOptions.PreserveWhitespace));

I created a folder in my solution called "schemas" to save the XML file and set the Build Action to Content and the "Copy to Output Directory" value to be Copy if newer.

My expectation is that if open the file in notepad, make a change, and save it, the updated version of the XML file will be copied to the ouput directory (in this case, bin\debug) when I press F5. However, the updated file is not copied to the output directory unless I select Rebuild. Regular Build does not work.

What do I need to change so that when I press F5, the file is copied to the output directory when it's been updated?

like image 629
Ben McCormack Avatar asked Feb 09 '10 14:02

Ben McCormack


1 Answers

It seems to work also in Visual Studio 2008 Team System - must be Expression edition specific, so cannot repro...

OK, my original guess was not true - it is about XML file being in the referenced library. Can repro it now.

I think the most natural way would be to embed the XML as resource and then read it with GetManifestResourceStream(). This way, the XML file would follow your dll as you reference it without copying it separately even if you reference the dll directly and not through project reference.

...or then you could use Pre-build event? (Project properties - Build Events):

copy $(ProjectDir)test.xml $(SolutiontDir)projectFolder\bin\debug\test.xml

I would think it will always run even if VS thinks no source files have changed. At least in full VS2008 this is the case - just tested.

like image 116
Ope Avatar answered Oct 26 '22 21:10

Ope