Seems to build, shows the following errors

I am trying to build, but I get the following errors, any help appreciated!

IOException: Sharing violation on path Temp\StagingArea\OCEnv_stormcap.exe" or "D:\Tao de Work\UnityProjects\Oldcastle_StormcaptureEnv\Oldcastle\builds5.2\OCEnv_stormcap.exe
System.IO.File.Copy (System.String sourceFileName, System.String destFileName, Boolean overwrite) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/File.cs:124)
UnityEditor.FileUtil.UnityFileCopy (System.String from, System.String to, Boolean overwrite) (at C:/buildslave/unity/build/Editor/Mono/FileUtil.cs:207)
UnityEditor.FileUtil.CopyDirectoryFiltered (System.String source, System.String target, Boolean overwrite, System.Func`2 includeCallback, Boolean recursive) (at C:/buildslave/unity/build/Editor/Mono/FileUtil.cs:142)
DesktopStandalonePostProcessor.CopyStagingAreaIntoDestination () (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/DesktopStandalonePostProcessor.cs:194)
DesktopStandalonePostProcessor.PostProcess () (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/DesktopStandalonePostProcessor.cs:25)
UnityEditor.WindowsStandalone.WindowsDesktopStandalonePostProcessor.PostProcess (BuildPostProcessArgs args)
UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, System.String downloadWebplayerUrl, System.String manualDownloadWebplayerUrl, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:316)
UnityEditor.HostView:OnGUI()

AND

Error building Player: IOException: Sharing violation on path Temp\StagingArea\OCEnv_stormcap.exe" or "D:\Tao de Work\UnityProjects\Oldcastle_StormcaptureEnv\Oldcastle\builds5.2\OCEnv_stormcap.exe

It looks like it’s having trouble with the file system and it specifies 2 possible files that are causing the problem.

One of them looks like it’s the exe that’s being built. So check the permissions on the directory, and if you’re overwriting a previous build then check you have permissions to do so (or, better yet IMO, don’t overwrite an existing build).

The other file it mentions is in Unity’s Temp folder. Sometimes a failed build leaves stuff in there that confuses future builds. To fix this, close Unity, delete the Library and Temp folders, and then restart Unity so that it recreates them from scratch.

A “sharing violation” indicates that another application has an active handle to a file you try to access. In windows when you run a program the system actually hold a handle to the exe file and keep it locked while the application is running. When you build your game it’s actually build inside that temp folder. When it’s done it copies the result over to the destination folder. Since the error happens inside “System.IO.File.Copy” it’s most likely that your old build is still running.

Keep in mind that “running” doesn’t mean that you necessarily have to see a window. If your game had a problem it’s possible that it still runs in the background without an active / visible window. So make sure your game application doesn’t run when you create a build. Just check the TaskManager’s details tab and search for your file. Don’t rely on the processes tab as it only shows “apps” that have a window.