How to save DLLs in a different folder when compil

2019-01-11 01:06发布

问题:

Let's suppose I have a Window Forms / Console Application C# project with some external references and references to other class library projects in the same solution too.

When I build the Window Form project, I want the referenced libraries be stored in a different location (eg: bin\Release\Libraries), and not in the same folder as the .exe.

Is it possible to do?

回答1:

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 ( http://support.microsoft.com/kb/837908 ).



回答2:

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.



回答3:

Set Reference path in project peoperties.

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



回答4:

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!"



回答5:

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