Microsoft KB Archive/311491

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

Article ID: 311491

Article Last Modified on 12/6/2006

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Visual J# .NET 2003 Standard Edition
 * Microsoft Visual J# .NET 2003 Standard Edition

-



This article was previously published under Q311491



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: &quot;Could not copy temporary files to the output directory&quot; 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 &quot;Symptoms&quot; 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 &quot;Resolution&quot; 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\. In this folder name,  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 &quot;Could not copy temporary files to the output directory&quot; 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 &quot;Resolution&quot; section.



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.

Solution 1
 Quit all running instances of the application. 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 &quot;Solution 2&quot; 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.
 * 1) Click Yes to end the application process.
 * 2) Build the application in Visual Studio .NET or Microsoft Visual Studio 2005.

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

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

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.
 * 1) Click Windows Control Library under Templates.
 * 2) In the Name box, type WindowsCtrl1, and then click OK.
 * 3) 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.
 * 1) Click Windows Application under Templates.
 * 2) In the Name box, type WindowsApp1, and then click OK.
 * 3) 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.
 * 1) 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.
 * 1) Click OK to close the Customize Toolbox dialog box.
 * 2) In the Toolbox on the Windows Forms tab, double-click UserControl1 to put the control on Form1 of the Windows Application project.
 * 3) In Solution Explorer, expand WindowsApp1, and then expand References.
 * 4) Right-click the reference for WindowsCtrl1, and then click Properties.
 * 5) Change the Copy Local property to False.
 * 6) On the Build menu, click Build Solution to build WindowsApp1.

Compile the original User Control project
 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.</li> When you try to build the project, you receive the following error message:

Could not copy temporary files to output directory.

</li></ol>

Steps to reproduce the behavior of cause 2
 Start the Visual Studio .NET IDE or Microsoft Visual Studio 2005.</li> On the File menu, point to New, and then click Project.</li> In the New Project dialog box, select Visual Basic Projects under Project Types.

Note In Visual Studio 2005, click Visual Basic under Project Types.</li> Click Windows Application under Templates.</li> In the Name box, type WindowsApp1, and then click OK.</li> Build the solution. Make sure that the project compiles without errors.</li> In Windows Explorer, open the folder where you built WindowsApp1.exe.</li> Double-click WindowsApp1.exe to start the application.</li> Return to the project in Visual Studio .NET or in Visual Studio 2005.</li> 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.</li></ol>

Keywords: kbnofix kbprb kbprod2web kbvs2005applies kbvs2005swept KB311491

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.