2

I have actually a ASP.NET project with Angular 5 (Angular CLI).

My question is, it is possible to execute ng serve command when i start IIS Express?

Actually I have to open a cmd, execute ng serve and then start IIS.

If someone have a solution for that, thanks a lot :)

Heroz
  • 61
  • 1
  • 1
  • 9

3 Answers3

3

You will have to run "ng build" and then deploy files/folders into ISS from "dist" folder of angular cli

Mukesh
  • 69
  • 7
2

1.Just like what adiii4 suggests. You can call the post-build-event as an alternative way. Copy the ng serve command into the post-build-event textbox.

2.And to achieve this goal: execute ng serve command when i start IIS Express

Since we can run IIS express from command-line,you can add the two commands in post-build-event by newlines like this issue.

3.In addition,a post-build-event will run every time you build the project.(No matter debug or release mode) I'm not sure if this meet your needs well, we can customize it by Right-click Project=>Unload Project=>Edit xxx.csproj.

e.g: We'll find the PostBuild Target at the bottom, add a Condition=" '$(Configuration)' == 'Debug' " can help control only in debug mode to execute ng serve command and start IIS Express like:

<Target Name="PostBuild" AfterTargets="PostBuildEvent"  Condition="'$(Configuration)'=='Debug'">
    <Exec Command="here commad1:call test.exe&#xD;&#xA;here command2:xxx.exe xxx" />
</Target>

Update:

When we add something in post-build-event, the Target "PostBuild" will be added into xxx.csproj file automatically (Below format is for asp.net core web app).

And we can add a custom script like below to do another target after the build engine run the PostBuild target. For your situation, ngserve.bat is for ng serve, and startIIS.bat is for starting IIS.

  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="call ngserve.bat" />
  </Target>

  <Target Name="StartIIS" AfterTargets="PostBuild">
    <Exec Command="call startIIS.bat"/>
  </Target>

enter image description here

In addition: In VS, we can go Tools=>options=>Projects and solutions=>Build and run to change the msbuild project build output verbosity to detailed. After that, every time we build the solution or project, we can see detailed info about the build process, which helps troubleshooting.

LoLance
  • 25,666
  • 1
  • 39
  • 73
  • Thanks for your comment. Im using post-build-event with a bat file but now iis is not starting. I think its because ng serve is never closed and iis is waiting the bat file. Do you know how to start my bat file in background ? Thanks;) – Heroz Apr 09 '19 at 16:07
  • @Heroz What's the content of the bat file? Do you mean you use the post-build-event to execute the bat(for ng serve) and then in which way you start the IIS? As a command2 in post-build or start manually? – LoLance Apr 09 '19 at 16:31
  • Hi, sorry for the delay and thanks for the help. My bat file contains the command "ng serve". To use it => "Right Click on project => Build Event and set "CALL ngServe.bat". After that I run my solution but actually is blocking. Im checking your update – Heroz Apr 16 '19 at 13:11
1

One way would be to utilize the build events in Visual Studio.

After a build you could call the command ng serve as a post-build event.

Adrian
  • 807
  • 2
  • 12
  • 25