【问题标题】:Can't import classes from custom NuGet package无法从自定义 NuGet 包导入类
【发布时间】:2019-07-08 20:38:15
【问题描述】:

我有一个带有 1 个接口和 1 个类的 .NET Standard 库:

public interface ITestService
{
    void Test(string test);
}

public class TestService : ITestService
{
    public void Test(string test)
    {
        Console.WriteLine("Got this string: " + test);
    }
}

我使用 nuspec 文件将使用 Azure Pipelines(dotnet pack 和 dotnet push)的库发布到 Azure Artifacts:

<?xml version="1.0"?>
<package>
  <metadata>
    <id>Service.Client</id>
    <version>5.0.2</version>
    <title>Service Client</title>
    <authors>auth</authors>
    <owners>owner</owners>
    <projectUrl>https://dev.azure.com/yyy/</projectUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>My test nuget description</description>
    <releaseNotes>Test release</releaseNotes>
    <copyright>Copyright 2019</copyright>
    <tags>latest 5.0.2</tags>
  </metadata>
</package>

当将此库(成功)导入我的其他项目时,我无法通过 VS2019 看到 ITestService/TestService,即使我可以在 nupkg 中看到它们!

有人可以帮我导入我的库吗?

【问题讨论】:

  • 您是否每次发布到您的私有 NuGet 源时都增加包版本?这听起来像是一个常见的场景,您在没有新接口和类的情况下发布了包,在本地机器上使用它,然后在不更改版本的情况下更新了包。现在您的计算机认为它具有该软件包,但不知道它与您的 nuget 提要中的版本不同。 NuGet 包在设计上是不可变的,因此每次发布包时都必须增加版本。
  • 另外,由于您的项目以 netstandard 为目标,因此它必须是 SDK 风格的项目。 SDK风格的项目不需要nuspec,可以指定the metadata in the csproj file,或者使用Visual Studio的项目属性窗口。

标签: azure azure-devops nuget


【解决方案1】:

我正在使用 nuspec 和 nuget pack 命令,这似乎不起作用。 我使用 csproj 字段和 Azure Devops 切换到使用 dotnet pack 命令,这一切都很好。

感谢 zivkan 的启发 :)

【讨论】:

    猜你喜欢
    • 2013-08-04
    • 2021-10-16
    • 1970-01-01
    • 1970-01-01
    • 2021-11-25
    • 2015-01-12
    • 2023-01-31
    • 1970-01-01
    • 2015-09-10
    相关资源
    最近更新 更多