I am trying to build a NuGet package from a Framework 4.8 .csproj file for a library. The project compiles fine. I have some unit tests that run fine. I run the "nuget pack" command and get the error in the title.
I have an interface defined in a .NET Standard 2.0 project. I need to implement this interface for both Core and Framework projects. There are platform-specific dependencies in the implementation. The core package is easily generated because I have a GeneratePackageOnBuild element with a True value in the project file.
The Framework package would be built with a command line. Nuget v6.0.0.280, MSBuild v17.1.0.7609
& nuget pack -includeReferencedProjects -Symbols -SymbolPackageFormat snupkg -Properties Configuration=Release
I have removed the System.Memory package from the Framework project. System.Memory is not in the project with the interface. I removed the System.Buffers package after reading about another person who had trouble with System.Memory. I find no explicit reference to System.Memory in either the Standard 2.0 project or the Framework 4.8 project. I have erased the bin and obj files and cleaned the solution, and restarted the compiler, and booted the machine.
What is trying to reference System.Memory 4.0.1.1, and how do I make it stop?
CodePudding user response:
Try these steps:
- Clean solution
- Remove the
bin
andobj
folders
If you are using git
you can remove left-over files using git clean -ffxd
. Be careful, this will remove all untracked files.
CodePudding user response:
The -includeReferencedProjects flag in the nuget pack command is not doing the expected thing. Somewhere in the dependency tree there is something that wants System.Memory 4.0.1.1. Rather than track the dependency down, run the pack without -includeReferencedPackages.
This means that the reference project that is needed, the interface declaration, now won't be included in the NuGet package, so either make a target in the .csproj of write a .nuspec file that includes the reference. I went the .nuspec route.
I ran
nuget spec
to get the file that nugt tried to use.
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>...</authors>
<owners>...</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
<description>...</description>
<releaseNotes>...</releaseNotes>
<copyright>$copyright$</copyright>
</metadata>
</package>
Then added an element inside the under the to gather the dependency that I do want into the delivered library:
<files>
<file src="bin\Release\InterfaceFile.*" target="lib\net48" />
</files>
Now the nuget pack doesn't trip on a dependency, but the dependency I want is packaged. I can put this in my NuGet source, my applications can consume it and use the interface and the implementation in a Framework app.