BUG: "Could not copy temporary files to the output directory" error message when you build a solution that contains multiple projects

Article translations Article translations
Article ID: 313512 - View products that this article applies to.
This article was previously published under Q313512
Expand all | Collapse all

On This Page

SYMPTOMS

When you build a solution that contains multiple projects in Visual Studio .NET, you may receive one of the following error messages:
Error message 1
Could not copy temporary files to the output directory.
The file 'assembly name' cannot be copied to the run directory. The process cannot access the file because it is being used by another process.
Error message 2
error CS0016: Could not write to output file 'fully qualified path of an assembly' -- 'The process cannot access the file because it is being used by another process. '
Error message 3
Cannot delete the project output: is the file read-only? A failure occurred while attempting to start the application.
Error message 4
ProjectName: error PRJ0008 : Could not delete file 'Managed C++ Output DLL'. Make sure that the file is not open by another process and is not write-protected.


When you try to build a solution that contains an .exe project, and the solution also depends on a second Class Library project or DLL Assembly, you may receive a build error message that is similar to the following:
The type or namespace name 'XXXXX' could not be found. (Are you missing a using directive or an assembly reference?) Cannot copy assembly 'Tools' to file 'I:\samplesViews\Bin\Debug\XXXXX.dll'. The process cannot access the file because it is being used by another process.
The error message is generated on every other build of the solution.

CAUSE

This problem may occur when one of the assemblies that you compile is larger than 64 kilobytes (KB) and one (or both) of the following conditions is true:
  • Your solution contains projects that are compiled to the same output folder.
  • The Copy Local property on one of the referenced assemblies or projects is set to False.

RESOLUTION

To work around this problem, do any (or all) of the following, as appropriate for your projects:
  • Compile the outputs for individual projects to different folders. Visual Studio .NET 2002 and Visual Studio .NET 2003 do not support a common output folder.
  • Set the Copy Local property for the referenced assembly or project to True.
  • Verify that you do not have the Object Browser window open.
  • Verify that you do not have the same project (or projects) open in another instance of Visual Studio .NET.
Note Microsoft strongly recommends that you use project references instead of assembly references. Assembly references do not contribute to the file locking problem. However, when you use assembly references, you must set the build order manually. When you use project references, the build order is established automatically.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

This problem occurs when the IntelliSense engine of the project locks a referenced assembly. The IntelliSense engine locks only those referenced assemblies that are larger than 64 KB.

To resolve this assembly locking problem, the master copy of the referenced assembly must be left unlocked. You must provide another "lockable" copy of the referenced assembly to the IntelliSense engine. If the assembly reference has the Copy Local property set to True, and the project is being built to its own output directory, a lockable copy of the referenced assembly already exists.

The Copy Local property determines whether a private copy of a reference will be copied to the output path of the project. When a reference is added, the default value for this property is computed by the project system. Microsoft strongly recommends that you do not change this default value. Therefore, when you have the Copy Local property set to True for the referenced assembly, the IntelliSense engine locks this private copy of the assembly in the local Bin folder. This private copy of the assembly is automatically updated each time that the master copy of the assembly is rebuilt.

Steps to reproduce the behavior

This article describes two different scenarios to reproduce this problem:
  • Common output folder
  • Copy Local is set to FALSE
Both of these scenarios require an assembly that is larger than 64 KB. To create this assembly for the examples in this article, follow these steps.

Note Verify that the line numbers appear in your C# code editor. Step 8 is easier to do when the line numbers are visible.
  1. Create a new folder named C:\Test.
  2. Start Visual Studio .NET.
  3. On the File menu, point to New, and then click Project. Under Visual C# Projects, click Class Library.
  4. In the Name text box, type MyLibrary. In the Location text box, type C:\Test.
  5. Click OK.
  6. In Solution Explorer, click MyLibrary. On the Project menu, click Properties, and then click Build under Configuration Properties. Change the Output path setting to the C:\Test folder. Click OK to save the project and close the MyLibrary Property Pages dialog box.
  7. In Solution Explorer, double-click Class1.cs to open the code window of the default class.
  8. Paste the following function in Class1:
            public void MyMethod()
                    {
                    Console.Write(".");
                    Console.Write(".");
                    Console.Write(".");
                    Console.Write(".");
                    // Repeat 
                    // Console.Write(".");
                    // about 5,500 times.
    }
  9. On the Build menu, click Build MyLibrary to compile and create the MyLibrary.dll file. Make sure that the output MyLibrary.dll file in C:\Test is larger than 64 KB.

Common output folder

  1. Start Visual Studio .NET, and then load the MyLibrary class library project that you created in the previous section.
  2. On the File menu, point to New, and then click Project.
  3. Under Visual C# Projects, click Console Application.
  4. In the Name text box, type ConApp. In the Location text box, type C:\Test.
  5. Click Add to Solution.
  6. Change the ConApp Output Path setting to C:\Test.
  7. On the Project menu, click Add Reference. On the Projects tab, click Select. Click OK to add the reference to the MyLibrary project.
  8. On the Project menu, click Set as StartUp Project to set ConApp as the startup project.
  9. In Solution Explorer, double-click Class1.cs to open the code window of the default class for the ConApp project.
  10. Add the following code to the Main method of ConApp:
    MyLibrary.Class1 o = new MyLibrary.Class1();
    o.MyMethod();
    					
  11. On the Build menu, click Build ConApp.

    The build succeeds.
  12. Open Class1 in the MyLibrary project, and then delete one of the following lines of code:
    Console.Write(".");
    Save Class1.
  13. Repeat step 11.

    You receive one of the error messages that is described in the "Symptoms" section of this article.

Copy Local is set to FALSE

Note If you have tried the steps in the "Common Output Folder" scenario, Visual Studio .NET will lock MyLibrary.dll. To try the steps in the "Copy Local Is Set to FALSE" scenario, you must quit Visual Studio .NET, and then delete the C:\Test\MyLibrary\obj folder.
  1. Create a new folder named C:\Test2.
  2. Start a new instance of Visual Studio .NET, and then load the MyLibrary class library project. Verify that you do not have the ConApp project loaded in the solution.
  3. On the File menu, point to New, and then click Project. Under Visual C# Projects, click Console Application.
  4. In the Name text box, type ConApp2. In the Location text box, type C:\Test2 location.
  5. Click Add to Solution.
  6. On the Project menu, click Add Reference. On the Projects tab, click Select. Click OK to add the reference to the MyLibrary project.
  7. On the Project menu, click Set as StartUp Project to set ConApp2 as the startup project.
  8. In Solution Explorer, click the MyLibrary reference for the ConApp2 project, set the Copy Local property for the reference to False. This step deletes the copy of the MyLibrary.dll file that has been copied to the local Bin folder of ConApp2.
  9. In Solution Explorer, double-click Class1.cs to open the code window of the default class for the ConApp2 project.
  10. Add the following code to the Main method of ConApp2:
    MyLibrary.Class1 o = new MyLibrary.Class1();
    o.MyMethod();
    					
  11. On the Build menu, click Build ConApp2.

    The build succeeds.
  12. Open Class1 in the MyLibrary project, and then delete one of the following lines of code:
    Console.Write(".");
    Save Class1.
  13. Repeat step 11.

    You receive one of the error messages that is described in the "Symptoms" section of this article.
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
311491 The "could not copy temporary files to the output directory" error is generated in Visual Studio .NET

Properties

Article ID: 313512 - Last Review: January 26, 2006 - Revision: 7.5
APPLIES TO
  • Microsoft Visual Studio .NET 2003 Professional Edition
  • Microsoft Visual Studio .NET 2003 Enterprise Architect
  • Microsoft Visual Studio .NET 2003 Enterprise Developer
  • Microsoft Visual Studio .NET 2003 Academic Edition
  • Microsoft Visual Studio .NET 2002 Professional Edition
  • Microsoft Visual Studio .NET 2002 Enterprise Architect
  • Microsoft Visual Studio .NET 2002 Enterprise Developer
  • Microsoft Visual Studio .NET 2002 Academic Edition
Keywords: 
kbvs2005doesnotapply kbvs2005swept kbtshoot kbvs2002sp1sweep kbfix kbbug kberrmsg kbprod2web KB313512

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com