Share via

Visual Studio Rebuild

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

2 answers

Sort by: Most helpful
  1. Gade Harika (INFOSYS LIMITED) 2,605 Reputation points Microsoft External Staff
    2026-03-30T10:51:51.6+00:00

    Thanks for reaching out.
    The issue was caused by temporary file locks on build output or intermediate files (bin/obj). Rebuild performs a clean operation, which fails if EXE/DLL/PDB files are still in use by another process. This is not a permissions issue.

    This commonly happens due to:

    • A running or crashed app instance
    • Another Visual Studio instance
    • File Explorer or tools opened on bin/obj outputs
    • Antivirus or backup software scanning the build folders

    Recommended steps:

    1. Stop debugging and close all Visual Studio instances
    2. Ensure no app EXE/DLL is running (check Task Manager)
    3. Close File Explorer windows opened on bin/obj
    4. Temporarily exclude the project folders from antivirus scanning
    5. If needed, close VS, delete bin and obj folders, reopen, and Build

    The fact that the rebuild succeeds after sitting overnight confirms a transient file‑lock condition rather than an elevation issue.

    Let me know if you need any further help with this. I will be happy to assist. If you find this helpful, Kindly mark the provided solution as "Accept Answer", so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.


  2. 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.