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

后端 未结 8 1001
礼貌的吻别
礼貌的吻别 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: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:

提交回复
热议问题