启动 IIS Express 以运行 ASP.NET Core 应用程序 [英] Launch IIS Express to run ASP.NET Core Apps

查看:36
本文介绍了启动 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 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆