Debug-only classes and resources in visual studio - is it possible?

后端 未结 4 1863
猫巷女王i
猫巷女王i 2021-01-03 02:56

Is it possible to add a class to a project in Visual Studio and have that class only built for the Debug configuration of the project? That is, it will not appear in the Rel

4条回答
  •  天命终不由人
    2021-01-03 03:34

    Classes are easy:

    #if DEBUG
    // Put your class here
    #endif
    

    Not sure about resources though... I suspect it's feasible by editing the project file by hand, but not in Visual Studio.

    I wouldn't do this for test purposes though - I'd encourage you to use a separate assembly for tests. Aside from anything else, that means you can test what you ship, by testing against the release build. If you need access to internal types/members, you can always use [InternalsVisibleTo] to grant internal access from your production assembly to your test assembly. Indeed, I suspect that's the most common use of the attribute :)

提交回复
热议问题