Search code examples
dotnet-clinuspec

dotnet pack "The element <package> is unrecognized"


Im trying to create a NuGet package of a dotnet new template. I created a nuspec file to set the details of the package, and it sits adjacent to my contents foler, which contains everything I want packaged up:

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
    <!-- The identifier that must be unique within the hosting gallery -->
    <id>My.EpiserverCMS</id>

    <!-- The package version number that is used when resolving dependencies -->
    <version>1.0.0</version>

    <!-- Authors contain text that appears directly on the gallery -->
    <authors>Me</authors>

    <description></description>

    <!-- 
        Owners are typically nuget.org identities that allow gallery
        users to easily find other packages by the same owners.  
    -->
    <owners>me</owners>

     <!-- License and project URLs provide links for the gallery -->
    <licenseUrl></licenseUrl>
    <projectUrl></projectUrl>

    <!-- The icon is used in Visual Studio's package manager UI -->
    <iconUrl></iconUrl>

    <!-- 
        If true, this value prompts the user to accept the license when
        installing the package. 
    -->
    <requireLicenseAcceptance>false</requireLicenseAcceptance>

    <!-- Any details about this particular release -->
    <releaseNotes>First Release</releaseNotes>

    <!-- 
        The description can be used in package manager UI. Note that the
        nuget.org gallery uses information you add in the portal. 
    -->
    <description>dotnet new template for Episerver CMS</description>

    <!-- Copyright information -->
    <copyright>Copyright ©2018 Me</copyright>

    <!-- Tags appear in the gallery and can be used for tag searches -->
    <tags>web episerver cms</tags>

    <!-- Dependencies are automatically installed when the package is installed -->
    <dependencies>
    </dependencies>

    <packageTypes>
        <packageType name="Template" />
    </packageTypes>
</metadata>

<!-- A readme.txt to display when the package is installed -->
<files>
    <file src="README.md" target="" />
    <file src="**" exclude=".vs\*,packages\*,**\*.mdf,**\*.ldf,**\*.log"></file>
</files>
</package>

But when I run dotnet pack I get the error:

error MSB4068: The element <package> is unrecognized, or not supported in this context.

Which I really dont get. Isnt package supposed to be the root element in a .nuspec file?


Solution

  • dotnet pack doesn't support packing nuspec files. It only supports msbuild projects that contain a Pack target.

    You can create a csproj project and use the NuspecFile property or use nuget pack through a nuget.exe version from http://nuget.org/downloads or through a nuget executable provided by the mono framework on non-windows platforms.