删除 Application Insights 后应用无法启动

App won't start after removing Application Insights

我在 Visual Studio 2015 年使用模板创建了一个 ASP.NET 核心项目,并错误地选中了 "Add Application Insights to project" 复选框。

后来,我从 project.json 中删除了 Microsoft.ApplicationInsights.AspNetCore 包,并删除了 Startup.cs 中对那些 类 的所有引用。

该项目编译正常,但当我尝试在 IIS Express 中 运行 它时抛出错误:

No service for type 'Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration' has been registered.

或者

The name 'TelemetryConfiguration' does not exist in the current context

如果您的 Razor 页面中仍有对 Application Insights 的引用,应用程序将编译但不会 运行。 (因为 Razor 页面是在 运行 时编译的。)

Views/_ViewImports.cshtmlViews/Shared/_Layout.cshtml 中查找引用 Application Insights 的行。一旦我删除了那些,我的应用程序就可以正常启动了。