Visual Studio Could Not Write to Output File Annoyance

Posted By Steven Smith at aspadvice.com =
(
http://aspadvice.com/blogs/ssmith/archive/2005/03/21/1849.=
aspx
)

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).=A0 The file is being used by another process.

There is a KB article describing this =
bug:

BUG: Could Not Copy Temporary Files to =
the Output Directory

But to be honest, that has never helped me one =
bit.=A0 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.=A0 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.=A0 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.=A0 Often =
not.=A0 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:

1) Find all the projects that reference the =
project whose assembly is causing the problem.

2) Remove all references to said project.

3) Build just that project.=A0 If it works, you’re good to go.

4) Re-add Project References to the project (for the ones you =
deleted).





[10] Comments | Categories: c#