dotnet核心发布:在输出中包含/排除目录

编程入门 行业动态 更新时间:2024-10-14 18:17:15
本文介绍了dotnet核心发布:在输出中包含/排除目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

Given aspnet project with folders:

/ /sql /WebApp /Client /wwwroot /Views

在我使用的project.json上

On project.json I used

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

dotnet publish之后有sql,wwwroot和Views文件夹.

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

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

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

在msbuild15 /t:publish之后(cli不适用于我),其中只有json个文件,其中有wwwroot,Views和Client. sql中的文件已复制但已展平.

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.

我也尝试将其更改为:

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

并获得相同的输出.

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

How to remove Client and preserve folder structure for sql?

推荐答案

更新:

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

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" />

原文:

您可以使用此:

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

包含项的链接元数据的内容有点使MSBuild使用项的相对路径作为目标路径.这是因为如果没有Link元数据(源).

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).

除了<Content Remove="..." />之外,您还可以执行此操作以使VS中仍包含文件:

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

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

更多推荐

dotnet核心发布:在输出中包含/排除目录

本文发布于:2023-11-17 08:51:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609518.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:核心   目录   dotnet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!