Deploying asp.net core 6 to environment with appsettings transform

peter.morlion's Avatar

peter.morlion

09 Sep, 2022 12:57 PM

I've converted a ASP.NET 4.6 web application to ASP.NET Core 6. Previously, I used appveyor.yml to build the artifact and I had two environments configured via the AppVeyor UI (staging & production). These environments contain environment variables and I used parameter substitution with parameters.xml to change the web.config with the correct values per stage. These include secrets.
Now that I've moved to ASP.NET Core 6, I'm not sure how to continue. I've move everything to appsettings.json. There is still a web.config, but it only contains the environment name so my application knows which appsettings..json to add over appsettings.json.
But obviously, I don't want to put all my secrets in appsettings..json because these files are in source control. I want to keep these values in the AppVeyor environment UI and was hoping that I can update the appsettings.json file when deploying.
I read about Mitch Gollub's deploy.ps1 script (https://www.mitchgollub.com/net-core-appsettings-json-variable-repl...) but that doesn't seem to work when using AppVeyor's environments feature.
So my question is how can I take the values in the AppVeyor environment and put them in my appsettings.json on deployment? Or should I be looking at this differently? What is the recommended way of deploying an ASP.NET Core 6 app with AppVeyor and without putting secrets in source control?

  1. Support Staff 1 Posted by Feodor Fitsner on 09 Sep, 2022 02:12 PM

    Feodor Fitsner's Avatar

    Hi Peter,

    Could you please confirm where is ASP.NET 4.6 app currently hosted and what method do you use to deploy it? Where is ASP.NET Core 6 app going to be hosted?

  2. 2 Posted by peter.morlion on 09 Sep, 2022 02:41 PM

    peter.morlion's Avatar

    Both are/were hosted by IIS on a VM in Google Cloud. I've installed the ASP.NET Core 6 Hosting bundle. I actually manually changed the appsettings.json file and then I can load the site. But of course, I want AppVeyor to change the appsettings.json file for me, so it happens on every deploy, and per environment.

  3. Support Staff 3 Posted by Feodor Fitsner on 09 Sep, 2022 02:47 PM

    Feodor Fitsner's Avatar

    OK, do you use WebDeploy to deploy the app to that VM?

  4. 4 Posted by peter.morlion on 12 Sep, 2022 02:32 PM

    peter.morlion's Avatar

    Hi Feodor, sorry for the late reply and for forgetting to mention it. Yes, I'm using WebDeploy to deploy to the server.

  5. Support Staff 5 Posted by Feodor Fitsner on 12 Sep, 2022 05:16 PM

    Feodor Fitsner's Avatar

    OK, so WebDeploy can't change appsettings.json during the deployment. However, as you're fully controlling the target server and IIS is used you can look into using of AppVeyor Deployment Agent: https://www.appveyor.com/docs/deployment/agent/. With deployment agent you can have deploy.ps1 changing appsettings.json. Let me know what you think.

  6. 6 Posted by peter.morlion on 13 Sep, 2022 06:19 PM

    peter.morlion's Avatar

    Thank you! By combining the AppVeyor Deployment Agent docs with this script (https://gist.github.com/eivindivine/83cbfbf2efb97575ec7c1268459a05a...) I was able to do what I wanted.

  7. peter.morlion closed this discussion on 13 Sep, 2022 06:20 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac