How to include other files to the output directory in C# upon build?

前端 未结 2 654
一生所求
一生所求 2020-11-30 06:15

I have some library files needed for my application to work.
My application has a setup and deployment included.

I already know that in order for a library file

相关标签:
2条回答
  • 2020-11-30 06:49

    You can add files to your project and select their properties: "Build Action" as "Content" and "Copy to output directory" as "Copy Always" or Copy if Newer (the latter is preferable because otherwise the project rebuilds fully every time you build it).

    Then those files will be copied to your output folder.

    This is better than using a post build step because Visual Studio will know that the files are part of the project. (That affects things like ClickOnce applications which need to know what files to add to the clickonce data.)

    You will also be more easily able to see which files are in the project because they will be listed with the source code files rather than hidden in a post-build step. And also Source Control can be used with them more easily.

    Once you have added "Content" files to your project, you will be able to add them to a Visual Studio 2010 Setup and Deployment project as follows:

    Go into your Setup project and add to your "Application Folder" output the Project Output called "Content Files". If you right-click the Content Files after adding them you can select "outputs" and see what it's going to copy.

    Note that Setup and Deployment projects are NOT supported in Visual Studio 2012.

    0 讨论(0)
  • 2020-11-30 07:03

    You can use Visual Studio Post Build Event - Copy to Relative Directory Location. Which are basically scripts that are executed on build of specified project.

    So you can use it to copy binaries you need, before actually running your application.

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