none
Is it safe to edit files while visual studio builds?

    Question

  • Is it safe to edit source files .h and .cpp while visual studio builds? What if I'm editing in another editor (Sublime text 3)?

    What I want is Visual Studio to take a copy of the source when I hit build and then use that for the entire build. I'm not sure this is happening. Random runtime errors look like visual studio has managed to miss compiling some source files (even after a build again without changing the source files). These errors then stop happening when I rebuild the whole project.

    Friday, March 31, 2017 10:34 AM

All replies

  • Hi,

    AFAIK, MSBuild, which is used internally by Visual Studio, doesn't take snapshots of code files when started. When a MSBuild target is executed and requires a file, it passes that file to the MSBuild task (compiler task, etc.) of the MSBuild target. When the MSBuild task needs that file then it is read.


    My portal and blog about VSX: http://www.visualstudioextensibility.com; Twitter: https://twitter.com/VSExtensibility; MZ-Tools productivity extension for Visual Studio: https://www.mztools.com

    Friday, March 31, 2017 3:09 PM
  • Hi Dave,

    Welcome to the MSDN forum.

    >>Is it safe to edit source files .h and .cpp while visual studio builds? What if I'm editing in another editor (Sublime text 3)?

    Do you want to build a huge or big solution? Usually, the build will not take too much time and it is better to waiting for the build is completed and edit your files to keep the integrity of your solution and avoid the build error message.

    Like Carlos said, when you build your C++ solutions, it invokes the msbuild.exe to execute tasks with order. When it executes the file that you are editing, it will read the current content of this file even if you not ready to save, the random build error will show up per your modify content. For the detail information about target build order, please have a look at this: Target Build Order

    Best regards,

    Sara


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, April 3, 2017 6:15 AM
    Moderator