将所有输出 dll 放在 Visual Studio 的公共目录中

发布于 2024-09-10 22:01:55 字数 433 浏览 3 评论 0原文

我有几个不同的解决方案,其中某些项目可能依赖于其他解决方案中项目的输出。为了管理这个问题,我在构建后将 dll 文件从每个项目中的 /bin/ 文件夹复制到共享库位置,然后将它们从那里复制/引用到依赖项目。

然而,随着库解决方案变得越来越大,这往往变得难以维护。我的太多时间都花在了在 Windows 资源管理器中遍历解决方案目录寻找 /bin/ 文件夹,并试图找出我需要的每个 dll 文件中的哪一个或哪些。

有没有办法让 Visual Studio 提示我希望解决方案中的所有项目都具有相同的输出目录?例如,解决方案文件夹正下方的 /bin/ 文件夹,其中所有项目都放置其输出。

如果可能的话,我希望在没有复制文件的硬编码构建后事件的情况下实现此目的,因为如果项目输出更改文件名或添加另一个文件,则会失败。如果愿意的话,我宁愿更改实际输出目录的位置 - $(OutDir) 的位置。

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 to 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小…红帽 2024-09-17 22:01:55

我知道您说过您不想使用构建后事件,但您的原因没有引起我的兴趣。听起来您可能会在构建后事件中对 .dll 的名称进行硬编码。这很容易避免。

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

* 只会导致 bin/Debug/ 中的一切文件夹以复制到您的公用文件夹。如果需要,您也可以只复制 dll。或者,如果您使用 $(TargetPath),您将仅复制作为项目结果的 1 个 dll,而不复制任何其他相关依赖项。

更新

我们的做法是将每个项目的整个 bin 文件夹复制到一个文件夹中。假设您有 2 个项目,WebUtilHtmlParser,其中 WebUtil 依赖于 HtmlParser。对于这两个项目,请使用 xcopy "$(TargetDir)*" "c:\common\$(ProjectName)" /Y。这将创建 c:\common\WebUtil\ 和 c:\common\HtmlParser。在 WebUtil 中,添加对 c:\common\HtmlParser\HtmlParser.dll 的引用。现在 c:\common 中将有 2 个 HtmlParser.dll 副本。

c:\common\HtmlParser\HtmlParser.dll // 最新版本。
c:\common\WebUtil\HtmlParser // WebUtil 构建时最新的构建是什么

这具有各种优点。如果您更改 HtmlParser 的 API,WebUtil 将继续工作,因为它将具有较旧的 HtmlParser.dll,直到您尝试重建 WebUtil(此时您将因更改的 API 而收到构建错误)。

现在,如果第三个项目依赖于 WebUtil,并且您正在使用 WebUtil 的某些部分来公开 HtmlParser 中的类,那么您需要添加对 两个 项目的引用你的新项目。添加对 HtmlParser.dll 的引用时,请使用 c:\common\WebUtil 中的引用。您这样做是因为您只是将其作为 WebUtil 的必要要求。现在,您将始终拥有与当前 WebUtil.dll 版本相匹配的 HtmlParser.dll 版本。

我希望这是有道理的。这绝对是一件很难管理的事情。只需等到您必须开始使用 svn:externals =P 拉取所有依赖项

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

你没皮卡萌 2024-09-17 22:01:55

您可以在每个项目属性中设置输出目录。

右键单击项目,选择Properties

对于C#,它是Build属性页之一,位于Output下,Output目录< /代码>。

在 VB.Net 项目中,它位于“编译”选项卡顶部的文本框中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文