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?
Asked
Active
Viewed 2,242 times
1
1 Answers
1
The only way I've come up with to make this work is:
- Set "Copy local" to false for the reference(s) in question
- Separately add the referenced assembly file(s) to the project as content (see below)
- 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
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