Visual Studio:如何“复制到输出目录”无需复制文件夹结构? [英] Visual Studio: How to "Copy to Output Directory" without copying the folder structure?

查看:212
本文介绍了Visual Studio:如何“复制到输出目录”无需复制文件夹结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目文件夹的\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,但它们位于\bin\Release gettinglib中,而不位于gettingbin butRelease中。

After build I am actually getting the dll copied but they are inside \bin\Release\lib and not in \bin\Release.

有没有办法复制dll文件写入\bin\Release(而不是\bin\Release\lib),而无需编写构建后脚本或求助于nant等?

Is there a way to copy dll files to \bin\Release (and not to \bin\Release\lib) without writing a post-build script or resorting to nant etc?

推荐答案

代替< Content> 使用< ContentWithTargetPath> 并指定目标这样的路径:

instead of <Content> use <ContentWithTargetPath> and specify target path, like this:

<ItemGroup>
  <ContentWithTargetPath Include="lib\some_file.dat">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    <TargetPath>some_file.dat</TargetPath>
  </ContentWithTargetPath>
</ItemGroup>

请注意,该条目可能无法从Visual Studio中看到(2012、2015、2017),但是一旦手动添加到csproj,它将出现在Visual Studio中。但是,目标路径将无法通过UI进行编辑。

Note that this entry may not be visible from Visual Studio (2012, 2015, 2017), but once manually added to the csproj, it will appear in Visual Studio. The target path will not be editable through the UI though.

这篇关于Visual Studio:如何“复制到输出目录”无需复制文件夹结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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