【问题标题】:Using NuGet Packages from different Source in AWS Project在 AWS 项目中使用来自不同来源的 NuGet 包
【发布时间】:2021-10-20 22:28:50
【问题描述】:

目前,我正在开发一种 Alexa 技能,可以从 DevOps 返回工作项。为此,我使用 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-lambda alexa


    【解决方案1】:

    您可以在存储库根目录的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 指定,因此您无需添加它。

    【讨论】:

    • 好的,我刚刚注意到我无法引用它的原因。我的项目是一个 .net Core 3.1 项目,而我的 NuGet 包在 .net Core 5 中。似乎我需要降级我的包才能让它工作。但它适用于 nuget.config 然后。谢谢你:)
    猜你喜欢
    • 1970-01-01
    • 2019-04-09
    • 2019-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多