c# - 从模板部署和运行 bot 框架 v4.4+ 有效,但使用 fork 和源代码控制部署和运行不起作用

标签 c# templates version-control botframework

总结

我正在尝试部署最新的 Microsoft Virtual Assistant code .在文档中,他们 describe a process使用 Visual Studio template 部署和运行机器人.文档中描述的整个过程非常有效。

但是,我不喜欢使用模板。我不想失去微软的 Git 历史。此外,这种部署需要经得起时间的考验,我希望尽可能简单地合并来自微软的更新。

内部 Microsoft's repo , 有一个 subdirectory包含 C# 虚拟助手 template和一个 sample of the code as if it were deployed by the template .

保留 Git 历史的方法、提取新提交的能力等

我将描述我的解决方案,它可以让我保留 Microsoft 的 Git 历史,轻松提取他们的最新提交,并且仍然为我提供一个合理规模的项目来处理我客户的机器人部署(Microsoft AI 存储库很大并且包含很多东西我不想在我的机器人部署中)。我正在处理的结果分支/项目与我从 Visual Studio 中的模板创建它时获得的解决方案/项目非常相似(参见下文,看起来相同)。

  1. forked Microsoft's entire GitHub repo .
  2. 我设置了一个本地 Git 存储库,将 Microsoft 的存储库和我的分支作为远程。
  3. 我使用了 Git 子树,如 Stack Overflow post 中所述将 repo 过滤为 Virtual Assistant C# sample code .我创建了一个 branch for this subtree .
  4. 我将子树分支复制到开发分支,我打算在其中进行所有自定义开发。
  5. 我可以在 Microsoft 的上游远程和新创建的子树分支上使用 master,以不断将 Microsoft 的新提交拉入我个人的开发分支。

这里有一些伪代码,粗略地遍历了整个过程。

$ git checkout upstream/master
Switched to branch upstream/master
Your branch is up to date with 'r_microsoft/master'.
$ git subtree split --prefix=templates/Virtual-Assistant-Template/csharp/sample --onto upstream/virtual-assistant-csharp -b upstream/virtual-assistant-csharp
$ git checkout upstream/virtual-assistant-csharp
$ git checkout -b eric/develop
Switched to branch 'eric/develop'
Your branch is up to date with 'r_eric/develop'.
$ git rebase upstream/virtual-assistant-csharp
Current branch eric/develop is up to date.

部署和运行机器人

使用这个子树而不是从模板创建的解决方案,我遵循了 directions用于部署和运行机器人。微软有一个 separate Markdown page for the deployment (链接以防万一你想检查它)。

部署似乎成功运行。我用 xxx 替换了敏感信息。

PS C:\Users\eric\bot\VirtualAssistantSample> .\Deployment\Scripts\deploy.ps1 -name "personal-bot-test-using-git" -location "westus" -luisAuthoringKey "xxx" -luisAuthoringRegion "westus" -resourceGroup "personal-bot-test-using-git" -appId "xxx" -appPassword "xxx"
> Creating resource group ...
> Deploying Azure services (this could take a while)...
> Updating appsettings.json ...
> Deploying cognitive models ...
> Initializing dispatch model ...
> Parsing general LU file ...
> Deploying general LUIS app ...
> Adding general app to dispatch model ...
> Parsing chitchat LU file ...
> Deploying chitchat QnA kb ...
> Adding chitchat kb to dispatch model ...
> Parsing faq LU file ...
> Deploying faq QnA kb ...
> Adding faq kb to dispatch model ...
> Creating dispatch model...
> Done.

我完全按照他们的步骤做了一切(除了没有使用模板)。当我构建时,没有错误。运行机器人显示没有错误。

The web page seems to indicate that things are working.

这是我使用 Microsoft's Bot Emulator 进行连接(替换了敏感值)。

Image of how I connected.

但是,当我测试机器人时,没有骰子。它不显示欢迎消息。

No welcome message.

沟通不畅。

Image showing that it's definitely not working .

这是 POST 400 directline.postActivity 所说的内容。

{
  "error": {
    "code": "ServiceError",
    "message": "Refresh access token failed with status code: 401"
  }
}

另一方面,如果我执行所有相同的步骤,除了从模板创建的项目/解决方案开始,它就可以正常工作。

This magically works. .

附加上下文

  • 我使用 Visual Studio 2019 和 2017 以及最新的 NuGet 包尝试了整个过程。似乎没有任何区别。
  • 根据我启动项目的方法,没有 .sln 文件。所以我使用 .csproj 文件打开项目。使用 bot 模板,它创建了一个 .sln 文件,我可以用它来打开整个文件。无论我是使用 .sln 还是 .csproj 打开从模板部署的项目,它都有效。
  • 我使用 WinMerge 比较了机器人的目录(源代码的子树与模板创建的子树) .我看不出有什么显着差异(当然我无法深入挖掘 .dll 文件的内容)。
  • 编辑 ~ 创建后 8 小时。似乎即使使用模板创建的机器人也不再运行?

最佳答案

@EricHansen 和我在 his related GitHub Issue 中讨论过这个问题.由于信息可能对其他人有值(value),因此我将在此处包含“答案”:

401 几乎总是由不匹配的 MicrosoftAppId/MicrosoftAppPassword 引起的。确保它们在所有这些位置都匹配:

  1. appsettings.json/.env/.bot,任何适用
  2. The App Registration
  3. 打开模拟器时使用的那个

如果这不起作用,请按照 Authentication Troubleshooting Guide

您还应确保所有软件包都是最新的,包括:

OP 解决方案很可能与此相关:

I've definitely had issues with some password strings. The README notes that it has trouble with passwords containing @. I know I've had trouble with another password, however (I don't remember what special character gave it the issue). I would guess that this was the issue.

My best guess is that it was either an issue with a special character in a password, emulator caching id/pass in some unexpected way, or IIS Express caching id/pass in some way. Usually, if I'm switching bots with the same endpoints and running into trouble, I restart those and it usually works.

关于c# - 从模板部署和运行 bot 框架 v4.4+ 有效,但使用 fork 和源代码控制部署和运行不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56047387/

相关文章:

c# - Entity Framework 和 DataContractSerializer

c# - LINQ LEFT JOIN where 子句不起作用

c++ - 带有基类的模板类

c++ - <未解析的重载函数类型> 带有成员函数指针和模板

database - 对于不使用源代码管理的团队 - 如何跟踪 SQL Server 2012 中的架构更改?

c# - 如果在 SQL 中启用了 Broker Service,我如何检查 c#?

c# - StreamReader.Readline() 真的是计算文件行数最快的方法吗?

c++ - 将可变参数模板的参数分成不同的列表?

git - 如果 git pull 请求仍待处理,我如何继续跨分支工作?

c# - 以编程方式检测从 C# 代码 checkout 的当前 git 分支