VS2008:具有定义的多个构建配置无法按预期工作

发布于 2024-10-02 20:56:36 字数 640 浏览 1 评论 0原文

我有一个基础库需要维护多个版本。每当我需要使用另一个版本时,我都会切换 SVN。

我的测试应用程序解决方案没有多个版本,因此我认为对于不同的版本,我可以执行多个解决方案/项目配置,为该版本定义符号,以便能够在我的测试中具有特定于版本的代码。

目前,我在测试应用程序解决方案中有以下构建配置:调试、发布、DebugV10、ReleaseV10、DebugV15、ReleaseV15。在 *V10 和 *V15 配置中,我为具有特定于版本的测试代码的两个项目创建并选择了相应的 *V10 和 *V15 PROJECT 配置(并非所有项目,大多数项目在解决方案 -Vx 中运行正常的调试/发布配置)配置)。

在这些项目配置中,我输入了相应的条件编译符号(VERSION10 和 VERSION15)。

现在,在我的项目代码中,我会这样

#if VERSION10
  // do v1.0 stuff
#elif VERSION15
  // do v1.5 stuff
#else
  // do trunk stuff
#endif

,但显然 VS 无法识别这些符号。即使简单的 #if DEBUG 也不再起作用,但在所有 Debug* 项目配置中都会检查定义 DEBUG 常量。

这是众所周知的事情吗?我能做什么呢?

I have a base library to maintain in multiple versions. I do a SVN switch whenever I need to work on another version.

I don't have multiple versions of my test application solution, so I thought that for different versions I could do multiple solution / project configurations that define symbols for the version to be able to have version-specific code in my test.

Currently I have the following build configurations in the test application solution: Debug, Release, DebugV10, ReleaseV10, DebugV15, ReleaseV15. In the *V10 and *V15 configs, I created and selected corresponding *V10 and *V15 PROJECT configurations for the two projects that have version-specific test code (not for all projects, most run normal Debug / Release configuration in the solution -Vx configuration).

In those project configurations I entered the corresponding conditional compilation symbols (VERSION10 and VERSION15).

Now in my code in the project I go like

#if VERSION10
  // do v1.0 stuff
#elif VERSION15
  // do v1.5 stuff
#else
  // do trunk stuff
#endif

But apparently VS doesn't recognize the symbols. Even a simple #if DEBUG does not work anymore, allthoug define DERBUG constant is checked in all Debug* project configurations.

Is this a known thing? What can I do about it?

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

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

发布评论

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

评论(2

长亭外,古道边 2024-10-09 20:56:36

你所描述的概念听起来不错。

也就是说,代码使用:

#if VERSION10 ... #endif

并且项目配置定义了 VERSION10

并设置了一个解决方案配置,该配置设置为使用上述项目配置。

只要这些都设置正确,我希望它能够工作。

事实上,你说即使 #if DEBUG 也没有按预期工作,这表明某些东西已经严重损坏。

我建议您尝试最简单的情况,以确保您了解如何设置它:创建一个新的最小“hello world”应用程序,该应用程序只有简单的代码,允许您区分版本:

#if VERSION1
  Console.WriteLine("Hello from version 1");
#else
  Console.WriteLine("Hello from version 2");
#endif

然后创建项目配置(“调试版本 1”、“调试版本 2”)并查看是否可以设置它们(一个定义了 VERSION1,一个没有定义)以在构建时获得两个输出。

然后添加使用上述项目配置的解决方案配置,并构建它们以检查它们在执行时是否打印正确的内容。

完成此操作后,您应该拥有一个可以应用到更复杂的项目中的工作系统(了解这些元素如何相互关联)。为了应用它们,我建议删除大部分项目/解决方案配置,然后从头开始重建它们,因为您确定自己知道该怎么做 - 通常从第一原则重建这些东西比尝试调整现有的“损坏的”要好。 ' 设置恢复正​​常。

The concept that you describe sounds fine.

That is, the code uses:

#if VERSION10 ... #endif

and the Project configuration defines VERSION10

and a Solution configuration is set up that is set to use the above Project configuration.

As long as these are all set up correctly, I'd expect it to work.

The fact that you say even #if DEBUG isn't working as expected suggests that something is very broken.

I'd suggest you try the simplest possible case, to ensure you undersatand how to set it up: Create a new minimal "hello world" application that just has simple code that allows you to tell apart the versions:

#if VERSION1
  Console.WriteLine("Hello from version 1");
#else
  Console.WriteLine("Hello from version 2");
#endif

Then create project configurations ("Debug Version 1", "Debug version 2") and see if you can set them up (one with VERSION1 defined, one without) to get the two outputs when built.

Then add Solution configurations that use the above Project configurations, and build them to check that they print the right things when executed.

Once you've done this you should have a working system (an understanding of how these elements relate to each other) that you can apply back to your more complex project. To apply them back, I suggest deleting most of the project/solution configurations and then rebuilding them from scratch now that you are sure you know what to do - often rebuilding these things from first principles works out better than trying to tweak an existing 'broken' setup back into life.

往日情怀 2024-10-09 20:56:36

C# 中的条件编译与 C 和 C++ 不同。有关 ConditionalAttribute< 的信息,请参阅此处 /代码> 类。

例如:

doDebugOutput();    // unconditionally call the optional code

Conditional["DEBUG"]
void DoDebugOutput()
{
  // do expensive debug-only output here
}

Conditional compilation in C# is different from C and C++. See here for info on the ConditionalAttribute class.

For example:

doDebugOutput();    // unconditionally call the optional code

Conditional["DEBUG"]
void DoDebugOutput()
{
  // do expensive debug-only output here
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文