Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 251
Ethan Schofer Avatar asked Jun 21 '18 21:06

Ethan Schofer


2 Answers

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.

like image 143
Martin Ullrich Avatar answered Sep 21 '22 11:09

Martin Ullrich


dotnet pack does support nuspec files. However, you have to pass them a couple specific configuration flags and add a dependency to your project. See the documentation here: https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#packing-using-a-nuspec

like image 22
Spencer C Avatar answered Sep 19 '22 11:09

Spencer C