删除发布版本的 NUnit 引用

发布于 2024-12-02 10:38:48 字数 185 浏览 0 评论 0原文

我有一个包含许多 NUnit 测试的项目。我很高兴这些测试包含在调试配置构建中,但我想删除发布配置对 nunit.framework 的依赖。有没有办法排除特定(发布)配置的 NUnit 引用和 nunit 测试对象?我正在使用 Sharp Develop,但我很好奇您将如何使用 Visual Studio 解决这个问题。

有什么线索吗?

I have a project with many NUnit tests. I am happy for these tests to be included in the Debug configuration build but I would like to remove the dependency on nunit.framework for the Release configuration. Is there a way of excluding the NUnit reference and the nunit test objects for a specific (Release) configuration? I am using Sharp Develop but I am curious how you would approach this problem with Visual Studio as well.

Any clues?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

随梦而飞# 2024-12-09 10:38:48

听起来您的测试与发布代码位于同一项目中。这不是一个好主意 - 将代码分成两个项目,一个包含测试,另一个包含生产代码。只有测试项目需要引用 NUnit。

这也意味着发布代码不会附带任何测试,并且浏览生产代码或测试代码会更容易。

It sounds like you've got your tests in the same project as your release code. That's not a great idea - split the code into two projects, one with the tests and one with the production code. Only the test project will need to refer to NUnit.

That also means that none of the tests will ship with the release code, and it's easier to browse just the production code or just the test code.

撕心裂肺的伤痛 2024-12-09 10:38:48

如果您更喜欢将我的单元测试作为您要测试的项目的一部分进行开发,则可以将以下条件添加到您的单元测试文件和项目文件中的 nunit 引用中。

Condition=" '$(Configuration)'=='Debug' "

当您处于调试模式时,这将仅包括 nunit 引用以及构建中的测试类。

所以你的项目文件可能有这样的内容:

<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" Condition=" '$(Configuration)'=='Debug' ">
  <HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
</Reference>

<Compile Include="UnitTests.cs" Condition=" '$(Configuration)'=='Debug' "/>

If you prefer to develop with my Unit Tests as a part of the project you're trying to test, you can add the following condition to both your unit test files and your nunit reference in the project file.

Condition=" '$(Configuration)'=='Debug' "

That will only include the nunit reference as well as your test classes in the build when you're in debug mode.

So your project file might have something like this:

<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" Condition=" '$(Configuration)'=='Debug' ">
  <HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
</Reference>

<Compile Include="UnitTests.cs" Condition=" '$(Configuration)'=='Debug' "/>
眼趣 2024-12-09 10:38:48

将单元测试移至不同的程序集 - 即 YourProject.UnitTests

这不会构成部署包的一部分,并且无需在主应用程序中包含 nUnit 引用。

Move your unit tests to a different assembly - i.e. YourProject.UnitTests

This won't form part of your deployment package, and there will be no need to include the nUnit reference in your main application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文