【问题标题】:Visual Studio copies dll files which are set to "Do not copy"Visual Studio 复制设置为“不复制”的 dll 文件
【发布时间】:2017-11-10 08:27:26
【问题描述】:

在我的 VS 2015 项目中,我有一个包含一些 .dll 文件的文件夹,我想根据平台使用构建后脚本将这些文件复制到输出目录。

为了防止 Visual Studio 触摸它们,我将属性“复制到输出目录”设置为“不复制”。我还将“构建操作”设置为“无”。

但是当我构建项目时,一些(但不是全部).dll 文件无论如何都会复制到输出目录。 我已经注释掉了我的后期构建脚本。

构建输出日志显示文件是在目标“_CopyFilesMarkedCopyLocal”期间复制的:

1>Target "_CopyFilesMarkedCopyLocal" in file "C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets" from project
 "C:\SS\C#\InSQLMDASDriver2014R2\InSQLMDASDriverMain\InSQLMDASDriverMain.csproj" (target "CopyFilesToOutputDirectory" depends on it): 
1>Task "Copy"

... Copying of referenced assembly project output: 
1>  Copying file from "C:\SS\C#\InSQLMDASDriver2014R2\InSQLMDASDriverGui\bin\x86\Debug\InSQLMDASDriverGui.dll" to "bin\x86\Debug\InSQLMDASDriverGui.dll".

... Unwanted copying of static files below:

1>  Copying file from "C:\SS\C#\InSQLMDASDriver2014R2\InSQLMDASDriverMain\x64 Libraries\Historian.CBE.dll" to "bin\x86\Debug\Historian.CBE.dll". 
1>  Copying file from "C:\SS\C#\InSQLMDASDriver2014R2\InSQLMDASDriverMain\x64 Libraries\Historian.DPAPI.dll" to "bin\x86\Debug\Historian.DPAPI.dll".   

...    

1>Done executing task "Copy". 
1>Done building target "_CopyFilesMarkedCopyLocal" in project "InSQLMDASDriverMain.csproj".

为什么会发生这种情况..?

【问题讨论】:

  • 这些dll是否通过csproj文件中的<Reference Include="..">项目引用?
  • dll 被引用并标记为“复制本地”,正如目标名称所暗示的那样。
  • 没有引用 dll,它们只是在项目的一个文件夹中。
  • @Ryebread,如果您已将属性“复制到输出目录”设置为“不复制”,并将“构建操作”设置为“无”,项目文件夹中的文件,Visual Studio 不会将其复制到输出文件夹。你应该仔细检查一下。如果此问题仍然存在,您介意与我们分享一个示例以重现此问题吗?谢谢。
  • @Leo-MSFT 我有一个解决方案,很高兴在 GitHub 上分享它的项目。

标签: c# .net visual-studio msbuild


【解决方案1】:

在我的 VS 2015 项目中,我有一个包含一些 .dll 文件的文件夹,我想根据平台使用构建后脚本将这些文件复制到输出目录。

是否要使用后期构建脚本将 dll 复制到输出目录而不是使用 Visual Studio?如果我理解正确,您应该在 References 的属性中为 dll 设置copy local=False。例如:

使用此设置,Visual Studio 将不会接触 dll。

【讨论】:

  • 不幸的是,它并不总是按照你说的去做。
猜你喜欢
  • 2011-06-24
  • 2014-08-04
  • 2013-03-19
  • 1970-01-01
  • 2022-12-18
  • 1970-01-01
  • 1970-01-01
  • 2021-07-22
  • 1970-01-01
相关资源
最近更新 更多