Search code examples
asp.net-coregithub-actionsappsettings

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:

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

OR

  • Eliminate it with GitHub Actions

Solution

  • 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>