设置使用多个外部开源项目的 VS 项目的最佳方法是什么?

发布于 2024-08-17 20:15:28 字数 444 浏览 6 评论 0原文

我有一个大型项目,我正在用更好的开源替代方案替换其中的两个部分。开源库相当大,但它们很稳定且不变,因此直接将源代码包含在我的 VS 项目中对我来说似乎毫无意义 - 它需要加载更多内容,需要编译更多内容等。我宁愿只单独构建 2 个开源项目,固定版本,然后从主项目中引用它们。

但这给我带来了一些问题。

  1. 我想要库的 DEBUG 和 RELEASE 版本 - VS 无法根据这些定义在引用之间切换。

  2. 如果我想单步执行其他项目中的代码,调试会更困难 - 这并不像单步执行代码那么简单 - 或者是吗?

  3. 其他一些我还没有想到的事情...

所以,当我思考想法时,我想我会问你们如何设置它。

主项目和2个开源项目都位于不同的SVN存储库中。 开源项目我不会每天都得到新的主干,而是修复一个版本。

谢谢

I have a large project which I am replacing 2 parts of with better open source alternatives. The open source libraries are pretty big but they are stable and unchanging so including the source in my VS project directly seems pointless to me - its more to load, more to compile etc. I would much rather just build the 2 open source projects alone, at a fixed version and then reference them from the main project.

But this gives me a couple of problems.

  1. I will want DEBUG and RELEASE versions of the libraries - VS has no way to switch between references based on those defines.

  2. Debugging is harder if I want to step into the code in the other projects - its not as simple as just stepping through the code - or is it?

  3. Something else I've not yet thought of...

So while I play around with ideas I thought I would ask how you guys would set it up.

The main project and the 2 open source projects are all in different SVN repositories.
The Open source projects I will not be getting the new trunk every day, but fixing on a release.

Thanks

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

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

发布评论

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

评论(1

披肩女神 2024-08-24 20:15:28

1) 如果您通过编辑 .csproj 文件手动执行此操作,则可以在不同构建配置的引用之间切换。

csproj 文件是一个 XML 格式的 MSBuild 脚本。如果您向下浏览,您应该会找到一个包含一堆的元素元素。您可以向这些引用元素之一添加一个条件,如下所示:

<Reference Condition=" '$(Configuration)' == 'Debug' " Include="System.Drawing" />

Include 属性可以包含程序集的完整强名称,该名称对于二进制文件的调试和发布版本不一定有所不同。在这种情况下,您可以添加元素以包含 .dll 的路径。

<Reference Include="assembly strong name">
  <HintPath>c:\LibraryStuff\Debug\Library.dll</HintPath>
</Reference>

您的提示路径也可以是相对的:

<HintPath>..\..\LibraryStuff\Debug\Library.dll</HintPath>

[免责声明:尽管我从未真正使用参考文献完成过此操作,但我不能保证不会出现问题。我很快对其进行了测试,它似乎工作正常,尽管无论您选择哪种构建配置,Visual Studio 都会显示这两个引用(尽管它只构建匹配配置类型的引用)。如果第二个节点具有匹配的名称,它还会在第二个节点上放置一个警告图标,但编译似乎工作正常。]

如果确实遇到问题,您可以尝试仅使用两个不同 HintPath 节点的一个引用,并将条件放在提示上小路。


2) 如果您的 .pdbs 和源代码都位于正确的位置且可访问,您应该能够通过单步执行代码直接调试到库中,即使您只是引用 .dll 文件。

1) You can switch between references for different build configurations if you do it manually by editing the .csproj file.

The csproj file is an MSBuild script which is XML. If you browse down it you should find a <ItemGroup> element that contains a bunch of <Reference> elements. You can add a condition to one of these reference elements like this:

<Reference Condition=" '$(Configuration)' == 'Debug' " Include="System.Drawing" />

The Include attribute can contain the full strong name of the assembly, which may not necessarily be different for the debug and release builds of your binary. In which case, you can add a <HintPath> element to include the path to the .dll.

<Reference Include="assembly strong name">
  <HintPath>c:\LibraryStuff\Debug\Library.dll</HintPath>
</Reference>

Your hint path can also be relative:

<HintPath>..\..\LibraryStuff\Debug\Library.dll</HintPath>

[Disclaimer: I've never actually done this with references though, I can't guarantee there won't be issues. I quickly tested it out and it seems to work fine, although visual studio does display both the references no matter which build config you have selected (although it only builds the one for the matching config type). It also puts a warning icon on the second one if they have matching names, but the compile seems to work fine.]

If you do have problems, you could try just having one reference with two different HintPath nodes and putting the conditional on the hint path.


2) Provided you have the .pdbs and the source code all in the correct places and accessibly, you should just be able to debug straight through into the library by just stepping into the code even though you are only referencing the .dll file.

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