❔ [Resolved] How to delete the OBJ folder after a build
Hello it's been several days that when I try to build it gives me this error:
I found a solution for this problem, delete the contents of the OBJ folder with each build, so I went to find out how to do it, however I found several solutions for Rider or VS.
Everyone says it works, that's how it should be done, whereas on my side it doesn't work.
In file .csproj, between
Fody: An unhandled exception occurred:
Exception:
Le processus ne peut pas accéder au fichier 'E:\Projet Unity\Curator\Curator\obj\x64\Debug\Curator.exe', car il est en cours d'utilisation par un autre processus.
Type:
System.IO.IOException
StackTrace:
à System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
à System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
à System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
à Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters) dans C:\Code\Fody\cecil\Mono.Cecil\ModuleDefinition.cs:ligne 1144
à InnerWeaver.WriteModule() dans C:\projects\fody\FodyIsolated\ModuleWriter.cs:ligne 18
à InnerWeaver.Execute() dans C:\projects\fody\FodyIsolated\InnerWeaver.cs:ligne 114
Source:
mscorlib
TargetSite:
Void WinIOError(Int32, System.String)
Fody: An unhandled exception occurred:
Exception:
Le processus ne peut pas accéder au fichier 'E:\Projet Unity\Curator\Curator\obj\x64\Debug\Curator.exe', car il est en cours d'utilisation par un autre processus.
Type:
System.IO.IOException
StackTrace:
à System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
à System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
à System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
à Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters) dans C:\Code\Fody\cecil\Mono.Cecil\ModuleDefinition.cs:ligne 1144
à InnerWeaver.WriteModule() dans C:\projects\fody\FodyIsolated\ModuleWriter.cs:ligne 18
à InnerWeaver.Execute() dans C:\projects\fody\FodyIsolated\InnerWeaver.cs:ligne 114
Source:
mscorlib
TargetSite:
Void WinIOError(Int32, System.String)
<Project></Project>
<Target Name="SpicNSpan" AfterTargets="Clean">
<!-- Remove obj folder -->
<RemoveDir Directories="$(BaseIntermediateOutputPath)" />
</Target>
<Target Name="SpicNSpan" AfterTargets="Clean">
<!-- Remove obj folder -->
<RemoveDir Directories="$(BaseIntermediateOutputPath)" />
</Target>
<Target Name="CleanObjFolder" AfterTargets="Build">
<Exec Command="rd /s /q $(OutDir)obj" />
</Target>
<Target Name="CleanObjFolder" AfterTargets="Build">
<Exec Command="rd /s /q $(OutDir)obj" />
</Target>
<Target Name="CleanObjFolder" AfterTargets="Builds">
<Exec Command="rd /s /q $(OutDir)obj" />
</Target>
<Target Name="CleanObjFolder" AfterTargets="Builds">
<Exec Command="rd /s /q $(OutDir)obj" />
</Target>
<Target Name="SpicNSpan" AfterTargets="Clean">
<RemoveDir Directories="$(ProjectDir)$(BaseIntermediateOutputPath)" /> <!-- obj -->
</Target>
<Target Name="SpicNSpan" AfterTargets="Clean">
<RemoveDir Directories="$(ProjectDir)$(BaseIntermediateOutputPath)" /> <!-- obj -->
</Target>
<Target Name="SpicNSpan"
AfterTargets="Clean">
<RemoveDir Directories="$(OUTDIR)"/>
</Target>
<Target Name="SpicNSpan"
AfterTargets="Clean">
<RemoveDir Directories="$(OUTDIR)"/>
</Target>
<Target Name="CleanAndDelete" AfterTargets="Clean">
<!-- Remove obj folder -->
<RemoveDir Directories="$(BaseIntermediateOutputPath)$(Configuration)" />
</Target>
<Target Name="CleanAndDelete" AfterTargets="Clean">
<!-- Remove obj folder -->
<RemoveDir Directories="$(BaseIntermediateOutputPath)$(Configuration)" />
</Target>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent" Condition="'$(Configuration)' == 'Release'">
<!--remove obj-->
<Exec Command="rd /s /q "$(BaseIntermediateOutputPath)Release"" />
</Target>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent" Condition="'$(Configuration)' == 'Release'">
<!--remove obj-->
<Exec Command="rd /s /q "$(BaseIntermediateOutputPath)Release"" />
</Target>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent" Condition="'$(Configuration)' == 'Debug'">
<!--remove obj-->
<Exec Command="rd /s /q "$(BaseIntermediateOutputPath)Debug"" />
</Target>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent" Condition="'$(Configuration)' == 'Debug'">
<!--remove obj-->
<Exec Command="rd /s /q "$(BaseIntermediateOutputPath)Debug"" />
</Target>
2 Replies
Fix
I clean my .csproj.
And simply add
<Target Name="BeforeBuild">
<!-- Remove obj folder -->
<RemoveDir Directories="$(BaseIntermediateOutputPath)" />
</Target>
<Target Name="BeforeBuild">
<!-- Remove obj folder -->
<RemoveDir Directories="$(BaseIntermediateOutputPath)" />
</Target>
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.