.NET Core 在发布中包含文件夹

编程入门 行业动态 更新时间:2024-10-19 22:24:40
本文介绍了.NET Core 在发布中包含文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的 .NET Core 2.1 项目具有以下文件夹结构:

I have the following folder structure for my .NET Core 2.1 project:

如何在发布解决方案时包含文件夹 AppData 及其所有子文件夹和文件?

How can I include folder AppData and all of its subfolders and files when I publish the solution?

我尝试将其添加到 .csproj 文件中,但没有成功:

I tried adding this to .csproj file but it didn't work:

<ItemGroup> <Folder Include="AppData*" /> </ItemGroup>

编辑

我也试过这个,但没有用:

I also tried with this and it didn't work:

<ItemGroup> <Content Include="AppData**" LinkBase="AppData" /> </ItemGroup>

推荐答案

添加:

<ItemGroup> <Content Include="AppData**"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> </ItemGroup>

到您的 .csproj 文件将复制 AppData 文件夹(如果它不为空).对于空的 AppData 文件夹,您可以使用以下解决方法:

to your .csproj file will copy AppData folder if it's not empty. For empty AppData folder you can use this workaround:

<Target Name="CreateAppDataFolder" AfterTargets="AfterPublish"> <MakeDir Directories="$(PublishDir)AppData" Condition="!Exists('$(PublishDir)AppData')" /> </Target>

如果它尚未包含在输出中,这将在发布后创建 AppData 文件夹.这意味着只有在发布时它是空的,才会创建 AppData 文件夹.

This will create AppData folder after publish if it won't be already included in output. Meaning this will create AppData folder only if it's empty while publishing.

更多推荐

.NET Core 在发布中包含文件夹

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

发布评论

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

>www.elefans.com

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