2

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:

  • Mark it as "no publish" from the .csproj or a similar setting

OR

  • Eliminate it with GitHub Actions

3 Answers 3

4

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Worked, let me see other answers before accepting.
1

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>

Comments

0

The approved solution works for publishing, but not for the standard build. I did not like the idea of removal, so I went the opposite way:

<ItemGroup Condition="'$(Configuration)' == 'Debug'">
  <None Update="appsettings.Development.json">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </None>
</ItemGroup>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.