[英]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. 我在项目的wwwroot
文件夹中有一个.gitignore
文件,我试图将其排除在发布之外。 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. 当我使用dotnet publish
命令发布项目时,仍会在输出目录中找到.gitignore
文件。
You have to use Update
like so: 您必须像这样使用Update
:
<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). 在浏览.csproj文件的代码时,我遇到了这个标签(无),它由visual studio放在所有发布配置文件的文件(.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. 有关构建操作属性的MSDN文章解释了这些差异。
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. 我有一个ASP.NET核心Web项目,我正在使用Web Deploy到远程服务器。 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: 我试图排除wwwroot下的整个文件夹被包含在部署中,经过各种试验和不同的事物组合后,唯一对我有用的是两者的组合:
AND 和
wwwroot\\\\profiles
to be the directory you want to exclude. 完全按原样将以下内容添加到我的.csproj中,但将wwwroot\\\\profiles
更改为要排除的目录。 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.