How to save DLLs in a different folder when compiling in Visual Studio?

前端 未结 5 720
借酒劲吻你
借酒劲吻你 2020-12-01 06:30

Let\'s suppose I have a Window Forms / Console Application C# project with some external references and references to oth

相关标签:
5条回答
  • 2020-12-01 06:49

    Set Reference path in project peoperties.

    You can also specify where your compiled exe goes by specifying Output path in project peoperties.

    0 讨论(0)
  • 2020-12-01 06:51

    There are 2 parts of your question:

    How to configure solutions to build assemblies/EXE into folders of your choice - this is configured through properties of the project in VS (project properties -> build -> output path). Also value of check "copy local" property on each reference.

    How to load assemblies files from non-default locations (i.e. from your ...\Libraries folder) - you need to make changes to your app.config file to add this non-default paths to assembly search location..

    Link to Microsoft site no longer works, so summary from wayback machine: How to load an assembly at runtime that is located in a folder that is not the bin folder of the application:

    Method 1: Install the assembly in the global assembly cache (GAC). The GAC is a computer-wide code cache where the common language runtime is installed. The GAC stores assemblies that you specifically designate to be shared by several applications.

    Note You can only install strong-named assemblies in the GAC.

    Method 2: Use an application configuration (.config) file with the tags A .config file contains the following settings:

    • Settings that are specific to an application

    • Settings that the common language runtime reads, such as the assembly binding policy settings and the remoting objects settings

    • Settings that the application reads

    The <codeBase> tags specify where the common language runtime can find an assembly. The common language runtime applies the settings of the <codeBase> tags from the .config file. The settings of the <codeBase> tags determine the version and the location of the assembly.

    Method 3: Use the AssemblyResolve event The AssemblyResolve event fires whenever the common language runtime tries to bind to an assembly and fails. You can use the AddHandler method to add an event handler to the application that returns the correct assembly whenever the AssemblyResolve event fires.

    The AssemblyResolve event handler must return an [Assembly] object, and the common language runtime must bind to this object. Typically, you can use the Assembly.LoadFrom method to load the assembly and then to return the object.

    0 讨论(0)
  • 2020-12-01 06:52

    Correct answers were given earlier. I'll just mention that there is a nuget package for this called PrettyBin.

    Install it on your startup project. DLLs and XMLs will go to a lib folder and you'll have a working example of how it's done, if you won't to customize.

    0 讨论(0)
  • 2020-12-01 06:58

    You'll find best practices for organizing project references here: http://codebetter.com/patricksmacchia/2009/01/11/lessons-learned-from-the-nunit-code-base/

    Look under chapter "The VisualStudio Project Reference + Copy Local true option is evil!"

    0 讨论(0)
  • 2020-12-01 07:00

    Yes it is possible, you'd do it in your msbuild script. While I can't give you an exact answer, look here at this question on SO Copy all files and folders using msbuild

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