如何让这个脚本对我的团队所有成员运行?

huangapple go评论62阅读模式
英文:

How Can I Make This Script Run For All Members of My Team?

问题

我已经弄清楚如何让PowerShell检查运行中的DLL,如果它没有运行,就运行它。我输入 npm run passthru,脚本会执行以下操作:

"scripts": {
  "passthru": "powershell if (-not (Get-Process -Name MyPassThruApp -ErrorAction SilentlyContinue)) { dotnet run --project C:/git/MyPassThruApp/MyPassThruApp/MyPassThruApp.csproj }",
},

一切都很好,但我希望这个脚本适用于我的团队的任何成员(在Windows上)。我尝试将.csproj文件的路径添加到Path环境变量中(并从脚本中删除它),但这并不起作用 - 即使在重新启动计算机后,它也不会为我运行。

有什么建议吗?

英文:

I've figured out how to get powershell to check for a running DLL and if it's not running, to run it. I type npm run passthru and the script does the work:

  "scripts": {
    "passthru": "powershell if (-not (Get-Process -Name MyPassThruApp -ErrorAction SilentlyContinue)) { dotnet run --project C:/git/MyPassThruApp/MyPassThruApp/MyPassThruApp.csproj }",
  },

All well and good, but I want the script to work for any member of my team (on Windows). I tried adding the path to the .csproj file to the Path environment variable (and removing it from the script), but that didn't work - it won't run for me, even after restarting the computer.

Suggestions?

答案1

得分: 0

通常,如与dotnet CLI一样,PATH环境变量不用于解析除可执行文件之外的其他文件类型的文件路径(例如.exe.cmd.bat.ps1)。

您可以创建一个专用的环境变量,例如MY_CSPROJ_PATH,用于指定项目文件的路径,然后像这样使用它:

--project $env:MY_CSPROJ_PATH

或者,您可以使用项目文件必须位于用户目录的固定子目录中的约定,此时可以使用$env:HOME环境变量:

--project $env:HOME\projects\MyPassThruApp\MyPassThruApp\MyPassThruApp.csproj

参考文献:

[1] 顺便提一下,PowerShell意外地执行(使用默认的shell操作打开)$env:PATH中的任意文件 - 请参见GitHub问题#12632

英文:

Normally <sup>1</sup>, as is the case with the dotnet CLI, the PATH environment variable isn't used to resolve file paths for other file types than executables (e. g. .exe, .cmd, .bat, .ps1).

You may create a dedicated environment variable, say MY_CSPROJ_PATH that specifies the path to the project file and then use it like this:

--project $env:MY_CSPROJ_PATH

Alternatively you could use the convention that the project files have to reside in a fixed sub directory of the user's directory, in which case the $env:HOME environment variable could be used:

--project $env:HOME\projects\MyPassThruApp\MyPassThruApp\MyPassThruApp.csproj

<sup>[1] As an aside, PowerShell unexpectedly does execute (open with the default shell action) arbitrary files in $env:PATH - see GitHub issue #12632.</sup>

huangapple
  • 本文由 发表于 2023年2月16日 02:39:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75464135.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定