简体   繁体   English

在CI构建管道中临时更新appsettings.json文件

[英]Updating appsettings.json file during CI build pipeline temporarily

I have a .NET Core app that is built in Azure DevOps CI pipeline. 我有一个在Azure DevOps CI管道中构建的.NET Core应用程序。 During the CI I also generate sql scripts from EF migrations using dotnet ef migrations script command which then are being run during CD pipeline. 在CI期间,我还使用dotnet ef migrations script命令从EF迁移生成sql脚本,然后在CD管道中运行该dotnet ef migrations script Everything was fine when i used to store the connection string in appsettings.json file. 当我过去将连接字符串存储在appsettings.json文件中时,一切都很好。 But that is not the case any more, now I am using User Secrets for local and Azure AppService Application settings for deployed version. 但是,情况不再如此,现在我将用户密钥用于本地版本,将Azure AppService应用程序设置用于已部署的版本。 That means CI pipeline will fail once it tries to run dotnet command as the connection string will be empty. 这意味着CI管道一旦尝试运行dotnet命令将失败,因为连接字符串将为空。 I did my research to see if connection string dynamically can be added to dotnet command on the run but that is not an option (just yet, but looks like dev team has plans for it). 我进行了研究,以查看是否可以在运行时将连接字符串动态添加到dotnet命令中 ,但这不是一个选择(尽管如此,但看起来开发团队已制定了计划)。 I came up with idea of transforming the appsettings.json file during CI. 我想到了在CI期间转换appsettings.json文件的想法。 Basically i store the connection string under variables and inject it to appsettings.json file by using File Transform task. 基本上,我将连接字符串存储在变量下,并通过使用File Transform任务将其注入到appsettings.json文件中。 But the problem is that this task will update and save the file, which means during publish it will have the updated file. 但是问题在于此任务将更新并保存文件,这意味着在发布过程中它将具有更新的文件。 But what i want is to transform the file just temporarily so that i can run dotnet command without any problem and also not deploy the json file with connection string in it. 但是我想要的只是临时转换文件,这样我就可以运行dotnet命令而没有任何问题,并且也可以不部署带有连接字符串的json文件。 Any idea how i can achieve this ? 知道我如何实现这一目标吗?

File Transform task only works with variables. 文件转换任务仅适用于变量。 Therefore I ended up using Magic Chunk task 2 times. 因此,我最终使用了Magic Chunk任务2次。 One task to transform appsettings.json so that it will have connection string before generating sql script. 转换appsettings.json的一项任务,以便在生成sql脚本之前具有连接字符串。 The second task does the reverse - transforming appsettings.json again so that connection string will be empty string after migrations sql script generated. 第二个任务是相反的-再次转换appsettings.json,以便在生成迁移sql脚本后,连接字符串将为空字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 appsettings.json 设置包含到 Azure DevOps 构建和发布管道中 - How to include appsettings.json settings into Azure DevOps build and release pipeline 未找到配置文件“appsettings.json”且不是可选的 - The configuration file 'appsettings.json' was not found and is not optional 在 azure 部署的应用程序中更新 appsettings.json 值 - Updating appsettings.json values in azure deployed application 从 Azure 中的 KeyVault 更新 appsettings.json 值 Function - Updating appsettings.json values from KeyVault in Azure Function Azure应用程序设置不会覆盖我的appsettings.json文件值 - Azure Application Settings not overriding my appsettings.json file values 将功能部署到Azure时无法加载appsettings.json文件 - Could not load the appsettings.json file when function deployed to azure 如何跟踪 appsettings.json 文件中设置的使用情况 - How the track the usage of settings in appsettings.json file 在 Appsettings.Json 添加数组元素,on Azure Devops Release Pipeline Via magic chunks Config transformation - Adding array element in Appsettings.Json, on Azure Devops Release Pipeline Via magic chunks Config transformation Azure 批处理服务 - 找不到 appsettings.json - Azure Batch Service - appsettings.json not found 在azure webapp上应用appsettings.json - applying appsettings.json on azure webapp
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM