首页 > 解决方案 > 在 AWS 项目中使用来自不同来源的 NuGet 包

问题描述

目前,我正在开发一种可以从 DevOps 返回工作项的 Alexa 技能。为此,我使用 Aws Toolkit for Visual Studio。

现在我想知道是否可以包含来自我们 DevOps 组织的 NuGet 包。

基本上是这样的:

using Amazon.Lambda.Core;
using Newtonsoft.Json;
using Slight.Alexa.Framework.Models.Requests;
using Slight.Alexa.Framework.Models.Responses;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace AlexaDevOpsSkill
{
    public class Function
    {

        /// <summary>
        /// Searches for a work item.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public string FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            IOutputSpeech outputSpeech = null;
            if (input.Request.Intent.Name == "SearchIntent")
            {
                MyNuGetPackage.DevOpsItem devOpsItem = MyNuGetPackage.GetWorkItem(input.Request.Intent.Slots["Id"]);
                outputSpeech = new PlainTextOutputSpeech() { Text = $"I found the workitem: {devOpsItem.Name}" };
            }
            Response response = new Response() { OutputSpeech = outputSpeech };
            SkillResponse skillResponse = new SkillResponse() { Response = response };
            return JsonConvert.SerializeObject(skillResponse);
        }
    }
}

我知道,有一个 NuGet 包允许我在 nuget.org 上搜索工作项,但我希望有一天能包含来自不同 NuGet 包的其他功能。这只是我目前的例子。

从其他来源安装 Nuget 包时,我什至无法在 function.cs 文档中引用它。

如果 AWS 无法做到这一点,我可以在 DevOps 上托管我的功能以供 Alexa 使用吗?

标签: c#aws-lambdaalexa

解决方案


您可以在存储库根目录的文件中为包定义多个源NuGet.Config(如果不存在则创建它)。

就像是:

<?xml version="1.0" encoding="utf-8"?>
<configuration>

    <packageSources>
        <add key="MyCompanySource" value="https://nuget.mycompany.org/repository/index.json" />     
    </packageSources>


</configuration>

您需要指定的确切配置取决于本地 nuget 服务器的类型及其配置。默认 nuget.org 源已由系统范围的 nuget.config 指定,因此您无需添加它。


推荐阅读