Search code examples
.net.net-coremsbuildmsdeploy

dotnet publish behind proxy 407


I am trying to setup my gitlab build server to deploy an ASP.NET Core project using msdeploy. Now the problem is that my deploy gets blocked by the proxy server...

How do I configure the proxy in the dotnet publish command?

MSDEPLOY : error Code: ERROR_COULD_NOT_CONNECT_TO_REMOTESVC
Error : The remote server returned an error : (407) Proxy Authentication Required. 
MSDEPLOY : error count: 1. 

This is the command I have currently:

dotnet publish [project.csproj] -c Release /p:PublishProfile="[Location of publish profile]" /p:Password="[Password]"

Example of a publish profile

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>MSDeploy</WebPublishMethod>
    <PublishProvider>AzureWebSite</PublishProvider>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish>[Url]</SiteUrlToLaunchAfterPublish>
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <ProjectGuid>[Guid]</ProjectGuid>
    <MSDeployServiceURL>[URL]</MSDeployServiceURL>
    <DeployIisAppPath>DeployProd</DeployIisAppPath>
    <RemoteSitePhysicalPath />
    <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
    <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
    <EnableMSDeployBackup>True</EnableMSDeployBackup>
    <UserName>[Username]</UserName>
    <_SavePWD>True</_SavePWD>
    <_DestinationType>AzureWebSite</_DestinationType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <SelfContained>false</SelfContained>
  </PropertyGroup>
</Project>

Solution

  • You need to specify your environment variable:

    http_proxy = http://user:pass@proxy:port/
    https_proxy = http://user:pass@proxy:port/
    

    And if your gitlab is not behind the proxy then you need to exclude it:

    no_proxy=servername,servername2
    

    Then you need to inform msdeploy to use this proxy information. Look for which msdeploy.exe is used by the gitlab runner and modify it's .config file. Add the following in between the configuration tags:

      <system.net>
        <defaultProxy useDefaultCredentials="true" enabled="true"/>
      </system.net>