[SOLVED] How to use the password in pubxml.user during dotnet publish


I am trying to setup CI for a ASP.NET project. There is a publish profile defined in VS, which is working fine. (I can deploy the page to a remote IIS server.)

I want to automate this, using GitLab, so I am looking for a command line equivalent of the publish action of VS.

The publish profile files that VS is using can be found under Properties\PublishProfiles. I have 2 files here:

  • myServer.pubxml (contains the username to use for deploy, and other server data, like hostname)
  • myServer.pubxml.user (contains the encrypted password for the user)

My attempts to deploy/publish on the command line:

dotnet publish /p:PublishProfile=myServer.pubxml

This results in the following error:

MSDEPLOY : error Code: ERROR_USER_UNAUTHORIZED [C:\Users\myUser\source\repos\Beam Time Request\BeantimeRequest\BeantimeRequest.csproj] Error : The remote server returned an error : (401) Unauthorized. [C:\Users\myUser\source\repos\Beam Time Request\BeantimeRequest\BeantimeRequest.csproj] MSDEPLOY : error count: 1. [C:\Users\myUser\source\repos\Beam Time Request\BeantimeRequest\BeantimeRequest.csproj]

Which is logical, as I have not defined the password.

I can set the password on the command line, like this:

dotnet publish /p:PublishProfile=myServer.pubxml /p:password=myPassword

And this works, but I want to avoid having the password written in plain text.

So how could I tell dotnet publish to use the password from the myServer.pubxml.user file?


If anyone come across this:
I solved this with a GitLab Secret, as follows:

  1. Defined a new GitLab Secret for the repository, called DEPLOY_PASSWD
  2. using the following command to deploy:
    dotnet publish -c Release -o Publish /p:PublishProfile=myServer.pubxml /p:password=$DEPLOY_PASSWD"

Answered By – user2448122

Answer Checked By – Timothy Miller (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *