有没有办法在构建后事件中删除输出文件
我正在尝试在 .NET 构建上运行构建后批处理文件,该文件会加密输出文件,删除原始文件,然后将加密版本重命名为原始输出文件名。 即:
构建A,然后在构建后:
- 加密A->B,
- DEL / FA,
- 重命名B A。
我似乎无法在加密后删除原始输出文件,因为似乎有一个文件锁定安装程序项目(或者项目本身?)就可以了。 我尝试强制删除,但它不仅仅是只读属性,而是完全锁定。 有什么办法可以解决这个问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道旧帖子,但万一有人登陆这里......
OP没有给出错误消息,所以我们不确定它是否由于文件锁定而失败。
我在构建前和构建后脚本中多次看到文件的引用就像这样:
当项目移动到不同的位置时,这可以工作很长时间,然后就会彻底失败,因为
del 命令不喜欢路径中有空格。
将调用用双引号引起来,它将始终有效:
任何时候使用路径变量时,都应该将整个路径用引号引起来,因为您不知道将来可能会在路径中引入空格。
对于这篇文章,更好的版本是:
Old post I know but in case anyone lands up here....
There is no error message given by the OP so we don't know for sure that it is failing because of a file lock.
I have seen many times in pre- and post-build scripts that files are referenced simply like:
This can work for a long time before falling flat on its face when the project is moved to a different location because the
del
command doesn't like having spaces in the path.Wrap the call in double-quotes and it will work all the time:
Any time you use a path variable, you should wrap the entire path in quotes as you don't know that in the future, spaces may be introduced into your path.
For this post, the better version would be:
这是一个视觉工作室问题。 它通常会到处泄漏文件锁。 您可以考虑直接使用 MSBuild 在 Studio 外部运行构建。
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.
输出文件是 DLL 还是只是一些内容? Visual Studio 项目引用往往会锁定程序集项目的主要输出(某些情况下为 DLL、EXE)。 确保您知道哪个进程正在保存文件打开句柄,也许可以通过运行 SysInternals Handle在您尝试重命名之前使用实用程序。 如果是 devenv.exe 保存该文件,我不确定您可以对此做什么,除了让您的安装程序拉入重命名的文件而不是输出文件。
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.