我需要将自定义build设置传递给单元测试。我知道我可以在代码中使用 System.EnvironmentVariable 。我想知道如何向 TFS 构建定义添加参数,并使其可作为代码中的 env 参数读取。它必须由我们的发布工程师在构建定义中指定。
最佳答案
听起来您想使用 preprocessor directive有条件地执行一些代码。
[TestMethod]
public void MyTestMethod ()
{
bool buildArgumentIsSet = false;
#if MY_BUILD_ARGUMENT
buildArgumentIsSet = true
#endif
Assert.IsFalse(
buildArgumentIsSet,
"The evil release engineer set the build argument.");
}
然后,您的发布工程师可以使用 /define 进行编译参数,例如
/define:MY_BUILD_ARGUMENT
关于.net - 如何将构建参数传递给我的 .NET 单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10601116/