ASP.NET Core:在发布时排除或包含文件 [英] ASP.NET Core: Exclude or include files on publish

查看:262
本文介绍了ASP.NET Core:在发布时排除或包含文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

project.json文件中的aspdotnet1.0包含/排除部分之前

There were before aspdotnet1.0 include/exclude sections on project.json file

{
  "exclude": [
    "node_modules",
    "bower_components"
  ],
  "publishExclude": [
    "**.xproj",
    "**.user",
    "**.vspscc"
  ]
}

ASP.NET Core 1.1中的此部分在哪里(没有project.json)? .csproj文件或.pubxml上是否有类似的部分?

Where is this section in ASP.NET Core 1.1 (there is no project.json)? Are there similar sections on .csproj file or .pubxml?

推荐答案

来自文档:如果您希望指定(例如,一些文件要随您的应用发布),您仍然可以使用csproj中的已知机制(例如,<Content>元素).

From documentation: if you wish to specify, for example, some files to get published with your app, you can still use the known mechanisms in csproj for that (for example, the <Content> element).

对于ItemGroup 元素,有一个CopyToPublishDirectory属性.确定是否将文件复制到发布目录,并且可以具有以下值之一:

There is a CopyToPublishDirectory attribute for ItemGroup elements that determines whether to copy the file to the publish directory and can have one of the following value:

  • 总是
  • PreserveNewest
  • 从不

请注意,输出文件夹也有类似的CopyToOutputDirectory属性.

Note, that there is also similar CopyToOutputDirectory attribute for output folder.

示例(来自此处):

<ItemGroup>

  <None Include="notes.txt" CopyToOutputDirectory="Always" />
  <!-- CopyToOutputDirectory = { Always, PreserveNewest, Never } -->

  <Content Include="files\**\*" CopyToPublishDirectory="PreserveNewest" />
  <None Include="publishnotes.txt" CopyToPublishDirectory="Always" />
  <!-- CopyToPublishDirectory = { Always, PreserveNewest, Never } -->
</ItemGroup>


如果您很感兴趣project.json -.csproj迁移如何使用CopyToPublishDirectory属性来迁移发布选项,则可以查看


If you are interesting how project.json -.csproj migration use CopyToPublishDirectory attribute to migrate publish options, you may look into MigratePublishOptionsRule class in dotnet cli repo.

这篇关于ASP.NET Core:在发布时排除或包含文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆