使用 xUnit 引用将项目部署为 NuGet 包 [英] Deploy project with xUnit reference as NuGet package

查看:47
本文介绍了使用 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:

重现步骤:

  1. 创建类库

  1. 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.

推荐答案

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

According to https://github.com/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 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆