如何使 Visual Studio 2010 项目依赖项成为特定于配置的依赖项?

发布于 2024-10-01 09:24:34 字数 307 浏览 1 评论 0原文

这个可能有点奇怪。我在 Visual Studio 2010 中有一个包含三个 C++ 项目的解决方案。两个库和一个可执行应用程序。两种配置。在一种配置中,我需要可执行应用程序对一个库具有项目依赖性,在另一种配置中,我需要可执行应用程序对其他库具有项目依赖性。

具体来说,第一个库中有一个 Direct3D9 实现,第二个库中有一个 OpenGL 实现。第三个项目是一个测试工具,两者使用相同的接口,唯一的区别在于它链接到哪个库。测试工具项目中存在两种配置,每种配置对应一种实现。我无法根据活动配置将测试工具项目设置为单独依赖于每个实现库。

如何使项目依赖项配置特定?

This one may be a bit strange. I have a solution in Visual Studio 2010 with three C++ projects. Two libraries and one executable application. Two configurations. In one configuration, I need the executable application to have a project dependency on one library, in the other configuration I need the executable application to have a project dependency on other library.

With specifics, there's a Direct3D9 implementation in the first library and an OpenGL implementation in the second library. The third project is a test harness that uses the same interface for both, the only difference is which library it links to. Two configurations exist in the test harness project, one for each implementation. I can not set the test harness project to depend on each implementation library individually based on active configuration.

How can I make the project dependencies configuration-specific?

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

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

发布评论

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

评论(3

贩梦商人 2024-10-08 09:24:34

C++项目格式是msbuild吗?如果是这样,您应该能够对引用设置一个条件。引用这两个项目,然后编辑项目文件并为每个项目添加一个条件。这就是它在 C# 项目中的工作方式,不确定 C++ 是否相同:

<ProjectReference Include="..\DirectXLib\DirectXLib.csproj" Condition=" '$(Configuration)' == 'DirectX' ">
  <Project>{99999-9999-9999-9999-99999999999}</Project>
  <Name>DirectXLib</Name>
</ProjectReference>
<ProjectReference Include="..\OpenGLLib\OpenGLLib.csproj" Condition=" '$(Configuration)' == 'OpenGL' ">
  <Project>{99999-9999-9999-9999-99999999999}</Project>
  <Name>OpenGLLib</Name>
</ProjectReference>

Is the C++ project format msbuild? If so, you should just be able to put a condition on the reference. Reference both projects and then edit the project file and add a condition on each one. This is how it would work in a C# project, not sure if c++ is the same:

<ProjectReference Include="..\DirectXLib\DirectXLib.csproj" Condition=" '$(Configuration)' == 'DirectX' ">
  <Project>{99999-9999-9999-9999-99999999999}</Project>
  <Name>DirectXLib</Name>
</ProjectReference>
<ProjectReference Include="..\OpenGLLib\OpenGLLib.csproj" Condition=" '$(Configuration)' == 'OpenGL' ">
  <Project>{99999-9999-9999-9999-99999999999}</Project>
  <Name>OpenGLLib</Name>
</ProjectReference>
执笏见 2024-10-08 09:24:34

我认为配置管理器的目的正是为了满足您的要求,不是吗?

在解决方案级别,您可以指定要构建的配置,对于每个配置,您可以指定要构建的项目以及构建的顺序。在每个项目的设置中,您可以指定要包含哪些库以及您想要执行的一大堆其他操作。

I think the purpose of configuration manager is just for what you are asking, doesn't it?

At the solution level you specify what configurations you want to build and for each configuration you can specify what projects you want to build and in what order. And in each project's settings, you can specify what libraries to include and a whole bunch of other things you want to do.

心舞飞扬 2024-10-08 09:24:34

IDE 中似乎有效的一个技巧:

  • 让两个库也有一个配置 NOT_USED;

  • 将 NOT_USED 配置中的库的配置类型(在公共属性:常规:项目默认值中)设置为应用程序 (.exe)。

这将使 VS 认为他没有这些项目的库,因此不会提供链接错误。

One trick which seems to work from the IDE:

  • Let both libraries also have a configuration NOT_USED;

  • set the Configuration Type (in Common Properties: General : Project Defaults) to Application (.exe) for the libraries in the NOT_USED configuration.

This will VS think he does not have a lib as result from these projects, and thus not provide a link error.

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