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.
You have to use Update
like so:
<Content Update="wwwroot\.gitignore">
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
Replace your code
<Content Include="wwwroot\.gitignore"> with
<None Include="wwwroot\.gitignore">
How did I get to know this? While going through the code of .csproj file I came across this tag (None) that was put by visual studio in front of all publish profiles' file (.pubxml). so I tried with my files as well and it worked like a charm.
The MSDN article on the build action property explains the differences.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With