John von No Man
John von No Man

Reputation: 3030

How to build and run a .NET Framework MVC project from command line with MSBuild and IIExpress.exe

I surprisingly didn't find any good answers after a bit of Googling. With .NET Core I can just do dotnet run, but I'm not sure how to do it on my .NET Framework 4.7 project.

I can build with MSBuild like this: MSBuild.exe *.sln.

But I can't figure out how to set IISExpress.exe to launch my MVC project using the settings Visual Studio uses. Ideas?

Upvotes: 3

Views: 5666

Answers (1)

N. Raj
N. Raj

Reputation: 457

For my .NET Framework 4.6.1 project, I was able to start my server by these 2 lines of PowerShell script.

PS> cd "C:\Program Files (x86)\IIS Express\"
PS> ./iisexpress /config:E:\Repos\MyProjectFolder\.vs\SolutionName\config\applicationhost.config /site:MyProjectName

To find the equivalent script for your project I recommend the following.

  1. Find the location of applicationhost.config file. IIS Express uses this file to start the projects in Visual Studio. It usually resides in .vs folder. Here's the complete path E:\Repos\MyProjectFolder\.vs\SolutionName\config\applicationhost.config
  2. Find iisexpress.exe. For me, path is C:\Program Files (x86)\IIS Express\iisexpress.exe.
  3. Start IIS Express server by specifying the applicationhost.config full path and the site you wish to start.

NOTE: The site/project must be listed on your applicationhost.config file like shown below.

     <sites>
         <site name="MyProjectName" id="1">
             <application path="/" applicationPool="Clr4IntegratedAppPool">
                 <virtualDirectory path="/" physicalPath="E:\Repos\MyProjectFolder\" />
             </application>
             <bindings>
                 <binding protocol="https" bindingInformation="*:44466:localhost" />
                 <binding protocol="http" bindingInformation="*:12435:localhost" />
             </bindings>
         </site>
     </sites>

Upvotes: 5

Related Questions