Search code examples
c#.netnugetazure-devopsnuspec

Importing simple custom NuGet package with error: Package does not support any target frameworks


I created a .NET framework class library targeting 4.6.1 .NET Framework. The project contains one .cs class and no external references to any libraries, DLLs, or NuGet packages. Here is the nuspec:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <metadata>
        <!-- Required elements-->
        <id>MyEventLogger.Core</id>
        <version>1.0.0</version>
        <description>Logs event log</description>
        <authors>Me</authors>
    </metadata>
    <files>
      <file src="MyEventLogger.Core\**\bin\Debug\*.dll" target="lib\net" />
      <file src="MyEventLogger.Core\**\bin\Debug\*.dll" target="lib\netstandard" />
    </files>
</package>

I am having trouble importing this from an ASP.NET Core application running .NET Framework 4.7.1.

The error I get is that the package does not support any frameworks:enter image description here

I am using Azure Devops Build pipeline to initiate the pack and push to a local feed. How should I reference this correctly so that an application on a newer version of .NET Framework can still use this library that is on an older version?

Thank you for any help! I can't find how to fix this error anywhere or good examples of targeting multiple .NET Frameworks.


Solution

  • I got it working when I was able to use the following file nodes:

    <files>
       <file src="**\MyEventLogger.Core.dll" target="lib\net461\MyEventLogger.Core.dll" />
    </files>
    

    What helped me figure this out was to install NuGet onto my machine as well as installing the NuGetPackageExplorer. You can create a package using the NuGetPackageExplorer and then exporting the .nuspec file. I copied that .nuspec file into my repository and then pointed my Azure DevOps build pipeline to the .nuspec file. This error disappears when I import the package into another project.