Excluding a file from a publishing directory in VS 2017. .NET Core Project

I have a .gitignore file in the wwwroot folder of my project, which I am trying to exclude from publication. The following code does not work:

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

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

+9
source share
4 answers

You should use Update like this:

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

Replace your code

 <Content Include="wwwroot\.gitignore"> with <None Include="wwwroot\.gitignore"> 

How did I find out about this? Looking through the code of the .csproj file, I came across this tag (None), which was put by the visual studio in front of the file of all published profiles (.pubxml). so I tried with my files and it worked like a charm.

The MSDN article on build action explains the differences.

+1
source

I have several files that I want to exclude from publication. Where did you put the tag to exclude them?

0
source

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

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

AND

  1. Adding the following to my .csproj is exactly as it is, but changing wwwroot\\profiles to the directory you want to exclude. You should also repeat the entire fragment for each folder that you want to exclude:
  <ItemGroup> <MsDeploySkipRules Include="CustomSkipFolder"> <ObjectName>dirPath</ObjectName> <AbsolutePath>wwwroot\\profiles</AbsolutePath> </MsDeploySkipRules> </ItemGroup> 
0
source

Source: https://habr.com/ru/post/1015315/


All Articles