dotnet包“无法识别元素<package>”

时间:2018-06-21 21:08:24

标签: dotnet-cli nuspec

我正在尝试创建一个 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文件中的根元素吗?

2 个答案:

答案 0 :(得分:5)

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

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

答案 1 :(得分:0)

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