I have asp.net core 2 application. Based on documentation i have created .pubxml
file for my development environment. I am using web deployment (remote agent) to deploy the web package to target web server. On our build server where, jenkins is installed, i run the following command to build & deploy
D:\Jenkins\myproject\workspace\myapplication\Src\Api>dotnet publish Api.csproj /p:PublishProfile=development.pubxml
It builds and deploys the application successfully to target web server.
However my application has multiple appsettings
files specific to each environment. For example appsettings.json
, appsettings.development.json
, appsettings.staging.json
and appsettings.production.json
The deployment process deploys all the appsettings files to web server. (in this case to development web server)
How do i only include environment specific appsettings file? (in this case i want to deploy appsettings.json
, appsettings.development.json
but not other 2 files)
json, which set variables for different environments. But, if you don't need any appsettings (which is probably not true, but if it is, more power to you), you can remove it.
Yes, I'm leaving appsettings. json in the project and it's being deployed - for documentation and non-sensitive settings. And, yes, I could leave sensitive data encrypted in Visual Studio Online but for now, the simplest thing to do is hide an overriding version elsewhere in the file system, as I'm doing.
Of course, we can add and use multiple appsettings. json files in ASP.NET Core project. To configure and read data from your custom json files, you can refer to the following code snippet.
The appsettings. json file is an application configuration file used to store configuration settings such as database connections strings, any application scope global variables, etc. If you open the ASP.NET Core appsettings. json file, then you see the following code by default which is created by visual studio.
You can add <ItemGroup>
definitions to your publish profiles (.pubxml files) containing update statements for the files.
For example if the publish profile is named Production.pubxml
/ Staging.pubxml
according to the environment, you can add this item group to the root <Project>
xml node:
<ItemGroup>
<Content Update="appsettings.*.json" CopyToPublishDirectory="Never" />
<Content Update="appsettings.$(MSBuildThisFileName).json" CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With