Running ASP.NET Core Web App on IIS Express from Command Line
Running ASP.NET Core Web App on IIS Express from Command Line
Alper Ebiçoğlu
·
Follow
Published in
Volosoft
·
·
Mar 23, 2020
3 min read
—
I usually run the Web projects from Visual Studio. But it was required to run an ASP.NET Core 3.1 Web project from the Command Line on IIS Express
Visual Studio
At first, I thought it was easy! But I stumbled in some places. To keep this article simple, I don’t want to write all my tries.
Here’s how you can start an ASP.NET Core 3.1 Web Project from the Command Line
run-host.bat
SET ASPNETCORE_ENVIRONMENT=Development
SET LAUNCHER_PATH=bin\Debug\netcoreapp3.1\Volo.AbpIo.Account.Web.exe
cd /d "C:\Program Files\IIS Express\"
iisexpress.exe /config:"D:\Github\volo\abp\abp_io\.vs\Volo.AbpIo\config\applicationhost.config" /site:"Volo.AbpIo.Account.Web" /apppool:"Volo.AbpIo.Account.Web AppPool"
You need to modify the bold ones in the batch file. Descriptions:
- LAUNCHER_PATH: This is the exe file of your Web project. Be careful you don’t provide the full exe path. Set it as a relative path. My CSPROJ is located in “D:\Github\volo\abp\abp_io\src\Volo.AbpIo.Account.Web\Volo.AbpIo.Account.Web.csproj” and I set LAUNCHER_PATH as “bin\Debug\netcoreapp3.1\Volo.AbpIo.Account.Web.exe”
- /config: This is the applicationhost.config file path. My solution path is “D:\Github\volo\abp\abp_io\Volo.AbpIo.sln” and applicationhost.config is located in the “D:\Github\volo\abp\abp_io\.vs\Volo.AbpIo\config\applicationhost.config”
- /site: You can find the site name in the applicationhost.config file. It’s in the <sites> tag.
- /apppool: You can find the site name in the applicationhost.config file. It’s in the your <site> tag.
applicationhost.config File Content:
<sites>
....<site name="Volo.AbpIo.Account.Web" id="2">
<application path="/" applicationPool="Volo.AbpIo.Account.Web AppPool">
<virtualDirectory path="/" physicalPath="D:\Github\volo\abp\abp_io\src\Volo.AbpIo.Account.Web" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:56570:localhost" />
<binding protocol="https" bindingInformation="*:44333:localhost" />
</bindings>
</site>
....
And this is the GitHub Gist
When you create a batch file as “run-host.bat” and run it, it’ll run as seen below:
Command-line output window
You’ll also see the system tray application of IIS Express. Right-click on it and click “Show All Applications” to see your running Web Apps.
Windows System Tray Icon
If you encounter any problem while running the application, check your Windows Event Viewer (eventvwr.exe) for the detailed logs!
IIS Express Parameters:
---------------------------------------------------------
/config:config-file
The full path to the applicationhost.config file. The default value is the IISExpress8\config\applicationhost.config file that is located in the user's Documents folder.
/site:site-name
The name of the site to launch, as described in the applicationhost.config file.
/siteid:site-id
The ID of the site to launch, as described in the applicationhost.config file.
/path:app-path
The full physical path of the application to run. You cannot combine this option with the /config and related options.
/port:port-number
The port to which the application will bind. The default value is 8080. You must also specify the /path option.
/clr:clr-version The .NET Framework version (e.g. v2.0) to use to run the application. The default value is v4.0. You must also specify the /path option.
/systray:boolean
Enables or disables the system tray application. The default value is true.
/trace:debug-trace-level
Valid values are info or i,warning or w,error or e.
Check out the Microsoft Docs for the IIS Express usage.
Happy coding!