An "could not copy temporary files to the output directory" error is generated in Visual Studio .NET or in Visual Studio 2005

Symptoms

When you build a project in Microsoft Visual Studio .NET or in Microsoft Visual Studio 2005, the build fails and you receive the following compile-time error message:
Could not copy temporary files to the output directory.
For more information about another cause for this symptom, click the following article number to view the article in the Microsoft Knowledge Base:

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

Cause

This behavior may occur for one of the following reasons.

Cause 1

You may receive this error message when you compile a component that is currently being used by another process. For example, you may try to compile a class library or a user control project. For example, this behavior may occur when the following conditions are true:
  • Multiple instances of Visual Studio .NET or Microsoft Visual Studio 2005 are open. In one instance, you have a UserControl or class library project. In the other instance, you have a project that references the component and the project of the component is open in the first instance.
  • The second instance uses a file reference to the assembly and the Copy Local property of the assembly is set to False.
  • The assembly has been loaded into memory of the second instance of Visual Studio .NET or Microsoft Visual Studio 2005.
If the Copy Local property is set to False for the referenced assembly, and the assembly is not installed in the global assembly cache, the assembly will not be copied to the local \Bin folder of the consuming project. To resolve the location of the referenced assembly, Visual Studio .NET or Microsoft Visual Studio 2005 will search the paths that are listed in the Reference Path property of the project until it finds the assembly. In a scenario where the assembly has been loaded, such as a UserControl loaded in the Windows Form designer, the assembly is being used and cannot be overwritten when you try to build it. When this behavior occurs, you receive the error message that is mentioned in the "Symptoms" section.

As soon as the assembly has been loaded in memory of the Visual Studio .NET or Microsoft Visual Studio 2005 IDE, the assembly will not be unloaded until you exit and then restart the Visual Studio .NET or Microsoft Visual Studio 2005 IDE. For more information, see the "Resolution" section.

Cause 2

This behavior also occurs if you try to build the application when you are currently running an instance of the application from its \Bin folder, externally of the Visual Studio .NET or Microsoft Visual Studio 2005 IDE.

During the build process, the compiler builds the project to an intermediate folder, such as Obj\configname. In this folder name, configname is the name of the project. When the build process has completed, the files are copied from the intermediate folder into the output folder. The "Could not copy temporary files to the output directory" error message indicates that the compiler could not copy these files from the intermediate folder to the output folder. If you run the application that is being built from the output directory, the compiler cannot overwrite these files because they are currently being used. For more information, see the "Resolution" section.

Resolution

Resolution to Cause 1

To resolve this behavior, save the project that references the assembly. Then, close Visual Studio .NET or Microsoft Visual Studio 2005 to unload the assembly from memory.

To prevent the error from occurring again, set the Copy Local property of the reference to True. To do this, follow these steps:
  1. Open the solution that references the assembly.
  2. In Solution Explorer, locate the project that references the assembly.
  3. Click the References node of the project.
  4. Right-click the assembly reference, and then click
    Properties.
  5. Set the Copy Local property to True:
  6. Save the solution.
Visual Studio .NET or Microsoft Visual Studio 2005 copies the referenced custom control file to the output folder of the consuming project. Therefore, Visual Studio. NET or Microsoft Visual Studio 2005 does not load the assembly from its original \Bin folder.

Resolution to Cause 2

Solution 1

  1. Quit all running instances of the application.
  2. Build the solution. To do this, use one of the following methods:
    • On the Build menu, click Build Solution.
    • Press CTRL+SHIFT+B.
    Note If you receive the error message, follow the steps in the "Solution 2" section.

Solution 2

  1. Press CTRL+ALT+DEL to start Task Manager.
  2. On the Processes tab, make sure that your application is not listed as a running process. If it is, select the process from the list, and then click End Process.

    Note
    Make sure that you have not selected any additional processes, because ending other processes may cause unwanted results.
  3. Click Yes to end the application process.
  4. Build the application in Visual Studio .NET or Microsoft Visual Studio 2005.

Status

This behavior is by design.

More Information

Note The following procedures apply to both Visual Basic .NET or Microsoft Visual Studio 2005 and Visual C# .NET.

Steps to reproduce the behavior of cause 1

Create a User Control project

  1. Start the Visual Studio .NET or Microsoft Visual Studio 2005 IDE.
  2. On the File menu, point to New, and then click Project.
  3. In the New Project dialog box, click Visual Basic Projects under Project Types.

    Note In Visual Studio 2005, click Visual Basic under Project Types.
  4. Click Windows Control Library under Templates.
  5. In the Name box, type WindowsCtrl1, and then click OK.
  6. On the Build menu, click Build Solution to build the control.

Create a Windows Application project

  1. Open a second instance of the Visual Studio .NET or Microsoft Visual Studio 2005 IDE.
  2. On the File menu, point to New, and then click Project.
  3. In the New Project dialog box, click Visual Basic Projects under Project Types.

    Note In Visual Studio 2005, click Visual Basic under Project Types.
  4. Click Windows Application under Templates.
  5. In the Name box, type WindowsApp1, and then click OK.
  6. Right-click the Windows Forms tab of the Toolbox, and then click Add/Remove Items.

    Note In Visual Studio 2005, right-click the Windows Forms tab of the Toolbox, and then click Choose Items.
  7. In the Customize Toolbox dialog box, on the .NET Framework Components tab, click Browse to locate the WindowsCtrl1.dll assembly that you just built. Select the file, and then click Open.

    Note In Visual Studio 2005, this is the Choose Toolbox Items dialog box.
  8. Click OK to close the Customize Toolbox dialog box.
  9. In the Toolbox on the Windows Forms tab, double-click UserControl1 to put the control on Form1 of the Windows Application project.
  10. In Solution Explorer, expand WindowsApp1, and then expand References.
  11. Right-click the reference for WindowsCtrl1, and then click Properties.
  12. Change the Copy Local property to False.
  13. On the Build menu, click Build Solution to build WindowsApp1.

Compile the original User Control project

  1. Return to the first instance of the Visual Studio .NET or Microsoft Visual Studio 2005 IDE that contains only the WindowsCtrl1 project, and then put a Button control on the control.
  2. When you try to build the project, you receive the following error message:
    Could not copy temporary files to output directory.

Steps to reproduce the behavior of cause 2

  1. Start the Visual Studio .NET IDE or Microsoft Visual Studio 2005.
  2. On the File menu, point to New, and then click Project.
  3. In the New Project dialog box, select Visual Basic Projects under Project Types.

    Note In Visual Studio 2005, click Visual Basic under Project Types.
  4. Click Windows Application under Templates.
  5. In the Name box, type WindowsApp1, and then click OK.
  6. Build the solution. Make sure that the project compiles without errors.
  7. In Windows Explorer, open the folder where you built WindowsApp1.exe.
  8. Double-click WindowsApp1.exe to start the application.
  9. Return to the project in Visual Studio .NET or in Visual Studio 2005.
  10. When you try to rebuild the project, you receive the following error message:
    Could not copy temporary files to the output directory.
    Note To build the project, click Rebuild Solution on the Build menu.

    Note You must modify your code or you must click Rebuild Solution to receive this error message.
Propriedades

ID do Artigo: 311491 - Última Revisão: 29 de abr de 2008 - Revisão: 1

Comentários