Visual Studio Could not write to output file annoyance
Date Published: 21 March 2005
Every now and then my VS.NET solutions will fail to build because of an error like:
Could not write to outputfile (filepath in /obj/ folder). The file is being used by another process.
There is a KB article describing this bug:
But to be honest, that has never helped me one bit. In my case, I’m not using a shared output folder, I am using Copy Local, and the project with the issues is only being referenced by Project References. So that KB is worthless, but it’s the only one I’ve found thus far.
Sometimes I get things to work by switching from Debug to Release mode, or vice versa. This usually works for one or two builds, sometimes more, but usually it ends up failing as well, at which point both the /obj/debug/assembly.dll and /obj/release/assembly.dll are being locked by VS.NET Intellisense and it’s game over.
Sometimes restarting VS.NET will help. Often not. Or, often only for one build.
What I’ve found worked for me most recently, and which I’m posting here as much for my own future reference as for anybody else, is this:
- Find all the projects that reference the project whose assembly is causing the problem.\
- Remove all references to said project.\
- Build just that project. If it works, you’re good to go.\
- Re-add Project References to the project (for the ones you deleted).\
- Send Steve $1 for saving you hours of headache (optional).
Anyway, those steps worked for me – hopefully they’ll help someone else as well. Can’t wait for Whidbey!!!
Steve is an experienced software architect and trainer, focusing currently on ASP.NET Core and Domain-Driven Design.