Publishing to Azure App Service - Error during GitHub Actions

Created Publish Profile to Azure App Service for a .Net Framework Project and was able to validate the connection on Visual Studio. 

Trying to setup CI/CD on GitHub Actions and getting error. Can someone help?

Workflow build step- 

msbuild <Solutionfile>.sln /p:Configuration=Release /p:Configuration=Release /p:DeployOnBuild=true /p:PublishProfile=<Publishprofilename(pubxmlfilename)>

Added the Secret for PublishProfile from Azure App Services.

Error:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\Web\Microsoft.Web.Publishing.targets(4284,5): msdeploy error ERROR_USER_UNAUTHORIZED: Web deployment task failed. (Connected to the remote computer (“vsaspnetmvcapp.scm.azurewebsites.net”) using the Web Management Service, but could not authorize. Make sure that you are using the correct user name and password, that the site you are connecting to exists, and that the credentials represent a user who has permissions to access the site. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_USER_UNAUTHORIZED.) [D:\a\vsaspdotnet\vsaspdotnet\aspnetmvcapp\aspnetmvcapp.csproj]

Hi @vinaysandela ,

I tried to ping ‘vsaspnetmvcapp.scm.azurewebsites.net’ from hosted runner but failed, does the site exist? or github hosted runner is restricted, you can try a selfhosted runner instead.

Did you create secrets in github repo setting and how did you invoke it in PublishProfile?

Typically can define it as a variable like $token in PublishProfile, and in workflow use below format:

- name: MSbuild
        run: |
          msbuild <Solutionfile>.sln /p:Configuration=Release /p:Configuration=Release /p:DeployOnBuild=true /p:PublishProfile=<Publishprofilename(pubxmlfilename)> #use $token in Publishprofile
        env:
          token: ${{ secrets.PAT }}

And please also recreate a new value for secrets for a try.

If the issue persists, please kindly share a repo/sample repo for further investigation, thanks.

Thanks for looking into it. 

Here is the link you can try - https://vsaspnetmvcapp.azurewebsites.net/

Yes, I’ve got the PublishProfile from Azure App Service and had that on secrets already- ${{ secrets.publish_profile }}

I am able to access the url from Visual Studio and from Azure App Service Portal. 

Please find my repo at - https://github.com/Sandelas/vsaspdotnet

Thanks

Hi @vinaysandela ,

I didn’t find the PublishProfile ‘vsaspnetmvcappPP’, did you put it in your repo?

I had Publish-Profile on Secrets- ${{ secrets.publish_profile }}

Hi @vinaysandela,

The value for parameter ‘/p:PublishProfile’ is the file name, not the profile content, and encrypted secerts value cannot be output.

Could you please try in a PRIVATE repo, put the publish profile file in the repo, and set the file name as the value for a check? 

Yes, I had uploaded the PublishProfile on the repo at - Properties/PublishProfiles/vsaspdotnet.PublishSettings

and changed the workflow build step as- 

msbuild aspnetmvcapp.sln /p:Configuration=Release /p:DeployOnBuild=true /p:PublishProfile=“vsaspdotnet.PublishSettings”

Also tried renaming the publishprofile with vsaspdotnetpp.pubxml.

Also updated the csproj with the <None Include=“Properties\PublishProfiles\vsaspdotnet.PublishSettings” />

They all dint worked. Got below error-

D:\a\vsaspdotnet\vsaspdotnet\aspnetmvcapp\Properties\PublishProfiles\vsaspdotnet.PublishSettings(1,1): error MSB4068: The element <publishData> is unrecognized, or not supported in this context. [D:\a\vsaspdotnet\vsaspdotnet\aspnetmvcapp\aspnetmvcapp.csproj]

Hi @vinaysandela ,

Sorry for late response.  In your repo, 3rd-party action ‘warrenbuckley/Setup-MSBuild’ and ‘warrenbuckley/Setup-Nuget’ are used to configure msbuild, and looks the issue is caused by the msbuild setup. It’s recommened to raise an issue on the action repo for confirmation.

And here is an example from Azure: builds a dotnet application, and publishes it to azure: https://github.com/Azure/actions-workflow-samples/blob/master/AppService/asp.net-core-webapp-on-azure.yml

Hope it helps!