I am getting the warning MSB3061 indicating that the output file (in this example a dll) cannot be deleted
Error message:
------ Rebuild All started: Project: CapInfo, Configuration: Release x86 ------
C:\Program Files\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(4319,5): warning MSB3061: Unable to delete file "C:\CapInfo\CapInfo\bin\Release\CapInfo.dll". Access to the path 'C:\CapInfo\CapInfo\bin\Release\CapInfo.dll' is denied.
CapInfo -> C:\CapInfo\CapInfo\bin\Release\CapInfo.dll
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
Most of the workarounds I have seen on this have suggested that changing the AssemblyVersion
and AssemblyFileVersion
fix this but this is not the case for me.
I my case this happens all the time but only on certain solutions yet all are being built in the same way by shelling MSBuild (the error also occurs when compiling in the IDE)
I can't simply delete the file in this case either because this is registered for COM interop, so during compile VS unregisters it. If the file is deleted then the unregistration fails with a different warning message)
I have also tried adding the following to the project properties (.vbproj file) with no success:
<GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies>
I also tried adding
if exist "$(TargetPath).locked" del "$(TargetPath).locked"
if not exist "$(TargetPath).locked" if exist "$(TargetPath)" move "$(TargetPath)" "$(TargetPath).locked"
To the pre-build event. This creates the locked file but still generates the warning
The most annoying part is that the compilation and copy actually works (VS does a retry then it works) so my questions are this
- Is there any other solution out there that might work for me in this case
- Is there a way I can add a pause to the build process before attempting to delete the file?
- Can I just disable this compiler warning (it doesn't show in the warning configurations table)
EDIT:
This appears to be something to do with the COM registration because if I untick "Register for COM Interop" I do not get the Warning anymore
EDIT2:
This install is on a HyperV virtual Windows 7 box. I have found that moving the project to a network drive and compiling onto that drive does not throw this warning, so I am investigating if there is some slow disk writing going on.