views:

401

answers:

2

I'm trying to run a post-build batch file on a .NET build that encrypts an output file, deletes the original and then renames the encrypted version to the original output filename. i.e.:

Build A, then in post-build:

Encrypt A->B DEL /F A RENAME B A

I can't seem to delete the original output file after encryption though as it seems like there's a file lock by the installer project (or maybe the project itself?) on it. I tried forcing the delete, but it's not just a read-only attribute, but a full lock. Is there any way to get around this?

+1  A: 

This is a visual studio problem. It generally leaks file locks all over the place. You might consider running the builds outside of Studio by using MSBuild directly.

Chris Lively
A: 

Is the output file a DLL or just some content? Visual Studio project referencestend to lock the primary output (DLL, EXE in some cases) of an assembly project. Make sure you know what process is holding your file open handle, perhaps by running SysInternals Handle Utility just before your attempted rename. If it is devenv.exe that is holding the file, I'm not sure what you can do about it, other than to maybe have your installer pull in the renamed file rather than the output file.

jlew
The output file is a .dll file.