我的组织有一个复杂的Web应用程序,通常需要打开多个Visual Studio实例来运行不同的解决方案,然后通过IIS Express启动所有API和接口项目,其中一些是.net核心。对于我的需求,我实际上不需要打开VS,只需要在后台运行API和UI项目
我正在尝试构建一个批处理脚本来为我完成此任务。目前,我已经用msbuild
构建每个项目,但是我无法使iisexpress
正常工作。
这是我到目前为止所拥有的。
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
这就是我作为控制台输出得到的
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
问题似乎是第一个在IIS Express中正常启动,但是随后挂起,无法继续进行下一个。这是有道理的,但是我需要一种同时启动多个站点的方法。
答案 0 :(得分:0)
我发现这里唯一真正的解决方案似乎是为每个IIS Express&.NET核心实例打开一个新的命令窗口。有点烦人,但它可以工作,并且也可以将已经最小化的它们启动。这是我更改过的.bat
文件
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