Visual Studio:如果编译为dll,则排除类 [英] Visual Studio: Exclude a class if compiling as a dll
问题描述
.exe
,以便我可以轻松地测试其中的类。一个类包含一个 Main()
方法,当我将它编译为 .dll
文件时,这是无用的。当我将其编译为类库时,我想自动将该类从项目中排除。看来我一定是第一个遇到这个问题的人之一,因为全能的谷歌似乎没有回答我的问题:我该怎么做?我会认真考虑单元测试,这样做是不经意的。即使单元测试未正确执行,您只是将其用作中间调试器。我甚至会说一个单元测试项目作为调试代码的控制台应用程序,在获取访问方面将使您的生活变得更加容易,并且将来如果您希望实现某种形式的单元测试你可以。
[TestMethod]
public class YourClassNameTests
{
public T YourObject ;
[TestInitialize()]
public void Initializer()
{
YourObject = new T();
}
[TestMethod()]
public void YourMethodTest()
{
//排列
YourObject.ReliantProperty = 1;
// Act
var objResult = YourObject.YourMethod();
// Assert
Assert.IsTrue(objResult == 1);
}
}
I have a DLL project that I often compile as a .exe
so that I can easily test the classes in it. One class contains a Main()
method, which is useless when I compile it as a .dll
file. I would like to automatically exclude this class from the project whenever I am compiling it as a class library. It seems like I must be one of the first people to run into this problem, as the almighty Google doesn't seem to have an answer for my question: How do I do this?
I would seriously consider unit testing as apose to doing this constantly. Even if unit testing isn't implemented properly and you just use it as an intermediate debugger. I would even go as far as saying do a unit test project as apose to a console application for debugging your code, in terms of getting access it will make your life a lot easier and in the future if you wish to implement some form of unit testing you can.
[TestMethod]
public class YourClassNameTests
{
public T YourObject;
[TestInitialize()]
public void Initializer()
{
YourObject = new T();
}
[TestMethod()]
public void YourMethodTest()
{
//Arrange
YourObject.ReliantProperty = 1;
//Act
var objResult = YourObject.YourMethod();
//Assert
Assert.IsTrue(objResult == 1);
}
}
这篇关于Visual Studio:如果编译为dll,则排除类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!