Share via

Visual Studio Rebuild

Sid Kraft 31 Reputation points
2026-03-28T13:29:51.8666667+00:00
Developer technologies | Visual Studio | Debugging
{count} votes

1 answer

Sort by: Most helpful
  1. Q&A Assist
    2026-03-28T13:30:02.9266667+00:00
    AI generated content. This question contains an answer created with AI from Q&A; Assist. Learn more

    The repeated "cannot open file xxx" during rebuild is typically caused by files being locked or lacking write/delete permissions, not just by Visual Studio needing elevation.

    Based on the documented Visual C++/MSBuild errors, use these checks:

    1. Check for locked output/intermediate files
      • Errors like PRJ0008 ("Could not delete file 'file'") and PRJ0009 ("Build log could not be opened for writing") occur when Visual C++ cannot delete or open files because they are in use or write-protected.
      • Close all tools that might hold locks on your build outputs or intermediates:
        • Other instances of Visual Studio (especially building the same solution/configuration).
        • File explorers, editors, or viewers opened directly on .exe, .dll, .lib, .pdb, .htm (BuildLog.htm), or intermediate files.
        • Antivirus or backup tools that aggressively scan the build folder.
    2. Verify write permissions on the build folders
      • Ensure the current Windows user has full write access to:
        • The project’s output directory (for .exe/.dll/.lib/etc.).
        • The intermediate directory $(IntDir) (for BuildLog.htm and other intermediates).
      • Remove read-only attributes or write protection from these folders and files.
    3. Check Visual Studio build logging
      • If build logging is enabled, Visual C++ writes BuildLog.htm to $(IntDir).
      • If that file is locked or not writable, PRJ0009 occurs and can interrupt the build.
      • In Visual Studio: Tools → Options → Projects → VC++ Build → verify Build Logging and ensure nothing external is holding BuildLog.htm open.
    4. Avoid concurrent builds on the same configuration
      • Do not build the same project/configuration simultaneously from:
        • Multiple Visual Studio instances.
        • Visual Studio and a separate MSBuild/CI process.
      • If using parallel builds, temporarily disable them to see if the issue disappears.
    5. Confirm user permissions are stable over time
      • Because the first rebuilds succeed and later ones fail, look for:
        • Scheduled tasks (backup, indexing, antivirus) that start later and lock files.
        • Network or redirected folders where permissions or connectivity fluctuate.

    If the error message includes a specific MSBuild or VC++ error code (for example PRJ0008, PRJ0009, or MSB3821), use that code to narrow down which file is blocked and then:

    1. Locate that file in File Explorer.
    2. Ensure it is not open in any process.
    3. Ensure it is not marked read-only and that the user has write access.
    4. Rebuild the solution.

    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.