声明preprocesor符号(如调试)全球范围内为整个项目

声明preprocesor符号(如调试)全球范围内为整个项目

问题描述:

我想这样的NUnit和VS测试之间切换:

I would like to switch between NUnit and VS Tests like this:

#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
  using NUnit.Framework;
  using TestClass = NUnit.Framework.TestFixtureAttribute;
  using TestMethod = NUnit.Framework.TestAttribute;
  using TestInitialize = NUnit.Framework.SetUpAttribute;
  using TestCleanup = NUnit.Framework.TearDownAttribute;
  using TestContext = System.String;
  using DeploymentItem = NUnit.Framework.DescriptionAttribute;
#endif



我的问题是,怎么可能我宣布NUNIT preprocesor符号在一个地方( App.config中左右,将是巨大的),到NUnit的和VSTests轻松之间切换?因为当我使用的#define NUNIT ,它只能为文件,它是写的。

My question is, how may I declare NUNIT preprocesor symbol at one place (App.config or so, would be great), to switch between NUnit and VSTests easily? Because when I use #define NUNIT, it works only for the file, where it is written.

使用项目属性对话框。你可以在那里定义全局符号:

Use the project properties dialog. You can define global symbols there:

在项目右键 - >属性 - >生成选项卡 ​​- >条件编译符号

Right click on the project -> Properties -> Build tab -> Conditional compilation symbols