.NET Core 在发布中包含文件夹 [英] .NET Core include folder in publish

查看:113
本文介绍了.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 在发布中包含文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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