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

后端 未结 4 1839
猫巷女王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:46

    You can use #DEBUG (see Jon's answer) for classes.

    For resources you can edit the MSBuild script file to include parts of the project conditionally based on the build mode selected.

    The .csproj file is a XML MSBuild script, if you open it up in a text editor, you should find inside all of the parts of your project. If you can locate the parts you want to exclude from certain builds you can mark them with the Condition property. For example, to make a ItemGroup only be built for the Debug configuration you would do this:

    You should be able to take a look though this and find the resources you want to exclude and add a similar Condition property to them, or to their parent group.

    However, I would recommend that you use a separate assembly for test stuff and don't let it get mixed up with you main assemblies.

提交回复
热议问题