My organization has a complex webapp that normally requires opening multiple instances of Visual Studio to run different solutions, and then start up all the API & interface projects via IIS Express and some are .net core. For my needs, I don't actually need to have VS open, I only need the API & UI projects running in the background
I am trying to build a batch script that will do this for me. Currently I've got it building each project with msbuild
, but I'm having trouble getting the iisexpress
stuff to work.
Here's what I have so far.
SET MSBuildPath="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe"
SET IISExpressPath="%ProgramFiles(x86)%\IIS Express\IISExpress.exe"
SET ACPath=%HOMEPATH%\Workspace\MyProject
SET ConfigFile=%ACPath%\.vs\config\applicationhost.config
%MSBuildPath% "%ACPath%\Project1API\Project1API.csproj" /verbosity:quiet
%MSBuildPath% "%ACPath%\Project2API\Project2API.csproj" /verbosity:quiet
%MSBuildPath% "%ACPath%\Project3API\Project3API.csproj" /verbosity:quiet
%IISExpressPath% /site:Project1API /config:%ConfigFile%
start "" http://localhost:1106
%IISExpressPath% /site:Project2API /config:%ConfigFile%
start "" http://localhost:49418
%IISExpressPath% /site:Project3API /config:%ConfigFile%
start "" http://localhost:50244
dotnet run -p "%ACPath%\SubFolder\Project4API\Project4API.csproj"
start "" http://localhost:60711
dotnet run -p "%ACPath%\SubFolder\ProjectInterface\ProjectInterface.csproj"
start "" http://localhost:54225
Here's what I get as console output
C:\Users\MyUserName\Workspace>"C:\Program Files (x86)\IIS Express\IISExpress.exe" /site:Project1API /config:\Users\MyUserName\Workspace\Project1API\.vs\config\applicationhost.config
Starting IIS Express ...
Successfully registered URL "http://localhost:1106/" for site "Project1API" application "/"
Successfully registered URL "https://localhost:44300/" for site "Project1API" application "/"
Registration completed for site "Project1API"
IIS Express is running.
Enter 'Q' to stop IIS Express
The issue seems to be that the first one starts up in IIS Express just fine, but then it hangs there and does not continue on to the next one. This makes sense, however I need a way to start multiple sites at once.
I figured out that the only real solution here seems to be to open a new command window for each IIS Express & .NET core instance. A bit annoying, but it works and it's possible to also start them already minimized. Here's my changed .bat
file
SET MSBuildPath="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe"
SET IISExpressPath="%ProgramFiles(x86)%\IIS Express\IISExpress.exe"
SET ACPath=%HOMEPATH%\Workspace\MyProject
SET ConfigFile=%ACPath%\.vs\config\applicationhost.config
:: Build the 3 API projects
%MSBuildPath% "%ACPath%\Project1Api\Project1Api.csproj" /verbosity:quiet
%MSBuildPath% "%ACPath%\Project2Api\Project2Api.csproj" /verbosity:quiet
%MSBuildPath% "%ACPath%\Project3Api\Project3Api.csproj" /verbosity:quiet
:: Start up an minimized IIS Express instance for each API
start /min cmd /c "%IISExpressPath%" /config:%ConfigFile% /site:Project1Api
start /min cmd /c "%IISExpressPath%" /config:%ConfigFile% /site:Project2Api
start /min cmd /c "%IISExpressPath%" /config:%ConfigFile% /site:Project3Api
:: Build the 2 .NET Core projects, and then launch the UI project in a browser
start /min cmd /c dotnet run -p "%ACPath%\SubFolder\Project4Api\Project4Api.csproj"
start /min cmd /c dotnet run -p "%ACPath%\SubFolder\ProjectInterface\ProjectInterface.csproj" & start "" http://localhost:54225