12
votes

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)

2

2 Answers

17
votes

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>
0
votes

I could handle this with the following *.pubxml:


<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
   .
   .
   .
  </PropertyGroup>
  <ItemGroup>
    <Content Update="appsettings.Development.json">
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
      <CopyToOutputDirectory>Never</CopyToOutputDirectory>
    </Content>
    <Content Update="appsettings.TestBed.json">
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
      <CopyToOutputDirectory>Never</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
</Project>