Search code examples
c#nuget.net-6.0

Creating a Nuget Package with Nuget Pack Says to Add a dependency group for net6.0 to the nuspec and Dots Required?


When creating a nuget package from a c# .net 6 class library with nuget.exe, I first run "nuget spec" to generate a nuspec file. Then when attempting to create a nuget package .nupkg by running "nuget pack" the output says:

"Some target frameworks declared in the dependencies group of the nuspec and the lib/ref folder do not have exact matches in the other location. Consult the list of actions below: Add a dependency group for net6.0 to the nuspec"

The following packaged file folder(s) require(s) dots in the framework version: lib/net60/myLibrary.dll

This is a clean .net 6 class library, and nuget.exe is version 6.0.

Why does it think I have anything in the dependencies group of the nuspec and lib/ref folder not matching the "other location?" I don't even have a dependencies group in the nuspec.

I seem to have placed dots in the target framework stated in my csproj, why is it complaining that my framework specifier is missing dots?

My csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <PackageId>myLibrary</PackageId>
    <Author>me</Author>
    <Company>myCompany</Company>
    <Description>Library defining common objects</Description>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>

My nuspec:

<?xml version="1.0" encoding="utf-8"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <license type="expression">MIT</license>
    <!-- <icon>icon.png</icon> -->
    <projectUrl>http://project_url_here_or_delete_this_line/</projectUrl>
    <description>$description$</description>
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>$copyright$</copyright>
    <tags>Tag1 Tag2</tags>
  </metadata>
</package>

Solution

  • I was dumb - but here's what I fixed in case anyone made the same mistake I made.

    1.) Dotnet Pack will output a nupkg into bin, and a nuspec into obj. I didn't realize there was a difference, and have tried before to use the nuspec, but the nupkg in bin (not nuspec in obj) is what installs correctly.

    2.) I was trying to use nuget.exe's "nuget pack" command instead of the "dotnet pack" command when I kept getting "error: There are no versions available for the package 'myLibrary'." when adding the output to another project.

    3.) I had thought maybe "dotnet pack" was not working, as I saw it outputting a nuspec file instead of a nupkg. This was a misunderstanding, as it outputs both. The nupkg is found in the bin folder, the nuspec shows up in obj.

    4.) I made a mistake in my csproj property group by not including a "version" tag like this:

    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <PackageId>myLibrary</PackageId>
        <Version>1.0.0</Version>
        <Author>me</Author>
        <Company>myCompany</Company>
        <Description>Library defining common objects</Description>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
      </PropertyGroup>
    
    </Project>
    

    Thought about deleting this sad question, but will leave it in case anyone else makes the same string of incorrect assumptions and errors that I made.