我在尝试使用 NMAKE、PowerShell 和 UNC 路径清理当前构建时遇到一些问题。在 nmakefile 中,我的干净目标如下所示:
clean: del obj\* /Q
这应该在键入“nmake clean”时从“obj”目录中删除所有文件。但是,它不起作用。我收到以下错误:
CMD.exe was started with the specified path
UNC paths are not supported
Using the Windows directory instead
System cannot find the specified file
NMAKE : fatal error U1077: 'del' : return code '0x1'
严重地?它正在回退到 Windows 目录? 感谢上帝我没有
del *
在干净的目标。在最初的震惊之后(我没有使用上述命令感到宽慰)我试图找到另一种方法来从 nmakefile 中清除我的“obj”目录。我尝试使用 PowerShell 命令而不是“del”,即像这样:
clean: Remove-Item obj/* -Recurse -Force
但是,这仍然不起作用。 NMAKE 仍在尝试启动 CMD.exe,然后从那里运行“Remove-Item”,这当然不起作用。它仍然会执行这种“回退到 Windows 目录,以防 UNC 路径”的恐怖!
有人能告诉我应该如何实现一个适用于 PowerShell 和 UNC 路径的 nmake clean 目标吗?
另外,有没有办法关闭这种回退到 Windows 目录的恐怖?
谢谢!
请您参考如下方法:
看来nmake
对 PowerShell 没有 native 支持,因此您需要运行 PowerShell.exe
带参数,像这样:
clean: powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "Remove-Item obj/* -Recurse -Force"
如果出现任何问题,请先尝试无害的东西:
clean: powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "Get-ChildItem /* -Recurse -Force"