Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
以跨平台方式在.NET解决方案后期构建中运行Powershell_.net_Visual Studio_Powershell_.net Core - Fatal编程技术网

以跨平台方式在.NET解决方案后期构建中运行Powershell

以跨平台方式在.NET解决方案后期构建中运行Powershell,.net,visual-studio,powershell,.net-core,.net,Visual Studio,Powershell,.net Core,如果我想在Visual Studio中生成后运行Powershell脚本,我可以在项目属性中的生成后事件中这样做: "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe" -file $(SolutionDir)Powershell\Post-Build.ps1 这包含在项目文件中,并且受到dotnet build的尊重,因此它也可以在命令行上工作 Powershell二进制文件的路径似乎在所有包含Powershell的Windo

如果我想在Visual Studio中生成后运行Powershell脚本,我可以在项目属性中的生成后事件中这样做:

"C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe" -file $(SolutionDir)Powershell\Post-Build.ps1
这包含在项目文件中,并且受到
dotnet build
的尊重,因此它也可以在命令行上工作

Powershell二进制文件的路径似乎在所有包含Powershell的Windows系统上都有保证,因此PS的绝对路径不是问题


这一切都很棒。但是我如何重写对powershellbin的引用,使其跨平台工作?有没有办法在非Windows平台上利用PS Core(
pwsh
)解析PS二进制文件的路径?

尽可能接近,PowerShell Core与Windows PowerShell的功能不是1:1匹配。PowerShell核心是PowerShell 6+,而Windows PowerShell是5.1及更低版本。如果您想要跨平台解决方案,正确的答案是将PowerShell Core作为标准PowerShell版本,并确保它作为Windows和Linux节点的依赖项安装。

PowerShell Core和PowerShell基本上是兼容的,但尚未完全兼容,因此,不管怎样,使用其中一种似乎是次优的。简单地强制要求在路径中安装PowerShell Core怎么样?这在Windows上也是可行的,然后你可以简单地普遍使用
pwsh
。如果我使用Powershell Core,你会推荐Jeroen Mostert在评论中给出的解决方案吗?要求
pwsh
位于路径中?在Windows上,安装后
pwsh
应已位于路径中。在Linux上,入口点通常位于路径上的某个地方。在任何一种情况下,您都应该确保
pwsh
在路径上,如果不在,则添加它。