c# - 在 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 使用吗?
解决方案
您可以在存储库根目录的文件中为包定义多个源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 指定,因此您无需添加它。
推荐阅读
- wordpress - 将 Wordpress 菜单项描述写入 Timber Twig 模板
- javascript - 如何将附加文本放入其容器中
- java - 为什么 Spring 的 @Component 注解不使用完整的类名?
- php - 在我的语句中使用布尔值时函数总是返回 false
- python - 通过 Azure DevOps Python API 创建 VSTS PBI
- python - 使用多线程的异步请求
- javascript - 数组创建元素上的 JavaScript AppendChild
- apache-kafka - Spring Tool Suite IDE 与 Apache Kafka 的集成
- c++ - “找到一个或多个多重定义的符号”,包括
- c - C 的 OClint 警告混淆