web.config 中的 Azure DevOps 构建覆盖 ConnectionString 部分

Azure DevOps Build Overwriting ConnectionString section in web.config

我们正在为较旧的 Web 表单应用程序使用 azure devops onprem build。构建完成后,web.config 连接字符串部分会更新,但我们没有任何应该发生的转换。

举个例子。在 $(ReplaceableToke_TestDatabaseName-Web.config 连接 String_0 的位置,我们有 EntityFrame 构建的实际连接字符串。

我希望进行构建而不是实际修改连接字符串部分。我没有看到任何可用的选项来阻止这种情况的发生。

我尝试添加和删除 /p:precompilebeforepublish 变量,但没有帮助。

/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 />

Azure DevOps Build Overwriting ConnectionString section in web.config

要防止 ConnectionString 部分在 web.config 中被修改,您可以在参数中添加参数 /p:AutoParameterizationWebConfigConnectionStrings=False

所以,你的论点应该是这样的:

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

或者,您可以将此 属性 添加到您的项目文件中 .csproj:

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

希望这对您有所帮助。