Adam
Adam

Reputation: 4164

Removing appsettings.Development.json when deploying an ASP.NET Core website via GitHub Action

I have an ASP.NET Core 7 project deployed with GitHub Actions.

Internally the appsettings.Development.json is pushed into Git as all the developers are using the same setting.

But this file is not needed on deployment and may cause an unintended behaviour if used by mistake or even if compromised.

I didn't find an option to filter out this file at GitHub Actions actions/checkout@v3. We have also looked at an option to delete is with Jesse Remove but that didn't work and even if it works it would have been a patch rather than a proper solution.

Is there any solution to:

OR

Upvotes: 1

Views: 801

Answers (2)

Leo Lloyd Andrade
Leo Lloyd Andrade

Reputation: 49

I use this to remove development config in a release build:

  <!-- Exclude appsettings.Development.json in release build -->
  <ItemGroup Condition="'$(Configuration)' == 'Release'">
    <Content Remove="appsettings.Development.json"></Content>
  </ItemGroup>

Upvotes: 1

Dimitris Maragkos
Dimitris Maragkos

Reputation: 11312

You can add this to your .csproj to remove appsettings.Development.json from publish:

<Project ...>
  ...

  <ItemGroup>
    <Content Update="appsettings.Development.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </Content>
  </ItemGroup>

</Project>

Upvotes: 4

Related Questions