Skip to content

Commit 45766b4

Browse files
authored
Merge pull request #179879 from ggailey777/stefanus
Add remote debugging instruction for Visual Studio
2 parents 31d3f60 + e2f012c commit 45766b4

8 files changed

+87
-7
lines changed

articles/azure-functions/create-first-function-cli-csharp.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ adobe-target-content: ./create-first-function-cli-csharp-ieux
1515

1616
In this article, you use command-line tools to create a C# function that responds to HTTP requests. After testing the code locally, you deploy it to the serverless environment of Azure Functions.
1717

18+
This article supports creating both types of compiled C# functions:
19+
1820
[!INCLUDE [functions-dotnet-execution-model](../../includes/functions-dotnet-execution-model.md)]
1921

2022
This article creates an HTTP triggered function that runs on .NET 6.0. There is also a [Visual Studio Code-based version](create-first-function-vs-code-csharp.md) of this article.

articles/azure-functions/dotnet-isolated-process-guide.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ This section describes the current state of the functional and behavioral differ
270270
| ReadyToRun | [Supported](functions-dotnet-class-library.md#readytorun) | _TBD_ |
271271
| Application Insights dependencies | [Supported](functions-monitoring.md#dependencies) | Not Supported |
272272

273+
274+
## Remote Debugging using Visual Studio
275+
276+
Because your isolated process app runs outside the Functions runtime, you need to attach the remote debugger to a separate process. To learn more about debugging using Visual Studio, see [Remote Debugging](functions-develop-vs.md?tabs=isolated-process#remote-debugging).
273277
## Next steps
274278

275279
+ [Learn more about triggers and bindings](functions-triggers-bindings.md)

articles/azure-functions/functions-create-your-first-function-visual-studio.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ In this article, you learn how to:
2424
> * Create a function that responds to HTTP requests.
2525
> * Run your code locally to verify function behavior.
2626
> * Deploy your code project to Azure Functions.
27-
27+
2828
Completing this quickstart incurs a small cost of a few USD cents or less in your Azure account.
2929

3030
## Prerequisites

articles/azure-functions/functions-develop-vs.md

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Unless otherwise noted, procedures and examples shown are for Visual Studio 2022
2525

2626
## Prerequisites
2727

28-
- Azure Functions Tools. To add Azure Function Tools, include the **Azure development** workload in your Visual Studio installation. If you are using Visual Studio 2017, you may need to [follow some additional installation steps](#azure-functions-tools-with-visual-studio-2017).
28+
- Azure Functions Tools. To add Azure Function Tools, include the **Azure development** workload in your Visual Studio installation. If you're using Visual Studio 2017, you may need to [follow some extra installation steps](#azure-functions-tools-with-visual-studio-2017).
2929

3030
- Other resources that you need, such as an Azure Storage account, are created in your subscription during the publishing process.
3131

@@ -78,7 +78,7 @@ In C# class library functions, the bindings used by the function are defined by
7878

7979
![Create a Queue storage trigger function](./media/functions-develop-vs/functions-vstools-create-queuetrigger.png)
8080

81-
You will then be prompted to choose between two Azure storage emulators or referencing a provisioned Azure storage account.
81+
You'll then be prompted to choose between two Azure storage emulators or referencing a provisioned Azure storage account.
8282

8383
This trigger example uses a connection string with a key named `QueueStorage`. This key, stored in the [local.settings.json file](functions-develop-local.md#local-settings-file), either references the Azure storage emulators or an Azure storage account.
8484

@@ -134,7 +134,7 @@ As with triggers, input and output bindings are added to your function as bindin
134134

135135
---
136136

137-
In this example replace `<BINDING_TYPE>` with the name specific to the binding extension and `<TARGET_VERSION>` with a specific version of the package, such as `3.0.0-beta5`. Valid versions are listed on the individual package pages at [NuGet.org](https://nuget.org). The major versions that correspond to Functions runtime 1.x or 2.x are specified in the reference article for the binding.
137+
In this example, replace `<BINDING_TYPE>` with the name specific to the binding extension and `<TARGET_VERSION>` with a specific version of the package, such as `3.0.0-beta5`. Valid versions are listed on the individual package pages at [NuGet.org](https://nuget.org). The major versions that correspond to Functions runtime 1.x or 2.x are specified in the reference article for the binding.
138138
139139
3. If there are app settings that the binding needs, add them to the `Values` collection in the [local setting file](functions-develop-local.md#local-settings-file).
140140

@@ -163,7 +163,7 @@ For a full list of the bindings supported by Functions, see [Supported bindings]
163163

164164
## Run functions locally
165165

166-
Azure Functions Core Tools lets you run Azure Functions project on your local development computer. When you press F5 to debug a Functions project, the local Functions host (func.exe) starts to listen on a local port (usually 7071). Any callable function endpoints are written to the output, and you can use these for testing your functions. For more information, see [Work with Azure Functions Core Tools](functions-run-local.md). You're prompted to install these tools the first time you start a function from Visual Studio.
166+
Azure Functions Core Tools lets you run Azure Functions project on your local development computer. When you press F5 to debug a Functions project, the local Functions host (func.exe) starts to listen on a local port (usually 7071). Any callable function endpoints are written to the output, and you can use these endpoints for testing your functions. For more information, see [Work with Azure Functions Core Tools](functions-run-local.md). You're prompted to install these tools the first time you start a function from Visual Studio.
167167

168168
To start your function in Visual Studio in debug mode:
169169

@@ -209,6 +209,82 @@ You can also manage application settings in one of these other ways:
209209
* [Use the `--publish-local-settings` publish option in the Azure Functions Core Tools](functions-run-local.md#publish).
210210
* [Use the Azure CLI](/cli/azure/functionapp/config/appsettings#az-functionapp-config-appsettings-set).
211211

212+
## Remote Debugging
213+
214+
To debug your function app remotely, you must publish a debug configuration of your project. You also need to enable remote debugging in your function app in Azure.
215+
216+
This section assumes you've already published to your function app using a release configuration.
217+
218+
### Remote debugging considerations
219+
220+
* Remote debugging isn't recommended on a production service.
221+
* If you have [Just My Code debugging](/visualstudio/debugger/just-my-code#BKMK_Enable_or_disable_Just_My_Code) enabled, disable it.
222+
* Avoid long stops at breakpoints when remote debugging. Azure treats a process that is stopped for longer than a few minutes as an unresponsive process, and shuts it down.
223+
* While you're debugging, the server is sending data to Visual Studio, which could affect bandwidth charges. For information about bandwidth rates, see [Azure Pricing](https://azure.microsoft.com/pricing/calculator/).
224+
* Remote debugging is automatically disabled in your function app after 48 hours. After 48 hours, you'll need to reenable remote debugging.
225+
226+
### Attach the debugger
227+
228+
The way you attach the debugger depends on your execution mode. When debugging an isolated process app, you currently need to attach the remote debugger to a separate .NET process, and several other configuration steps are required.
229+
230+
When you're done, you should [disable remote debugging](#disable-remote-debugging).
231+
232+
# [In-process](#tab/in-process)
233+
234+
To attach a remote debugger to a function app running in-process with the Functions host:
235+
236+
+ From the **Publish** tab, select the ellipses (**...**) in the **Hosting** section, and then choose **Attach debugger**.
237+
238+
:::image type="content" source="media/functions-develop-vs/attach-to-process-in-process.png" alt-text="Screenshot of attaching the debugger from Visual Studio.":::
239+
240+
Visual Studio connects to your function app and enables remote debugging, if it's not already enabled. It also locates and attaches the debugger to the host process for the app. At this point, you can debug your function app as normal.
241+
242+
# [Isolated process](#tab/isolated-process)
243+
244+
To attach a remote debugger to a function app running in a process separate from the Functions host:
245+
246+
1. From the **Publish** tab, select the ellipses (**...**) in the **Hosting** section, and then choose **Download publish profile**. This action downloads a copy of the publish profile and opens the download location. You need this file, which contains the credentials used to attach to your isolated process running in Azure.
247+
248+
> [!CAUTION]
249+
> The .publishsettings file contains your credentials (unencoded) that are used to administer your function app. The security best practice for this file is to store it temporarily outside your source directories (for example in the Libraries\Documents folder), and then delete it after it's no longer needed. A malicious user who gains access to the .publishsettings file can edit, create, and delete your function app.
250+
251+
1. Again from the **Publish** tab, select the ellipses (**...**) in the **Hosting** section, and then choose **Attach debugger**.
252+
253+
:::image type="content" source="media/functions-develop-vs/attach-to-process-in-process.png" alt-text="Screenshot of attaching the debugger from Visual Studio.":::
254+
255+
Visual Studio connects to your function app and enables remote debugging, if it's not already enabled.
256+
257+
> [!NOTE]
258+
> Because the remote debugger isn't able to connect to the host process, you could see an error. In any case, the default debugging won't break into your code.
259+
260+
1. Back in Visual Studio, copy the URL for the **Site** under **Hosting** in the **Publish** page.
261+
262+
1. From the **Debug** menu, select **Attach to Process**, and in the **Attach to process** window, paste the URL in the **Connection Target**, remove `https://` and append the port `:4024`.
263+
264+
Verify that your target looks like `<FUNCTION_APP>.azurewebsites.net:4024` and press **Enter**.
265+
266+
![Visual Studio attach to process dialog](./media/functions-develop-vs/attach-to-process-dialog.png)
267+
268+
1. If prompted, allow Visual Studio access through your local firewall.
269+
270+
1. When prompted for credentials, instead of local user credentials choose a different account (**More choices** on Windows). Provide the values of **userName** and **userPWD** from the published profile for **Email address** and **Password** in the authentication dialog on Windows. After a secure connection is established with the deployment server, the available processes are shown.
271+
272+
![Visual Studio enter credential](./media/functions-develop-vs/creds-dialog.png)
273+
274+
1. Check **Show process from all users** and then choose **dotnet.exe** and select **Attach**. When the operation completes, you're attached to your C# class library code running in an isolated process. At this point, you can debug your function app as normal.
275+
276+
---
277+
278+
### Disable remote debugging
279+
280+
After you're done remote debugging your code, you should disable remote debugging in the [Azure portal](https://portal.azure.com). Remote debugging is automatically disabled after 48 hours, in case you forget.
281+
282+
1. In the **Publish** tab in your project, select the ellipses (**...**) in the **Hosting** section, and choose **Open in Azure portal**. This action opens the function app in the Azure portal to which your project is deployed.
283+
284+
1. In the functions app, select **Configuration** under **settings**, choose **General Settings**, set **Remote Debugging** to **Off**, and select **Save** then **Continue**.
285+
286+
After the function app restarts, you can no longer remotely connect to your remote processes. You can use this same tab in the Azure portal to enable remote debugging outside of Visual Studio.
287+
212288
## Monitoring functions
213289

214290
The recommended way to monitor the execution of your functions is by integrating your function app with Azure Application Insights. When you create a function app in the Azure portal, this integration is done for you by default. However, when you create your function app during Visual Studio publishing, the integration in your function app in Azure isn't done. To learn how to connect Application Insights to your function app, see [Enable Application Insights integration](configure-monitoring.md#enable-application-insights-integration).
268 KB
Loading
148 KB
Loading
68.2 KB
Loading

includes/functions-dotnet-execution-model.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ ms.date: 09/18/2021
66
ms.author: glenga
77
---
88

9-
This article supports creating both types of compiled C# functions:
10-
119
| Execution model | Description |
1210
| --- | --- |
1311
| **[In-process](../articles/azure-functions/create-first-function-cli-csharp.md?tabs=in-process)**| Your function code runs in the same process as the Functions host process. Supports both .NET Core 3.1 and .NET 6.0. To learn more, see [Develop C# class library functions using Azure Functions](../articles/azure-functions/functions-dotnet-class-library.md). |

0 commit comments

Comments
 (0)