如何删除 NAnt Build 期间使用的网络可执行文件
相关:如何强制删除文件?
我有一个 NAnt 脚本,它可以执行以下操作:完整构建并部署到我们的开发环境。 部署 C#.Net Win exe 及其使用的 DLL 涉及将它们移动到网络位置,我们的测试人员和其他开发人员在其中运行它们。
<copy todir="${dest.dir}" overwrite="true" failonerror="false" >
<fileset basedir="${source.dir}" >
<include name="**/*" />
</fileset>
</copy>
现在,脚本调用 Copy 任务,并设置 Overwrite="true",但如果有人正在运行该应用程序,则会失败,报告
无法将“source.dll”复制到“dest.dll”。 对路径“dest.dll”的访问被拒绝。
“dest.dll”是主要 EXE 的依赖项之一,与其一起复制。 现在,我有两种办法之一:我要么找出是谁打开了它并要求他们退出,要么我向我们的系统工程师发送电子邮件,他们会执行一些巫术来删除锁定的文件。 无论如何,我可以将一些我自己的巫术合并到 NAnt 脚本中,以便文件复制总是成功吗?
Related: How to force delete a file?
I have a NAnt script that does a full build and deployment to our Dev environment. Deploying the C#.Net Win exe and its used DLLs involves moving them to a network location, where our testers and other developers run them.
<copy todir="${dest.dir}" overwrite="true" failonerror="false" >
<fileset basedir="${source.dir}" >
<include name="**/*" />
</fileset>
</copy>
Right now, the script calls the Copy task, with Overwrite="true", but this fails if anyone is running the application, reporting
Cannot copy 'source.dll' to 'dest.dll'. Access to the path 'dest.dll' is denied.
"dest.dll" is one of the main EXE's dependencies, copied along with it. Right now, I have one of two recourses: I either figure out who has it open and ask them to quit, or I send an email to our systems engineers and they do some voodoo to delete the locked file. Is there anyway I can incorporate some of my own voodoo into the NAnt script, so the file copy always succeeds?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有几种可能的选择。
一种方法是编写一个自定义 NAnt 任务,使用 P/Invoke 调用 UnlockFile 或 UnlockFileEx< /a> 来自 Win32 API 的方法。 此任务可以包装解锁和复制操作,因此您只需从 NAnt 脚本调用新任务。
另一种方法是使用 NAnt exec 任务并在尝试复制之前执行命令行解锁实用程序。
You have a few possible options.
One would be to write a custom NAnt task that uses P/Invoke to call either the UnlockFile or UnlockFileEx methods from the Win32 API. This task could wrap the unlock and copy operations so you would only need to call your new task from the NAnt script.
Another would be to use the NAnt exec task and execute a command line unlock utlity before trying to copy.