启动 IIS Express 以运行 ASP.NET Core 应用程序

编程入门 行业动态 更新时间:2024-10-10 07:32:09
本文介绍了启动 IIS Express 以运行 ASP.NET Core 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我希望通过使用命令行从 IIS Express 启动来运行我的 ASP.NET Core 应用程序.

I wish to run my ASP.NET Core App by launching it from IIS Express using command line.

我偶然发现了 这篇 文章说

I stumbled across this article which says

所以其实Visual Studio是默默的添加了两个环境变量启动 IIS Express 时,以便 ASP.NET Core 相关位可以注射.

So in fact Visual Studio silently adds the two environment variables when launching IIS Express, so that ASP.NET Core related bits can be injected.

LAUNCHER_ARGS: -debug -p C:Program Filesdotnetdotnet.exe" -a exec"C:Userslextmdocumentsvisual studio2017ProjectsWebApplication2WebApplication2inDebug etcoreapp1.0WebApplication2.dll""-pidFile C:UserslextmAppDataLocalTemp2 mpFD6D.tmp" -wd C:Userslextmdocumentsvisual studio2017ProjectsWebApplication2WebApplication2"

LAUNCHER_ARGS: -debug -p "C:Program Filesdotnetdotnet.exe" -a "exec "C:Userslextmdocumentsvisual studio 2017ProjectsWebApplication2WebApplication2inDebug etcoreapp1.0WebApplication2.dll"" -pidFile "C:UserslextmAppDataLocalTemp2 mpFD6D.tmp" -wd "C:Userslextmdocumentsvisual studio 2017ProjectsWebApplication2WebApplication2"

-pidFileC:UserslextmAppDataLocalTemp2 mpFD6D.tmp"中的tmp文件可以随时更改.如何将 LAUNCHER_ARGS 添加为环境变量,即使 tmp 文件更改也能正常工作?

The tmp file in -pidFile "C:UserslextmAppDataLocalTemp2 mpFD6D.tmp" can always change. How do I add LAUNCHER_ARGS as environment variable which will make it work even if the tmp file changes?

让我知道是否有任何更简单的方法来启动 IIS Express 以使用命令行或 powershell 脚本运行 ASP.NET Core 应用程序.

Let me know if there is any easier way to launch IIS Express to run ASP.NET Core Apps with command line or powershell scripts.

推荐答案

您正在寻找 [System.IO.Path]::GetTempFileName() 方法.它在文件系统上创建空的临时文件并返回其唯一名称.

You are looking for [System.IO.Path]::GetTempFileName() method. It creates empty temp file on file system and returns its unique name.

我目前正在使用以下 PowerShell 脚本来运行我的 .NET Core 2.0 应用程序:

I'm currently using the following PowerShell script to run my .NET Core 2.0 App:

$env:LAUNCHER_ARGS = "-p ""<path to dotnet.exe>"" -a ""exec ""<path to webapp main dll>"""" -pidFile $([System.IO.Path]::GetTempFileName()) -wd ""<path to webapp root folder>"" -pr <project name>" $env:LAUNCHER_PATH = "<path to VSIISExeLauncher.exe>" & "<path to iisexpress.exe>" /config:"<path to applicationhost.config>" /site:"<webapp name>"

占位符(尖括号内的文本)必须填充相应的值.您可以通过从 Visual Studio 运行您的项目并使用 Process Explorer 检查 iisexpress.exe 进程的环境变量来找到它们,如您提供的链接中所示.

Placeholders (text within angle brackets) have to be filled with the corresponding values. You can find them out by running your project from Visual Studio and inspecting environment variables of iisexpress.exe process using Process Explorer as shown above in the link you provided.

更多推荐

启动 IIS Express 以运行 ASP.NET Core 应用程序

本文发布于:2023-11-07 15:29:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566823.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   Express   IIS   ASP   Core

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!