Azure 自定义 Nuget 包外部库

Azure custom Nuget package external libraries

System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'TextFieldParserStandard, Version=1.0.0.0,
 Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. 

如果我在使用 NuGet 的项目中手动搜索并添加此库,我的 NuGet 就可以工作。但它们应该自动出现。当我安装其他包时,我不需要手动安装它们的库。 所以问题是“TextFieldParserStandard”没有随我的 NuGet 安装立即自动安装。

在 Artifacts Feed 中,我只有我的包“MyNuGet 版本 1.0.0.11538”。我不知道我的 Feed 中是否应该有“TextFieldParserStandard”。 在Visual Studio,Manage NuGetPackages中,我的NuGet没有任何依赖。

我的 NuGet SDK:.NET Standard 2.0(注意:与导入的项目兼容,因为如果我手动添加 TextFieldParserStandard,它就可以工作)。

如果需要,我可以提供 yaml 管道。这以某种方式针对问题。 Build NuGet Package automatically including referenced dependencies

但是在yaml中添加IncludeReferencedProjects并没有解决

Azure custom Nuget package external libraries

那是因为您没有将参考包 TextFieldParserStandard 作为依赖项添加到自定义包 MyNuGet 中。

在这种情况下,当您安装包MyNuGet时,它不会自动将参考包TextFieldParserStandard安装到您的项目中。

要解决此问题,您可以在项目 MyNuGet 文件 MyNuGet.csproj:[=27 中为包 TextFieldParserStandard 添加 属性 <PrivateAssets>all</PrivateAssets> =]

  <ItemGroup>
    <PackageReference Include="TextFieldParserStandard" Version="1.0.0">
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

将此更改提交到 repo,然后为您的自定义包生成新包,它将 TextFieldParserStandard 包作为依赖项:

更新:

因为TextFieldParser不能在单元测试中引用。

您可以尝试使用 Dependencies 元素创建 .nupsec 文件,例如:

<dependencies>             
  <dependency id="another-package" version="3.0.0" />             
  <dependency id="yet-another-package" version="1.0.0" />        
</dependencies>

您可以参考this document了解更多详情。