Reputation: 3762
I have a .NET Core app that is built in Azure DevOps CI pipeline. 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. Everything was fine when i used to store the connection string in appsettings.json
file. But that is not the case any more, now I am using User Secrets for local and Azure AppService Application settings for deployed version. That means CI pipeline will fail once it tries to run dotnet
command as the connection string will be empty. 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). I came up with idea of transforming the appsettings.json file during CI. Basically i store the connection string under variables and inject it to appsettings.json file by using File Transform task. 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. Any idea how i can achieve this ?
Upvotes: 0
Views: 1473
Reputation: 3762
File Transform task only works with variables. Therefore I ended up using Magic Chunk task 2 times. One task to transform appsettings.json so that it will have connection string before generating sql script. The second task does the reverse - transforming appsettings.json again so that connection string will be empty string after migrations sql script generated.
Upvotes: 1