简体   繁体   中英

How to restart the IIS Site when re-compiling an asp.net website

What is the best way to add into the build/compile script of an Asp.net project to initiate a IIS to restart the website on DLL rebuild instead of the first request to the site.

Current Process

  1. Compile Project
  2. Wait
  3. Hit APSX Page
  4. IIS starts reload
  5. Wait
  6. Page loads

Ideal process:

  1. Compile Project & Reload IIS
  2. Wait
  3. Hit APSX Page
  4. Page loads

The first way I though of was add a request to just hit one of the pages in the "Post-Build events". Just wondering best practices. This would be similar to "Start" which opens a page immediately on build.

Update: The reason I would like to accomplish this is for just for efficiency. I would the to encapsulate the compile time and the restart time into one batch to save on time on step 4 below

  1. VS: ctrl + shift + b
  2. Wait for visual que "Build succeeded".
  3. Broswer: F5 .
  4. Wait for IIS reload. (as well as Hit kbd>F5 in unanswered questions in SO )
  5. Test page

Add 'iisreset /stop' into the Pre-Build event and 'iisreset /restart' at the end of the Post-Build event.

As David mentioned, you should try to find out what the underlying issue is here. If you are experiencing performance issues when first loading a website, this is quite normal. The initial compilation often takes some time to occur. Resetting IIS is only going to make it take longer. If there is another issue, please post your reason for doing this here, and we can see if we can help you.

A naive way would be to write a shell vb script or PowerShell script to use XmlHttpRequest to request a page from the site, and include that as a post-build task.

Is there any particular reason you feel the need to do this? If you're experiencing performance issues at the first JIT then you may need to consider breaking up your application into smaller projects/DLLs (assuming that size is the issue), or start looking at bottlenecks that occur when your app starts.

Another question: why the IIS reset? That won't cause the DLL to be recompiled until the first page request. Unlike classic ASP, it isn't necessary to restart IIS for DLL changes to be allowed/take effect.

The "wait" you are hoping to remove from the process is most likely the aspx markup pages compiling. When you build in VS by default it will compile all your code, but it will not compile your markup aspx pages. You can get round this by adding a Web Deployment Project to your solution, which allows you to precompile the markup pages. This way the initial load time after deployment should not be very much different to any other load time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM