使用 xUnit 引用将项目部署为 NuGet 包

编程入门 行业动态 更新时间:2024-10-25 05:23:51
本文介绍了使用 xUnit 引用将项目部署为 NuGet 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个包含一些类的库,我在几个单元测试项目中需要这些类.该库应作为 NuGet 包部署在我的私有存储库中.我已经在那里部署了一些 NuGet 包,所以我知道我必须做什么.

I have a library that contains some classes, which I need in several Unit Test projects. The library should be deployed as a NuGet package in my private repository. I already deployed some NuGet packages there, so I know what I have to do.

但是:在这个库中,我需要一个对 xUnit 的引用.一旦我添加了这个引用,在执行 dotnet pack 时就不会再创建 .nupkg 文件了.

BUT: Inside of this library I need a reference to xUnit. And as soon as I add this reference, there is no more .nupkg file created when execute dotnet pack.

另一个有趣的效果是,一旦我添加了 xUnit,项目图标就会变成单元测试图标:

Another interesting effect is, that the project icon turns into a Unit Test icon as soon as I add xUnit:

重现步骤:

  • 创建类库

  • Create a Class Library

    添加对 xUnit NuGet 包的引用

    Add a reference to the xUnit NuGet package

    右键点击项目并点击打包

    Right click the project and click on pack

    预期行为:./bin/Debug 中应该有一个 .nupkg 文件

    Expected Behvior: there should be a .nupkg file in ./bin/Debug

    实际行为:没有这样的文件.

    Actual Behevior: there is no such file.

    推荐答案

    根据 github/dotnet/cli/issues/7539,有些项目在默认情况下似乎不可打包".您必须通过将以下几行添加到您的 .csproj 文件中来手动启用此功能:

    According to github/dotnet/cli/issues/7539, some projects seem to be "not packable" by default. You have to enable this manually by adding the following lines to your .csproj file:

    <PropertyGroup> <IsPackable>true</IsPackable> </PropertyGroup>

    之后,将创建 .nupkg 文件.

    After that, the .nupkg file is created expected.

  • 更多推荐

    使用 xUnit 引用将项目部署为 NuGet 包

    本文发布于:2023-11-16 21:04:16,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1607450.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:项目   xUnit   NuGet

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!