如何使用 Azure Functions 在 VSTS 包管理中使用 NuGet 包?

How to Use NuGet Package in VSTS Package Management with Azure Functions?

Azure Functions 的一个好处是你可以 bring your own dependencies with NuGet, npm, etc. If you have an internal NuGet package inside of VSTS Package Management 你想在你的 Azure Functions 中用作依赖项,你将如何将它包含在你的 Azure Functions usings?

示例:我可能想利用我的内部数据访问库、模型或业务逻辑,然后使用 VSTS 包管理作为我们团队管理内部依赖项的方式。我们不想将它们发布到 public nuget.org 图库

感谢您的帮助!

您可以使用可用信息在私有 NuGet 存储库中引用包

将私有源添加到配置文件后,您可以按照概述的信息添加对自定义包的引用 here

(来自 OP 的额外编辑...)

例子project.json

{
  "frameworks": {
    "net46":{
      "dependencies": {
        "Contoso.Models": "1.2.0",
        "Contoso.DAL ": "1.2.0"
      }
    }
   }
}
  • project.json 已添加到您的函数的根文件夹。

例子nuget.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
      <add key="MyVSTSPackageManagementFeed" value="https://contoso.pkgs.visualstudio.com/_packaging/Contoso/nuget/v3/index.json" />
  </packageSources>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
    <packageSourceCredentials>
    <MyVSTSPackageManagementFeed>
      <add key="Username" value="me@contoso.com" />
      <add key="ClearTextPassword" value="<MyPersonalAccessTokenHere>" />
    </MyVSTSPackageManagementFeed>
  </packageSourceCredentials>
</configuration>
  • nuget.config 被添加到您的函数的根文件夹,或者如果您想在所有函数中使用它们,您可以将它添加到主机级别文件夹。