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

Deadly 提交于 2019-12-04 02:14:17

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.

Unfortunately the voted answer did not work for me. I had an ASP.NET Core web project and I was using Web Deploy to a remote server. I was trying to exclude a whole folder under wwwroot from being included in the deployment and after various trials and different combinations of things the only thing that worked for me was a combination of both:

  1. Exclude the folder from the project (i.e. right-click > Exclude from project)

AND

  1. Adding the following to my .csproj exactly as it is but changing wwwroot\\profiles to be the directory you want to exclude. You also have to repeat the whole snippet for each folder you want to exclude:
  <ItemGroup>
    <MsDeploySkipRules Include="CustomSkipFolder">
      <ObjectName>dirPath</ObjectName>
      <AbsolutePath>wwwroot\\profiles</AbsolutePath>
    </MsDeploySkipRules>
  </ItemGroup>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!