Search code examples
.netasp.net-core.net-corevisual-studio-2017dotnet-cli

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


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.


Solution

  • You have to use Update like so:

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