dotnet core 发布:在输出中包含/排除目录 [英] dotnet core publish: include/exclude dir in output

查看:47
本文介绍了dotnet core 发布:在输出中包含/排除目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定带有文件夹的 aspnet 项目:

<预><代码>//sql/网络应用程序/客户/wwwroot/浏览次数

在我使用的 project.json 上

"publishOptions": {包括": ["..\sql","wwwroot","观点",网络配置"]}

dotnet publish 之后有 sqlwwwrootViews 文件夹.

迁移到 csproj (Microsoft.NET.Sdk.Web) 后,我得到了

<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory></无>

msbuild15/t:publish(cli 对我不起作用)之后有 wwwrootViewsClient> 里面只有 json 文件.sql 中的文件已复制但已展平.

我也尝试将其更改为:

<Content Remove="Client*" CopyToPublishDirectory="从不"/>

并得到相同的输出.

如何删除Client并保留sql的文件夹结构?

解决方案

更新:

当使用 VS 2017 >= 15.3 或 .NET CLI 版本 >= 2.0 时,有一项新功能会自动为一些已知项目类型(包括 Content).这可以像这样使用:

原文:

你可以使用这个:

 <Content Remove="Client**"/><Content Include="..sql**" CopyToPublishDirectory="PreserveNewest" Link="sql\%(RecursiveDir)\%(Filename)%(Extension)"/></项目组>

包含项目链接元数据的内容有点小技巧,可以让 MSBuild 使用项目的相对路径作为目标路径.这是因为如果项目锥"之外的项目没有 Link 元数据(来源.

替代 <Content Remove="..."/> 您也可以这样做以保留 VS 中的文件:

Given aspnet project with folders:

/
  /sql
  /WebApp
    /Client
    /wwwroot
    /Views

On project.json I used

"publishOptions": {
    "include": [
      "..\sql",
      "wwwroot",
      "Views",
      "web.config"
    ]
  }

And after dotnet publish there was sql, wwwroot and Views folders.

After migration to csproj (Microsoft.NET.Sdk.Web), I got

<None Update="..sql***;wwwroot***;Views***">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>

After msbuild15 /t:publish (cli not works for me) there is wwwroot, Views AND Client with only json files inside. Files from sql copied but flattened.

I also try to change it to:

<Content Include="..sql**" CopyToPublishDirectory="PreserveNewest" />
<Content Remove="Client*" CopyToPublishDirectory="Never" />

and got same output.

How to remove Client and preserve folder structure for sql?

解决方案

Update:

When using VS 2017 >= 15.3 or a .NET CLI version >= 2.0, there is a new feature that automatically adds Link metadata for a few known item types (including Content). This can be used like:

<Content Include="..sql**" LinkBase="sql" />

Original:

You can use this:

  <ItemGroup>
    <Content Remove="Client**" />
    <Content Include="..sql**" CopyToPublishDirectory="PreserveNewest" Link="sql\%(RecursiveDir)\%(Filename)%(Extension)" />
  </ItemGroup>

The content include item's link metadata is a bit of hack to make MSBuild use the item's relative path as target path. This is because items outside of the "project cone" aren't considered in AssignTargetPath if they have no Link metadata (source).

Alternative to <Content Remove="..." /> you can also do this to still have the files inside VS:

<Content Update="Client**" CopyToPublishDirectory="Never" />

这篇关于dotnet core 发布:在输出中包含/排除目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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