Search code examples
.netasp.net-core-3.1github-actionsmsdeployhttp-error

GitHub actions publishes my site and ends with HTTP ERROR 500.30


My original question was about a deployment issue not showing wwwroot folder on the remote server. It turned out, I was wrong and that wasn't actually the issue. So I've edited my question (and the first few comments are not relevant now)!!

I'm trying to publish my website from GitHub to my server, via GitHub actions

- name: Stop Application Pool  
  shell: cmd  
  run: '"C:/Program Files (x86)/IIS/Microsoft Web Deploy V3/msdeploy.exe" -verb:sync -allowUntrusted -source:recycleApp -dest:recycleApp="${{ env.IIS_WEBSITE_NAME }}",recycleMode="StopAppPool",computerName="${{ env.DOMAIN_URL }}:8172/msdeploy.axd?site=${{ env.IIS_WEBSITE_NAME }}",username="${{ env.IIS_SERVER_USERNAME }}",password="${{ env.IIS_SERVER_PASSWORD }}",AuthType="Basic"'  
- name: Deploy Application to Live  
  shell: cmd  
  run: '"C:/Program Files (x86)/IIS/Microsoft Web Deploy V3/msdeploy.exe" -verb:sync -allowUntrusted -source:contentPath="%cd%\${{ env.PUBLISH_PATH }}" -dest:contentPath="${{env.IIS_WEBSITE_NAME}}",computerName="${{ env.DOMAIN_URL }}:8172/msdeploy.axd?site=${{ env.IIS_WEBSITE_NAME }}",username="${{ env.IIS_SERVER_USERNAME }}",password="${{ env.IIS_SERVER_PASSWORD }}",authtype="Basic"'  
- name: Start Application Pool  
  shell: cmd  
  run: '"C:/Program Files (x86)/IIS/Microsoft Web Deploy V3/msdeploy.exe" -verb:sync -allowUntrusted -source:recycleApp -dest:recycleApp="${{ env.IIS_WEBSITE_NAME }}",recycleMode="StartAppPool",computerName="${{ env.DOMAIN_URL }}:8172/msdeploy.axd?site=${{ env.IIS_WEBSITE_NAME }}",username="${{ env.IIS_SERVER_USERNAME }}",password="${{ env.IIS_SERVER_PASSWORD }}",AuthType="Basic"'   

The above is the code within GitHub actions. This stops the application pool on the server, deploys the site, and starts the application pool

This works for the most part (no exceptions or error messages in GitHub actions) but when I visit my result, I always see

enter image description here

The website publishes fine with a working website if i use WebDeploy in Visual Studio

I have researched and it seems like I need to set "remove additional files at destination" is also required, but, I can't see the command line argument for msdeploy to do this. However, as I'm using the verb sync I thought it would do that automatically.

Having written that, I do believe something strange is going on with left over files. If I manually delete the entire directory on my web server, and use the command lines above, the website publishes and works as expected. The issue only occurs if there are already files when I try to run the code above

I have no idea what I'm doing wrong.


Solution

  • You can try with -enableRule:DoNotDeleteRule in your msdeploy command.

    When you are deploying application from Visual Studio in Publish Settings there is a property called SkipExtraFilesOnServer and it is set to true.

    This property in msdeploy is transformed to -enableRule:DoNotDeleteRule.

    SkipExtraFilesOnServer is related to Remove additional files at destination. If you check Remove additional files at destination property then you will see SkipExtraFilesOnServer is set to false in Publish Settings.

    enter image description here

    Opposite command is -disableRule:DoNotDeleteRule. If you have direct access to the server you can go to the directory C:/Program Files (x86)/IIS/Microsoft Web Deploy V3/ and see msdeploy documentation in console with:

    msdeploy.exe /? or more specifically msdeploy.exe -help -enableRule

    If you want to see which command Visual Studio generate during publish you can follow next steps:

    • Right click on your project in Visual Studio
    • Unload Project (if it is .NET Framework)
    • Click on Edit Project File
    • In the <PropertyGroup> add <UseMsdeployExe>true</UseMsdeployExe>
    • Reload Project (if it is .NET Framework)
    • Rebuild solution
    • Publish

    Now with this configuration when you Publish your project in the Output window you will see generated command for msdeploy.