开发者

Place all output dlls in common directory from Visual Studio

开发者 https://www.devze.com 2023-01-08 17:50 出处:网络
I have a couple of different solutions, in which some projects may depend on output from projects in other solutions. To manage this, I\'ve been copying dll files from the /bin/ folder in each project

I have a couple of different solutions, in which some projects may depend on output from projects in other solutions. To manage this, I've been copying dll files from the /bin/ folder in each project to a shared library location after build, and then copy/reference them from there to the dependent project.

However, as the library solution gets larger, this tends to become unmaintainable. Too much of my time is being spent traversing solution directories in Windows Explorer looking for /bin/ folders, and trying to figure out which one, or which ones, of the dll files from each one I need.

Is there any way to give Visual Studio a hint that I want all projects in a solution t开发者_JS百科o have the same output directory? For example, a /bin/ folder directly under the solution folder, where all projects put their output.

If possible, I'd like to achieve this without hard-coded post-build events that copy the files, since that will fail if a project output changes file name, or adds another file. I'd rather like to change the location of the actual output directory - the location of $(OutDir), if you will.


I know you said you don't want to use post build events, but your reason as to why not intrigued me. It sounds like you might be hard coding the name of the .dll in your post build event. That can easily be avoided.

xcopy "$(TargetDir)*" "c:\common\" /Y

The * would just cause everything in your bin/Debug/ folder to get copied to your common folder. You could also just copy dlls if you want. Or, if you use $(TargetPath), you'll copy just the 1 dll that is the result of the project, and not any other related dependencies.

UPDATE

The way we do it is each projects entire bin folder is copied to a subfolder. Suppose you have 2 projects, WebUtil and HtmlParser, where WebUtil depends on HtmlParser. For both projects, use xcopy "$(TargetDir)*" "c:\common\$(ProjectName)" /Y. This will create c:\common\WebUtil\ and c:\common\HtmlParser. In WebUtil, add a reference to c:\common\HtmlParser\HtmlParser.dll. There will now be 2 copies of HtmlParser.dll in c:\common.

c:\common\HtmlParser\HtmlParser.dll // the most recent build. c:\common\WebUtil\HtmlParser // what was the most recent build when WebUtil was built

This has all kinds of advantages. If you change the API of HtmlParser, WebUtil will continue to work, since it will have the older HtmlParser.dll until you try to rebuild WebUtil (at which point you'll get build errors because of the changed API).

Now, if a 3rd project got in the mix that depended on WebUtil, and you're using some part of WebUtil that exposes classes in HtmlParser, then you'll need to add a reference to both projects from your new project. When you add a reference to HtmlParser.dll, use the one in c:\common\WebUtil. You do this because you're only including it as a necessary requirement of WebUtil. Now you'll always have the version of HtmlParser.dll that matches your current version of WebUtil.dll.

I hope that makes sense. It can definitely be a tricky thing to manage. Just wait till you have to start pulling down all your dependencies using svn:externals =P


You can set the output directory in each project properties.

Right click on the project, select Properties

For C#, it is one of the Build property page, under Output, Output directory.

In VB.Net projects, it is on the Compile tab, in the textbox at the top.

0

精彩评论

暂无评论...
验证码 换一张
取 消