Visual Studio:如何“复制到输出目录"不复制文件夹结构? [英] Visual Studio: How to "Copy to Output Directory" without copying the folder structure?
问题描述
我的项目文件夹的 lib 文件夹中有几个 dll 文件.在dll的属性页中,我选择了构建操作"为内容",复制到输出目录"为始终复制".
I have a few dll files in lib folder of my project folder. In the property page of dll, I have selected "Build Action" as "Content" and "Copy to Output Directory" as "Copy always".
构建后,我实际上正在复制 dll,但它们在 inReleaselib 中,而不是在 inRelease 中.
After build I am actually getting the dll copied but they are inside inReleaselib and not in inRelease.
有没有办法将 dll 文件复制到 inRelease(而不是 inReleaselib)而无需编写构建后脚本或求助于 nant 等?
Is there a way to copy dll files to inRelease (and not to inReleaselib) without writing a post-build script or resorting to nant etc?
推荐答案
代替
使用
并指定目标路径,如下所示:
instead of <Content>
use <ContentWithTargetPath>
and specify target path, like this:
<ItemGroup>
<ContentWithTargetPath Include="libsome_file.dat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>some_file.dat</TargetPath>
</ContentWithTargetPath>
<None Include="libsome_file.dat" />
</ItemGroup>
请注意,此条目可能在 Visual Studio(2012、2015、2017)中不可见,但一旦手动添加到 csproj,它将出现在 Visual Studio 中.目标路径将无法通过 UI 进行编辑.
为文件添加
条目将确保它仍然显示在 Visual Studio 的 UI 中.
Adding a <None>
entry for the file will ensure that it still shows up in Visual Studio's UI.
这篇关于Visual Studio:如何“复制到输出目录"不复制文件夹结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!