I'm trying to create base packages for my project. I would like to import them as NuGet packages.
Everything is fine until runtime. Importing custom nuget packages is fine, references are fine (I guess) and Rider does not complain.
After running my code I get an error, that says something in the lines of: Can not find referenced package "PACKAGENAME" with version "1.0.0" and throws FileNotFoundException. So far I have come to the conclusion, that the problem is within the NuGet packages namespaces and I think I'm correct.
After comparing original code with compiled code, the namespaces do not match.
Original code:
namespace Base.Domain.Identity
{
public class BaseUser<TKey> : IdentityUser<TKey>, IDomainEntityId<TKey>
where TKey : IEquatable<TKey>
{
[MaxLength(64)] public string? PictureUrl { get; set; }
[NotMapped]
public string Name
{
get => UserName;
set => UserName = value;
}
}
}
Compiled code
#nullable enable
namespace Domain.Identity
{
public class BaseUser<TKey> : IdentityUser<TKey>, IDomainEntityId<TKey> where TKey : IEquatable<TKey>
{
[MaxLength(64)]
public string? PictureUrl { get; set; }
[NotMapped]
public string Name
{
get => this.UserName;
set => this.UserName = value;
}
}
}
As you can see, the namespaces do not match. So far I havent found a place where some script would state, that the namespace should be switched.
Also I have another 3 packages with the same root namespace
eg Base.SomeOtherPlace
The nuspec file looks like this:
<?xml version="1.0"?>
<package >
<metadata>
<id>Api-Base-Domain</id>
<version>1.0.0</version>
<authors>Hannes</authors>
<owners>Hannes</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Base libraries for asp-net api domain items</description>
<releaseNotes>Release.</releaseNotes>
<copyright>Copyright 2021</copyright>
<tags>MyTag1</tags>
<dependencies>
<dependency id="Api-Base-Contracts" version="1.0.0"/>
</dependencies>
</metadata>
</package>
Api-Base-Contracts is my Base.Contracts package. The weird thing is, that only Base.Contracts is compiled correctly. The .nuspec file for that project is pretty much the same as for Base.Domain, except for the dependencies, where it has none.
I have tried reloading both of the solutions (the base solution and the solution, where I use the NuGet packages) with deleting the obj and bin folders. I'm using dotnet commands for NuGet, since I'm on linux.
How can I keep the compiler from changing the namespaces?