Search code examples
azure-devopsweb-config

Azure DevOps Build Overwriting ConnectionString section in web.config


We are using azure devops onprem build for an older web forms application. When the build is complete, the web.config connection string section is updated but we do not have any transforms that should be occuring.

Here is as example. Where the $(ReplaceableToke_TestDatabaseName-Web.config Connection String_0, we have our actual connection string that EntityFrame work builds out.

I want the build to occur and not actually modify the connection string section. I don't see any options available to stop this from happening.

I have tried to add and remove /p:precompilebeforepublish variable and it hasn't helped.

/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=false /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.binariesdirectory)\"

 <connectionStrings>
    <add name="DatabaseName" connectionString="$(ReplacableToken_TestDataBaseName-Web.config Connection String_0)" providerName="System.Data.EntityClient" />
 <connectionStrings />

Solution

  • Azure DevOps Build Overwriting ConnectionString section in web.config

    To prevent the ConnectionString section from being modified in web.config, you could add the parameter /p:AutoParameterizationWebConfigConnectionStrings=False in your arguments.

    So, your arguments should be like:

    /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=false /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.binariesdirectory)\ /p:AutoParameterizationWebConfigConnectionStrings=False
    

    Alternatively, you can add this property into your project file .csproj:

    <PropertyGroup>    
     <AutoParameterizationWebConfigConnectionStrings>False</AutoParameterizationWebConfigConnectionStrings>
    </PropertyGroup>
    

    Hope this helps.