1

By setting "Copy Local" to true in the VS2017 Properties window for a .net reference, you can tell the build process to copy a referenced assembly to your project's output directory. But what if you want the assembly to be copied to a specific subdirectory of the output directory (which will be added to the list of search paths via an app.config setting)? Is there any way to do this, short of using a batch file in a post-build step?

dlf
  • 9,045
  • 4
  • 32
  • 58
  • You could try the following:
    https://stackoverflow.com/questions/18743907/visual-studio-how-to-copy-to-output-directory-without-copying-the-folder-stru
    – hce May 17 '18 at 18:30
  • @hce I'm actually exploring that option right now. It's better than nothing, but it means I have to add the reference AND all of its references as content, and keep this list up-to-date as things change. With the standard "copy local" option, the build process is smart enough to collect and copy the transitive references on its own. – dlf May 17 '18 at 18:33

1 Answers1

1

The only way I've come up with to make this work is:

  1. Set "Copy local" to false for the reference(s) in question
  2. Separately add the referenced assembly file(s) to the project as content (see below)
  3. The big downside: if any referenced assembly has references of its own, they (and their own references, etc.) will need to be added as content in the same way. And if any of these assemblies' reference lists change, you'll need to update your project.

In the .vcxproj:

<ItemGroup> <!-- you probably already have an ItemGroup you can use -->
   <Content Include='subdir\referenced.dll'>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
   </Content>
</ItemGroup>

Note that if you need the directory structure in the output to be different than it is in the source location, you'll need to tweak things a bit as described in this answer:

<ContentWithTargetPath Include="source_dir\referenced.dll">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  <TargetPath>dest_dir\referenced.dll</TargetPath>
</ContentWithTargetPath>
dlf
  • 9,045
  • 4
  • 32
  • 58