Excluding File From Publish Directory in VS 2017 .NET Core Project

Muhammad Rehan Saeed picture Muhammad Rehan Saeed · Feb 27, 2017 · Viewed 10.4k times · Source

I have a .gitignore file in the wwwroot folder of my project that I am trying to exclude from being published. The following code does not seem to work:

<ItemGroup>
  <Content Include="wwwroot\.gitignore">
    <CopyToPublishDirectory>Never</CopyToPublishDirectory>
  </Content>
</ItemGroup>

When I publish the project using the dotnet publish command, the .gitignore file is still found in the output directory.

Answer

Muhammad Rehan Saeed picture Muhammad Rehan Saeed · Feb 28, 2017

You have to use Update like so:

<Content Update="wwwroot\.gitignore">
  <CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>