网络包 "The element <package> is unrecognized"

dotnet pack "The element <package> is unrecognized"

我正在尝试创建 dotnet new 模板的 NuGet 包。我创建了一个 nuspec 文件来设置包的详细信息,它位于我的内容文件夹旁边,其中包含我想要打包的所有内容:

<?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>

但是当我 运行 dotnet pack 我得到错误:

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

我真的不明白。包不应该是 .nuspec 文件中的根元素吗?

dotnet pack 不支持打包 nuspec 文件。它仅支持包含 Pack 目标的 msbuild 项目。

您可以创建一个 csproj 项目并使用 NuspecFile 属性 或使用 nuget pack 通过 http://nuget.org/downloads 的 nuget.exe 版本或通过 nuget 由非 windows 平台上的单声道框架提供的可执行文件。

dotnet pack 支持 nuspec 文件。但是,您必须向它们传递几个特定的​​配置标志并向您的项目添加依赖项。请参阅此处的文档:https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#packing-using-a-nuspec