question

6666666 avatar image
0 Votes"
6666666 asked BruceZhang-MSFT answered

How to auto publish to iis in vs 2009?

I am using IIS . I have to publish to the folder and copy it to the server right?

how to auto pulish?

or using git to auto publish?

windows-server-iisdotnet-aspnet-core-webapidotnet-aspnet-core-razor
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

BruceZhang-MSFT avatar image
0 Votes"
BruceZhang-MSFT answered

Hi @6666666 ,

When do you want VS to automatically release the application?

If you want VS to publish the application directly to the target IIS (no matter remote or local), you can choose Web Server (IIS) in Publish instead of Folder. You just need to right click solution and click publish after each modification. It will auto update application on IIS.

If you want to publish application after each building, you can use MSBuild and MSDeploy. Then combine with Powershell script.

 $WEBSITE_PATH = '<your visual studio solution web site path here'
 $BUILD_WEBSITE = '<path msbuild>/msbuild.exe <path .csproj file of your website>/yourfile.csproj  /T:Package /P:Configuration=Release'
    
 # stop IIS and Sql server 
 cmd /c 'iisrest /stop'
 if(-not $?)
 {
     'could not stop IIS.';
      
  }`
 cmd /c 'net stop mssqlserver'
 if(-not $?)
 {
     'could not stop SQL Server.';
  }`
    
    
 #pull your project before build 
 Write-Output 'Pull git project...'
 Invoke-Expression $WEBSITE_PATH
 cmd /c 'git pull'
 if(-not $?)
 {
     'could not pull the project from git.';
  }
    
  # build project 
 Write-Output 'Petclinic is building...'
 cmd /c $BUILD_WEBSITE
 if(-not $?)
 {
     'could not build the project. Check the stacktrace.';
     exit
  }
    
  # Import package create
 cmd /c '<path msDeploy>\msdeploy.exe -verb:sync -source:package=<path of your project>\obj\Release\Package\DotNetPetClinic.zip -dest:auto'
 if(-not $?)
 {
     'could not import the project.';
      exit
  }
    
  #restart IIS app pool to run the website
 cmd /c 'C:\Windows\System32\inetsrv\appcmd.exe start apppool /apppool.name:<NAME OF YOUR WEBSITE APP POOL'
 if(-not $?)
 {
     'error during restarting the appPool.';
      exit
  }`
    
    
  #  Restart IIS and SQL Sever Instance 
 cmd /c 'net start mssqlserver'
 if(-not $?)
 {
     'could not restart Sql Server.';
  }`
 cmd /c 'iisreset /start'
 if(-not $?)
 {
     'could not restart Sql Server.';
  }




If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.


Best regards,
Bruce Zhang




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.