Home > OS >  Why is a Namespace not included in resulting nuget package after 'nuget pack' and includin
Why is a Namespace not included in resulting nuget package after 'nuget pack' and includin

Time:11-16

I have a .net 6.0 class library project that has class files in the root, but also contains a Models folder with public classes declared in the class library. I've tried using the *.nupkg file created via nuget pack at the *.csproj level and the one created when the build preference to generate a package on every build. The package is created fine as MyPackage.

When I include 'MyPackage' in another project, I have access to the root classes, but the namespace MyPackage.Models doesn't seem to be included even though it was part of the project. Additionally, the xml documentation file does not seem to be included because I see none of my comments included when calling any of the methods on classes at MyPackage root.

I'm new to using my own nuget packages so this might be a rookie mistake, but I'm not sure what I'm doing wrong here.

Any advice?

CodePudding user response:

I make a test to create a MyPackage package and can correctly reference the namespace MyPackage.Models, here is the project:

enter image description here

I add this code in Method1.cs:

namespace MyPackage.Models
{
    public class Method1
    {
        public int Add(int a,int b)
        {
            return a   b;
        }
    }
}

It works in the test:

enter image description here

Maybe you can provide some more information to help reproduce the problem.

CodePudding user response:

The problem was a nuget package caching issue. I had to close out my solutions, clear the cache, and even reboot my machine. When I did that, things worked as I expected.

Before I tried this, I created a new class library project and copied the files from the prior project to this one. When I made a nuget package for this new one, everything worked as intended. That confirmed for me that the issue was caching.

  • Related