Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How exclude certain appsettings files from publishing

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)

like image 705
LP13 Avatar asked May 18 '18 19:05

LP13


People also ask

Can I delete Appsettings json?

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.

Can I move Appsettings json out of the app directory?

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.

Can we have multiple Appsettings json?

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.

Which Appsettings file is used?

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.


1 Answers

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>
like image 99
Martin Ullrich Avatar answered Sep 19 '22 01:09

Martin Ullrich