我有一个包含一些类的库,我在几个单元测试项目中需要这些类.该库应作为 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 包
发布评论