2

I have been developing a C# application with Visual Studio 2015 for months now. I have a problem that has just recently creeped up on me. My application solution is a main Windows Forms application with many referenced projects. Each project has some additional static text and xml files that are (were) copied to the bin\debug folder on building the application. Each of these files has its properties set to:

Build Action = Content
Copy to Output Directory = Always

When I Rebuild the Solution, all of the files are copied to the bin\debug application folder correctly as they should be. No problem there.

However, when I click the F11 Step Into, F10 Step, or F5 Run buttons, Visual Studio immediately erases some (about 50%) of the files just prior to stepping into the program!

I checked the Tools/Options/Debugging for a "Do Not Delete Build Content Files" option, but could not find it or any option to prevent this behavior. My application expects to find the content files, so when they turn up AWOL in debugging, it is not good.

Any ideas what I should do to prevent Debug from deleting my files?

Update: This problem is related to StackOverflow question Visual Studio Not Copying Content Files from Indirectly Referenced Projects The key difference is that the previous question has been fixed in Visual Studio. VS Build process now properly copies indirectly referenced project content files. The problem is that VS2015 Update 3, Run Process, is now DELETING those files.

Community
  • 1
  • 1
gridtrak
  • 731
  • 7
  • 20
  • In both debug and release ? – Jim Nov 03 '16 at 16:22
  • I did not try F11, F10, or F5 in Release mode. If I build a Debug or Release build and run the executable, the files are not deleted. – gridtrak Nov 03 '16 at 18:02
  • so how about trying debugging in release mode ? – Jim Nov 03 '16 at 18:05
  • I have a clue: The files being deleted by the Debug run are those that belong to Projects (Libraries) that are referenced by Projects that are referenced by the startup Application. If I reference the Libraries in the startup Application, then the content files from the Libraries are preserved when running the Debug. I was hoping there was a configuration option to control this behavior. I really do not like the Debug mode Deleting files that are Included in the build by the Build process. This might be an Update 3 feature since I'm sure I would have noticed it before. – gridtrak Nov 03 '16 at 18:13
  • 1
    Jim - same results with Release builds using F11 step in Release mode. It looks like I need to redundantly reference the sub-libraries in my main Application Project in order to Debug reliably - at least until there is a fix or someone knows the configuration setting that adjusts this behavior. I submitted a Problem Report to Microsoft. I would think requiring redundant references is undesirable, especially if the only reason is to include, text or xml files needed by the library. – gridtrak Nov 03 '16 at 18:25
  • This problem is probably related to the problem described in http://stackoverflow.com/questions/12386523/visual-studio-not-copying-content-files-from-indirectly-referenced-project?rq=1 The difference is the previous question has obviously been fixed in Visual Studio - the content files are properly copied by the build process for indirectly referenced projects. My problem is that the Visual Studio Run process immediately deletes the files properly copied by the Build process. – gridtrak Nov 03 '16 at 18:53
  • My work-around, for now, is to run a script after the build that sets the files as "Read Only" so the Visual Studio debug mode cannot delete them. B-( – gridtrak Nov 03 '16 at 19:17
  • Wow, I just noticed that this issue is still broken in Visual Studio 2017 15.3.5! I guess it won't be fixed any time soon. What is the point of the build process properly copying the files if the Visual Studio is just going to erase them? I find it interesting I found my own post when I searched for the solution again. I just have to add references to ALL of the sub-projects that have content. – gridtrak Oct 04 '17 at 03:35
  • This is happening to me too in VS 2017, 15.9.5; I also have not found any workaround other than to add the files to my main project (an ASP.NET WebForms project in my case) redundantly. I add the files from my DLL dependency project 'as links' to avoid literally duplicate copies of the files, and of course set them to Content & Copy to Output Directory = Always. That works, and the files are in my web app's main /bin folder both in a build and when debugging. Wish Visual Studio would fix this issue though. – East of Nowhere Jan 31 '19 at 19:37

0 Answers0