A core feature of Visual Studio that allows developers to inspect, analyze, and troubleshoot code during execution.
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:
- 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.
- 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.
- Ensure the current Windows user has full write access to:
- Check Visual Studio build logging
- If build logging is enabled, Visual C++ writes
BuildLog.htmto$(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.htmopen.
- If build logging is enabled, Visual C++ writes
- 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.
- Do not build the same project/configuration simultaneously from:
- 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.
- Because the first rebuilds succeed and later ones fail, look for:
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:
- Locate that file in File Explorer.
- Ensure it is not open in any process.
- Ensure it is not marked read-only and that the user has write access.
- Rebuild the solution.
References: