要实现“ASP.Net Core 2 - 仅在IIS Express中工作的PowerShell远程管理(Kestrel无法工作)”,可以按照以下步骤进行操作:
在ASP.Net Core 2项目的根目录中,创建一个名为powershell.ps1
的PowerShell脚本文件。
在powershell.ps1
中,添加以下代码来启动项目:
$projectPath = "路径/到/你的/ASP.Net Core 2项目"
$exePath = "$projectPath\bin\Debug\netcoreapp2.0\你的项目.dll"
$webHostArgs = "--urls http://localhost:5000"
$dotnetCmd = "dotnet"
Start-Process -NoNewWindow -FilePath $dotnetCmd -ArgumentList "run", "--project", $exePath, $webHostArgs
请确保将路径/到/你的/ASP.Net Core 2项目
替换为实际的项目路径。
launchSettings.json
的文件,如果已经存在,请添加以下配置:{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:5000",
"sslPort": 0
}
},
"profiles": {
"PowerShell": {
"commandName": "PowerShell",
"executablePath": "powershell",
"commandLineArgs": "-ExecutionPolicy Bypass -File powershell.ps1",
"launchBrowser": false,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
这将为PowerShell
配置一个启动配置,并使用powershell.ps1
脚本来启动项目。确保将executablePath
设置为正确的PowerShell可执行文件路径。
launchSettings.json
文件。现在,可以通过在项目的根目录中运行dotnet run
命令来启动ASP.Net Core 2项目。或者,可以在Visual Studio中选择PowerShell
配置并运行项目。
注意:这个解决方案仅在IIS Express中工作,不适用于Kestrel服务器。