OfficeDev / office-js-docs-pr

Microsoft Office Add-ins Documentation
https://learn.microsoft.com/office/dev/add-ins
Creative Commons Attribution 4.0 International
408 stars 251 forks source link

Custom Functions debugging not working #2597

Closed brad302 closed 3 years ago

brad302 commented 3 years ago

Put simply, this process does not appear to work.

I can successfully debug the taskpane using both VS Code and the Edge DevTools application but a break point in any custom function never fires.

I have no other information other than I stripped it all back to the default install from the YO generator (selected custom functions as the option) and still no good.

Happy to provide whatever information is required to try and solve this. I'm hoping it's a small trick that hasn't been documented.

Thanks

Brad


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

AlexJerabek commented 3 years ago

Hi Brad,

Thanks for raising this issue. I have a couple of questions for you to help us debug the debugging issue.

1) What version of Excel do you have? You can find this under File > Account (please give us the version and build number). 2) Is the custom function successfully running? I just want to verify everything is working as expected before working on the breakpoint issue.

brad302 commented 3 years ago

@AlexJerabek, thanks for the reply.

Excel version 2103 (Build 13901.20230 Click-to-run)

Yes, the functionality is running, there's no doubt about it. I can run one of the functions and it returns a value. If I put a breakpoint in the taskpane JS, it breaks as expected.

Happy to provide anything else you need.

AlexJerabek commented 3 years ago

Thanks @brad302.

Let me assign @alison-mk to dig deeper into the custom functions debugging issue.

brad302 commented 3 years ago

Thanks @AlexJerabek.

@alison-mk, looking forward to getting your views. Thanks!

brad302 commented 3 years ago

Does this help?

Breakpoint Error
alison-mk commented 3 years ago

Hi @brad302, thanks for reporting this issue! I just tested the UI-less custom functions debugging process, and I encounter an issue, but it looks like a different issue than the one you encounter. In my testing, the final step of the debugging process doesn't seem to work. My tests don't yield the "Breakpoint ignored..." error in your screenshot.

The process works for me up until "Use the VS Code debugger for Excel Desktop" > "Start debugging" > Step 3. Here, the article says "At this point execution will stop on the line of code where you set the breakpoint." In my testing, VS Code detects the breakpoint in the "Breakpoints" pane, but the custom functions with breakpoints still run in Excel, and nothing else changes in VS Code. I'm consulting @mscharlock to see if perhaps there's a step missing, or if this is a deeper issue. We'll update you when we have more information about this.

For the issue in your screenshot, "Breakpoint ignored because generated code not found...", I found results in a quick internet search, like this StackOverflow question. Do any of the suggestions there help you?

Thanks again, Alison

brad302 commented 3 years ago

Thanks @alison-mk, yes, found the same link but it's a lot deeper than I was hoping to go and that file is something I'll need to read up on I'd say. It appears in multiple places within the project directory and therefore, wanted to get your counsel first. Time to dig deeper I guess.

brad302 commented 3 years ago

@alison-mk, I should also point out, if I follow the UI-less procedure (https://docs.microsoft.com/en-gb/office/dev/add-ins/excel/custom-functions-debugging#use-the-vs-code-debugger-for-excel-desktop) then the breakpoint sticks but doesn't fire.

It's when I follow the UI based procedure (https://docs.microsoft.com/en-gb/office/dev/add-ins/testing/debug-with-vs-extension) that I get the message above.

So based on that, it's probably nothing to worry about.

I have to say, having two methods for debugging isn't ideal. It's probably why I'm keen on getting the VS template to work. That's another issue though.

alison-mk commented 3 years ago

Hi @brad302,

I've investigated this issue and have additional information for you.

The UI-less custom functions debugging article is only for "UI-less" custom functions, and the Yo Office generator no longer automatically creates a UI-less custom function. I will correct the article to clarify that point. Thanks for bringing this to our attention, and I'm sorry for the confusion!

A UI-less custom function uses OfficeRuntime, which has limitations and is currently only recommended for very specific scenarios. Based on the testing scenarios you've described, it sounds like setting your add-in up to use a "shared runtime" will be the best solution for you. A shared runtime offers the most functionality and flexibility to use the task pane, ribbon, Office.js APIs, and new features like keyboard shortcuts. To set up a shared runtime for your add-in, follow the steps in the Configure your Office Add-in to use a shared JavaScript runtime article. One important detail in this article concerns debugging:

When using a shared runtime, you can't use Visual Studio Code to debug custom functions in Excel on Windows at this time. You'll need to use developer tools instead. For more information, see Debug add-ins using developer tools on Windows 10.

I'll leave this issue open until I've updated the UI-less debugging article. Let us know if you have any further questions.

Thank you, Alison