我的 .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 在发布中包含文件夹
发布评论