Visual Studio: How to “Copy to Output Directory” without copying the folder structure?

后端 未结 8 963
礼貌的吻别
礼貌的吻别 2020-12-04 08:43

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

相关标签:
8条回答
  • 2020-12-04 09:32

    I had the same problem with Visual Studio 2010 / C# Project.

    For assemblies (i. e. having the .NET interface) use folder "References" under your project in the Solution Explorer. Right click it, choose "Add existing item" and locate your .dll assembly.

    Common .dll files can be placed in a subfolder (as "\lib" was mentioned above) and in the properties select:

    • Build Action = "HelpFiles"
    • Copy To OutputDirectory = "If Newer"

    This worked for me exactly as desired - during build, the .DLLs are copied to the output directory without the "\lib" subfolder.

    0 讨论(0)
  • 2020-12-04 09:38

    If your main intent is to include DLLs without cluttering up the project root directory, another solution is to move the DLLs to a separate Shared Project and add this as a reference in the original project.

    (Note that this post doesn't directly answer this question as it doesn't preserve the folder and project structure, but I found this approach useful because I was able to restructure my project in my case and because I wanted to avoid some of the downsides of the other approaches here.)

    Steps

    • Right-click your Solution -> Add -> New Project -> Shared Project
    • Add the DLLs to this project (in the root directory of this project, not in a "lib" sub-folder)
    • (Check DLL file properties are set correctly, e.g. Build Action: Content and Copy to Output Directory: Copy Always)
    • Right-click the original project's References -> Add Reference -> Shared Projects
    • Select the shared project you created earlier

    The setup looks like this:

    0 讨论(0)
提交回复
热议问题