Deploy project with xUnit reference as NuGet package
Asked Answered
N

2

7

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.

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.

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

enter image description here

Steps to reproduce:

  1. Create a Class Library

  2. Add a reference to the xUnit NuGet package

  3. Right click the project and click on pack

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

Actual Behevior: there is no such file.

Nawab answered 14/5, 2019 at 7:1 Comment(0)
F
1

Another option is to create Class Library project but don't add full xunit package, just: xunit.abstractions and xunit.assert this way VS won't detect it as unit test project but you can still put some common code.

enter image description here

Frazee answered 14/4, 2022 at 15:46 Comment(1)
@timnot90, it's a more appropriate answer if we talk about some library for tests, I suppose.Talesman
N
7

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>

After that, the .nupkg file is created expected.

Nawab answered 15/5, 2019 at 8:25 Comment(0)
F
1

Another option is to create Class Library project but don't add full xunit package, just: xunit.abstractions and xunit.assert this way VS won't detect it as unit test project but you can still put some common code.

enter image description here

Frazee answered 14/4, 2022 at 15:46 Comment(1)
@timnot90, it's a more appropriate answer if we talk about some library for tests, I suppose.Talesman

© 2022 - 2024 — McMap. All rights reserved.