visual-studio - 在 Visual Studio 中运行将 exe 作为预构建步骤运行的 PowerShell 脚本
问题描述
在我的 Visual Studio Pre-built 命令行中,我有一个新创建的行
Powershell.exe -file "$(SolutionDir)Folder1\MyPowerShell.ps1"
在这个 PowerShell 脚本中,它运行一个带有一些参数的 .exe
.\MyProgram.exe .\SomeFileArg.xml
当我只在本地运行 PowerShell 脚本时,无论是作为./MyPowerShell.ps1
命令还是将命令复制粘贴到我的 PowerShell 中,它都可以工作。
但是当我构建我的 Visual Studio 时,这不会发生。我收到错误.\MyProgram.exe.exe : The term '.\MyProgram.exe' is not recognized as the name of a cmdlet, 2> function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the 2> path is correct and try again.
如果我在我的 PowerShell 脚本中包含绝对路径,那么它可以工作。
如何通过本地路径实现这一目标?还是有一个变量,所以我不必硬编码绝对路径?
解决方案
您可以使用以下命令在代码中将本地路径(脚本文件所在的位置)声明为变量:
$PSScriptRoot
https://riptutorial.com/powershell/example/27231/-psscriptroot
推荐阅读
- memory - FFMPEG 吃掉所有内存
- git - eclipse导入本地git存储库,包资源管理器中显示两组相同的文件
- r - 如何在 jupyter notebook 中模拟 R markdown
- python - “NoneType”对象没有属性“member_count”
- tfs - 在选项卡/页面 Azure DevOps 工作项表单中呈现附件控件
- python - 我似乎无法使用 Microsoft Graph API 获取“收件箱”和“已发送邮件”文件夹
- java - 如何解决这个问答游戏循环问题?
- reactjs - 在新的 React 应用程序中打开主页的所有 URI
- google-apps-script - 用于分类银行对帐单的 Google 表格脚本下载
- python - 处理管理员用户重定向的 Django 装饰器