ASP.NET 从 Visual Studio 2015 升级到 2017RC 的核心项目在每次启动时都会抛出错误。

ASP.NET Core project upgraded from Visual Studio 2015 to 2017RC throws an error on every start.

我将一个 ASP.NET 核心项目从 Visual Studio 2015 升级到 Visual Studio 2017RC,现在每次我 运行 新项目,在 Program.Main 之前被击中,显示一个对话框:

Object reference not set to an instance of an object.

完成后 Visual Studio 继续并调用 Program.Main

这只会在 运行直接使用项目时发生,运行使用 IISExpress 似乎可以避免该问题。

为什么会这样,我该如何解决?

这似乎是 Visual Studio 2017 升级工具中的错误。问题出在 Properties/launchSettings.json - 格式已更改但升级无法处理它们。

2015 年 Visual Studio:

"MyApplication": {
  "commandName": "Project",
  "launchBrowser": true,
  "launchUrl": "http://localhost:12345/home",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
}

在 Visual Studio 2017 年,这需要变成:

"MyApplication": {
  "commandName": "Project",
  "launchBrowser": true,
  "launchUrl": "home",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  },
  "applicationUrl": "http://localhost:12345"
}

添加 "applicationUrl" 属性 修复了异常弹出窗口。