简体   繁体   English

从VS 2017 .NET核心项目中的发布目录中排除文件

[英]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下的整个文件夹被包含在部署中,经过各种试验和不同的事物组合后,唯一对我有用的是两者的组合:

  1. Exclude the folder from the project (ie 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. 完全按原样将以下内容添加到我的.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.

相关问题 从Visual Studio 2017运行ASP.NET Core项目 - Run ASP.NET Core Project from Visual Studio 2017 安装vs2017后无法打开vs2015 .net core 1.1项目 - Unable to open vs2015 .net core 1.1 project after installing vs2017 VS 2017 ASP.NET Core测试项目-缺少Microsoft.AspNetCore.Identity - VS 2017 ASP.NET Core Test Project - Microsoft.AspNetCore.Identity missing VS2017 .Net Core(完整框架)项目的后构建事件获取$(ConfigurationName)的空字符串 - VS2017 .Net Core (Full Framework) Project's Post Build Event gets empty string for $(ConfigurationName) 如何在VS 2017中将类图添加到ASP.NET Core项目? - How to add a Class Diagram to an ASP.NET Core project in VS 2017? 在一个目录下发布所有 .net 核心项目 - Publish all .net core projects in a directory 将项目从VS 2003升级到VS 2017 - Upgrading project from VS 2003 to VS 2017 如何在VS2017中引用.net项目中的netstandard项目? - How do you reference a netstandard project from .net project in VS2017? 在 VS 2017 中针对完整的 .net 框架 asp.net 核心项目运行 XUnit 2.2.0 单元测试时出现 System.BadImageFormatException - System.BadImageFormatException when running XUnit 2.2.0 unit test in VS 2017 against a full .net framework asp.net core project Asp.net core publish 在 Visual Studio 2017 的发布文件夹中创建所有 dll 文件 - Asp.net core publish creates all dll files in publish folder in visual studio 2017
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM