简体   繁体   English

Typescript 指令错误:VS2017 中的“断点设置但尚未绑定”

[英]Error on Typescript instruction: “Breakpoints set but not yet bound” in VS2017

I create a project with "dotnet new angular".我创建了一个带有“dotnet new angular”的项目。 When a breakpoint is set on a Typescript instruction, it shows as a open red circle when run.当在 Typescript 指令上设置断点时,它在运行时显示为一个开放的红色圆圈。 The error message is "The breakpoint will not currently be hit. Breakpoints set but not yet bound."错误消息是“当前不会命中断点。断点已设置但尚未绑定。”

This problem started when I updated from .Net Core SDK 1.x to 2.x Is this a bug in 2.x or something to do with my setup?当我从 .Net Core SDK 1.x 更新到 2.x 时开始出现这个问题 这是 2.x 中的错误还是与我的设置有关? Does anyone using 2.x have Typescript breakpoints working in VS2017?有没有人使用 2.x 有在 VS2017 中工作的 Typescript 断点? I describe my setup in detail below and where it fails.我在下面详细描述了我的设置以及它失败的地方。

To duplicate the problem, you can set a breakpoint on "this.currentCount++;"要复制该问题,您可以在“this.currentCount++;”上设置断点。 in ClientApp\\src\\app\\counter\\counter.component.ts and then click "Increment" on the "Counter" page.在 ClientApp\\src\\app\\counter\\counter.component.ts 中,然后在“计数器”页面上单击“增量”。

I am currently using what should be the latest official releases:我目前使用的应该是最新的官方版本:

Visual Studio Pro 15.7.2
.Net Core SDK 2.1.300 (x64)
.Net Core Runtime 2.1.0 (x64)

I tried other SDK 2.x releases.我尝试了其他 SDK 2.x 版本。 It fails in v2.1.4 & v2.1.300.它在 v2.1.4 和 v2.1.300 中失败。 But breakpoints succeed in v2.0.0, 2.1.200 & 2.1.201.但是断点在 v2.0.0、2.1.200 和 2.1.201 中成功。

The difference is that, when it succeeds, each of the SDKs generate the files "webpack.config.js" & "webpack.config.vendor.js" in the root of the project during the "dotnet new angular".不同的是,当它成功时,每个SDK在“dotnet new angular”期间在项目的根目录下生成文件“webpack.config.js”和“webpack.config.vendor.js”。 The latest 2.x release does not generate these files in the root.最新的 2.x 版本不会在根目录中生成这些文件。 So I don't want to use prior releases which did.所以我不想使用以前的版本。

The other difference is that the working projects define the location of "ClientApp" in webpack.config.js.另一个区别是工作项目在 webpack.config.js 中定义了“ClientApp”的位置。 In those projects that fail, the ClientApp location is defined in startup.cs.在那些失败的项目中,ClientApp 位置在 startup.cs 中定义。

Some more info:更多信息:

Using sdk v2.1.201 (one which works), the generated package.json contains:使用 sdk v2.1.201(一个有效的),生成的 package.json 包含:

"typescript": "2.4.1",
"webpack": "2.5.1",
"webpack-hot-middleware": "2.18.2",
"webpack-merge": "4.1.0",

Using sdk v2.1.300 (one which fails),the generated package.json contains:使用 sdk v2.1.300(失败的一个),生成的 package.json 包含:

"typescript": "~2.5.3"

but does not contain entries for webpack.但不包含 webpack 的条目。 In node_modules/.bin there is a "webpack.cmd" whose version is 3.11.0.在 node_modules/.bin 中有一个版本为 3.11.0 的“webpack.cmd”。

When I type "tsc -v" at in a VS2017 Developer Command window, I get:当我在 VS2017 开发人员命令窗口中键入“tsc -v”时,我得到:

version 2.8.4

UPDATE: I added an issue to the .Net SDK issues .更新:我在.Net SDK 问题中添加了一个问题
I was asked there to open a Developer Feedback item for Visual Studio .我被要求在那里打开Visual Studio开发人员反馈项目 They believe it is a VS issue for TS/JS tooling.他们认为这是 TS/JS 工具的 VS 问题。

If you are also having this issue, it can help bump its priority, if you add to the feedback page.如果您也遇到此问题,如果您添加到反馈页面,它可以帮助提高其优先级。

UPDATE (2018-03-23) RESOLVED更新 (2018-03-23) 已解决

This problem may have been resolved earlier than today, but I hadn't looked into it again until today.这个问题可能比今天更早解决了,但直到今天我才再次研究它。 Today, I updated VS2017 to v15.9.9, .Net Core SDK to 2.2.105 and .Net core Host to 2.2.3.今天我把VS2017更新到v15.9.9,.Net Core SDK更新到2.2.105,.Net core Host更新到2.2.3。 Typing "tsc -v" at the developer prompt shows "Version 3.1.2".在开发人员提示下键入“tsc -v”显示“版本 3.1.2”。

When I now run "dotnet new angular" and set a breakpoint on "this.currentCount++", the breakpoint is hit.当我现在运行“dotnet new angular”并在“this.currentCount++”上设置断点时,断点被命中。

NOTE: This problem may still be occurring when running the client app in other browsers than Chrome.注意:在 Chrome 以外的其他浏览器中运行客户端应用程序时,可能仍会出现此问题。 But I was always using Chrome, both when I had the problem earlier and today when it looks resolved.但是我一直在使用 Chrome,无论是在我早些时候遇到问题时还是今天看起来已经解决时。

Update from Microsoft on linked thread: Microsoft 在链接线程上的更新:

Typescript breakpoints in Visual Studio will not work for ASP.NET core projects currently in either of the 2 situations: Visual Studio 中的 Typescript 断点不适用于当前处于以下两种情况之一的 ASP.NET 核心项目:

  1. If you have either renamed/deleted the "ClientApp" directory within your Visual Studio project to be something else, OR如果您已将 Visual Studio 项目中的“ClientApp”目录重命名/删除为其他目录,或者
  2. You have Typescript/JavaScript files in a different directory (other than ClientApp).您在不同的目录(而不是 ClientApp)中有 Typescript/JavaScript 文件。

Unfortunately we currently do not have a way to resolve breakpoints in Typescript files outside of the ClientApp folder.不幸的是,我们目前没有办法解决 ClientApp 文件夹之外的 Typescript 文件中的断点。 We are working with the relevant teams within Visual Studio for a fix for the same but if you are impacted by this change, I would recommend switching to working within the "ClientApp" folder.我们正在与 Visual Studio 中的相关团队合作修复相同的问题,但如果您受到此更改的影响,我建议您切换到“ClientApp”文件夹中工作。

My workaround is that I debug the front-end separately using VSCode which is not ideal but seems the only way to get it working with .net core and custom project structure我的解决方法是我使用 VSCode 单独调试前端,这并不理想,但似乎是让它与 .net 核心和自定义项目结构一起使用的唯一方法

On Aug 29, 2018, a solution to this problem was reported by Blair Wang on: https://developercommunity.visualstudio.com/content/problem/268468/typescript-breakpoints-not-hit-in-visual-studio-15.html#reply-323159 2018 年 8 月 29 日,Blair Wang 报告了此问题的解决方案: https : //developercommunity.visualstudio.com/content/problem/268468/typescript-breakpoints-not-hit-in-visual-studio-15。 html#reply-323159

    "This issue has been fixed and is now available in our latest update. You can download the update via the in-product notification or from here: https://visualstudio.microsoft.com/vs/"

I had not seen this until today (2018-03-23), when I tested the fix using:直到今天(2018-03-23),当我使用以下方法测试修复程序时,我才看到这一点:

    Visual Studio v15.9.9
    .Net Core SDK 2.2.105
    .Net core Host 2.2.3
    Typescript 3.1.2

It was working with the fix.它正在修复。 It is also still working as of today on 2019-09-09 with VS2017 v15.9.15 and also Vs2019.截至今天,它仍然在 2019-09-09 使用 VS2017 v15.9.15 和 Vs2019 工作。

For anybody who runs across this issue while using .Net Core 3.1 and Angular/TypeScript, the solution for me was to add app.UseSpaStaticFiles() before the app.Use() line in the Startup.cs Configure method:对于在使用 .Net Core 3.1 和 Angular/TypeScript 时遇到此问题的任何人,我的解决方案是在 Startup.cs Configure 方法中的 app.Use() 行之前添加 app.UseSpaStaticFiles() :

// Declare middleware "use" statements before app.Use() in order to run/debug properly.
app.UseAuthentication();
app.UseHttpsRedirection();
app.UseSpaStaticFiles();
app.UseCookiePolicy();
app.UseStaticFiles();

// Necessary to force users to authenticate
app.Use(async (context, next) =>
{
  if (!context.User.Identity.IsAuthenticated)
  {
    await context.ChallengeAsync();
  }
  else
  {
    await next();
  }
});

Originally, I had the app.UseSpaStaticFiles() statement below the app.Use section and received the "breakpoints set but not yet bound" message.最初,我在 app.Use 部分下面有 app.UseSpaStaticFiles() 语句,并收到了“断点设置但尚未绑定”的消息。 This occurred in Visual Studio 2019. After moving the middleware statements up, the breakpoints started working.这发生在 Visual Studio 2019 中。将中间件语句上移后,断点开始工作。 (I think this used to work before I upgraded to .Net Core 3, but I'm not certain.) (我认为这在我升级到 .Net Core 3 之前曾经有效,但我不确定。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM