How to setup VSCode to debug Firebase Functions? - firebase

Pre-requisite: Firebase and node is setup correctly in the local machine
Requirements:
I only need to click the "Start Debugging (F5)" in VSCode once, then all other setup will be done automatically and I can start debugging.
When I change the code in editor during debugging, the change will be deployed and effective immediately
I can keep start and stop debugging session without worrying about process clean up because it's handled automatically after ending debugging session (Shift-F5)

You need only 2 files. Once they are in place, you can F5 to start debugging and Shift-F5 to stop debugging Firebase Functions.
{project_root}/.vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Debug",
"port": 9229,
"restart": true,
"skipFiles": ["<node_internals>/**"],
"preLaunchTask": "start firebase emulator",
"postDebugTask": "stop firebase emulator"
}
]
}
{project_root}/.vscode/tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "start firebase emulator",
"type": "shell",
"isBackground": true,
// (1) This autocompiles if there is any code change and effective immediately.
// (2) The single '&' ensures tsc -w (used in run build) will not block the emulator to start
// (3) --inspect-function allows debugger to be attached
"command": "npm --prefix ./functions run build -- -w & firebase emulators:start --inspect-functions",
"presentation": { "reveal": "silent", "close": true },
"problemMatcher": [
{
"pattern": [
{
"regexp": ".",
"file": 1,
"line": 1,
"column": 1,
"message": 1
}
],
"background": {
"activeOnStart": true,
"beginsPattern": { "regexp": "." },
"endsPattern": { "regexp": "." }
}
}
]
},
{
"label": "stop firebase emulator",
"command": "echo ${input:terminate}",
"type": "shell"
}
],
"inputs": [
{
"id": "terminate",
"type": "command",
"command": "workbench.action.tasks.terminate",
"args": "terminateAll"
}
]
}

Related

How does TeamsFx Hello World Tab sample app invoke local development?

I created the hello world tab example using TeamsFx toolkits VS Code extension. The part that I don't understand is how does the debug mode invoking the tab react app start script?
In the tasks.json file, there is a dependsOn teamsFx: frontend start setting. I couldn't figure out where frontend start script or frontend being declared.
Here is the task.json file
{
"version": "2.0.0",
"tasks": [
{
"label": "Pre Debug Check",
"dependsOn": ["dependency check", "prepare dev env"],
"dependsOrder": "sequence"
},
{
"label": "dependency check",
"type": "shell",
"command": "exit ${command:fx-extension.validate-dependencies}"
},
{
"label": "prepare dev env",
"dependsOn": ["prepare local environment", "frontend npm install"],
"dependsOrder": "parallel"
},
{
"label": "prepare local environment",
"type": "shell",
"command": "exit ${command:fx-extension.pre-debug-check}"
},
{
"label": "Start Frontend",
"dependsOn": ["teamsfx: frontend start"],
"dependsOrder": "parallel"
},
{
"label": "frontend npm install",
"type": "shell",
"command": "npm install --no-audit",
"options": {
"cwd": "${workspaceFolder}/tabs"
}
}
]
}
teamsfx: frontend start is a task contributed by Teams Toolkit extension using Visual Studio Code Extension API: Task Provider. Specifically, from TeamsFx GitHub repo:
the definition of this task is in https://github.com/OfficeDev/TeamsFx/blob/ms-teams-vscode-extension%403.8.0/packages/vscode-extension/package.json#L717-L729.
the implementation of this task is in https://github.com/OfficeDev/TeamsFx/blob/ms-teams-vscode-extension%403.8.0/packages/vscode-extension/src/debug/teamsfxTaskProvider.ts#L116-L129.

Debugging ASP.NET Web App on VS Code Linux doesnt work

I'm testing out ASP.NET Core using this tutorial: https://www.blinkingcaret.com/2018/03/20/net-core-linux/
When building and running from the terminal, both the CLI and Web app works fine:
Web app:
dotnet run
Using launch settings from /home/peter/Documents/dotnet_linux/Reminders.Web/Properties/launchSettings.json...
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using '/home/peter/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
Hosting environment: Development
Content root path: /home/peter/Documents/dotnet_linux/Reminders.Web
Now listening on: https://localhost:5001
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
However from VS Code 1.28.1 I can only run the CLI app. When I add a configuration for the web app:
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/Reminders.Web/bin/Debug/netcoreapp2.1/Reminders.Web.dll>",
"args": [],
"cwd": "${workspaceFolder}/Reminders.Web/bin/Debug",
"stopAtEntry": false,
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/Reminders.Cli/bin/Debug/netcoreapp2.1/Reminders.Cli.dll",
"args": [],
"cwd": "${workspaceFolder}/Reminders.Cli",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
},
]
}
I get the error
This DLL does indeed exist.
I have looked through all config options for launch.json here: https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md but not found anything
You have an extra angle bracket.
Change
"program": "${workspaceFolder}/Reminders.Web/bin/Debug/netcoreapp2.1/Reminders.Web.dll>",
to
"program": "${workspaceFolder}/Reminders.Web/bin/Debug/netcoreapp2.1/Reminders.Web.dll",

Internal server error when deploying ARM Template

I am deploying an arm template that contains the following resources
Microsoft.Storage/storageAccount
Microsoft.Sql/servers
Microsoft.Sql/servers/auditPolicies
Now everything worked until I started changing the values for the auditPolicies object. Here are the steps I took until the InternalServerError occurred.
Added the auditState property and set its value to Disabled. Deployment Successful.
Changed the auditState property to Enabled. Deployment failed. Error states that the storageAccountName is required.
Added storageAccountName and set its value to the name of the storage account. Deployment failed. Error states that storageAccountKey.
Added storageAccountKey and set its value to key1 of the storage account's keys object. Deployment failed. Internal Server Error - "An Error has occurred while saving Auditing settings, please try again later". Additionally, the errors cause the deployment to run indefinitely. Though I am not concerned about that aspect.
The following is the complete template.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"app-name-prefix": {
"type": "string",
"minLength": 1
},
"app-locations": {
"type": "array",
"minLength": 1
},
"app-friendly-names": {
"type": "array",
"minLength": 1
},
"db-user-admin-username": {
"type": "securestring"
},
"db-user-admin-password": {
"type": "securestring"
},
"database-audit-enabled": {
"defaultValue": "Enabled",
"allowedValues": [
"Enabled",
"Disabled"
],
"type": "string"
},
"storage-kind": {
"defaultValue": "BlobStorage",
"allowedValues": [
"StorageV2",
"BlobStorage"
],
"type": "string"
},
"storage-sku": {
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_ZRS",
"Standard_GRS",
"Standard_RAGRS",
"Premium_LRS"
],
"type": "string"
}
},
"variables": {
"db-service-name": "[concat(parameters('app-name-prefix'), '-database-service-')]",
"storage-name": "[concat(toLower(parameters('app-name-prefix')), 'auditstorage')]"
},
"resources": [
{
"name": "[concat(variables('storage-name'), parameters('app-friendly-names')[copyIndex()])]",
"type": "Microsoft.Storage/storageAccounts",
"sku": {
"name": "[parameters('storage-sku')]"
},
"kind": "[parameters('storage-kind')]",
"apiVersion": "2018-02-01",
"location": "[parameters('app-locations')[copyIndex()]]",
"copy": {
"count": "[length(parameters('app-locations'))]",
"name": "storageCopy"
},
"properties": {
"supportsHttpsTrafficOnly": true,
"accessTier": "Hot",
"encryption": {
"services": {
"blob": {
"enabled": true
},
"file": {
"enabled": true
}
},
"keySource": "Microsoft.Storage"
}
}
},
{
"type": "Microsoft.Sql/servers",
"name": "[concat(variables('db-service-name'), parameters('app-friendly-names')[copyIndex()])]",
"apiVersion": "2014-04-01",
"location": "[parameters('app-locations')[copyIndex()]]",
"copy": {
"name": "databaseServiceCopy",
"count": "[length(parameters('app-locations'))]"
},
"properties": {
"administratorLogin": "[parameters('db-user-admin-username')]",
"administratorLoginPassword": "[parameters('db-user-admin-password')]",
"version": "12.0"
},
"resources": [
{
"type": "auditingPolicies",
"name": "Default",
"apiVersion": "2014-04-01",
"location": "[parameters('app-locations')[copyIndex()]]",
"properties": {
"auditingState": "[parameters('database-audit-enabled')]",
"storageAccountName": "[concat(variables('storage-name'), parameters('app-friendly-names')[copyIndex()])]",
"storageAccountKey": "[listKeys(concat(variables('storage-name'), parameters('app-friendly-names')[copyIndex()]), '2018-02-01').keys[0].value]"
},
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', concat(variables('db-service-name'), parameters('app-friendly-names')[copyIndex()]))]",
"storageCopy"
]
}
]
}
]
}
What am I missing that will help resolve this issue? What do I need to do to stop this internal server error?
I have added the complete template as was requested by #Pete
I have found the answer after connecting with Azure Support.
The resource type: Microsoft.Sql/servers/auditingPolicies is no longer supported and in the next few weeks Azure Resource Manager will no longer support this completely.
This resource type refers directly to table auditing, which has been reported as being deprecated for blob auditing. Though the documentation at this time does not directly report it. The docs will be updated in the coming days after this post, by the owners.
To enable the auditing you need to use the Microsoft.Sql/servers/auditingSettings object. The documentation on this is coming and until it does you will be directed to documentation for the database version of this resource type Microsoft.Sql/servers/databases/auditingSettings.
Auditing settings work much like the Auto-Tuning advisors. You can set either server or database level settings. The server settings will be inherited by the database if the database has not been configured directly.
This is a sample of the auditingSettings object that I use instead of the auditingPolicies object above. It is nested just the same.
{
"apiVersion": "2017-03-01-preview",
"type": "auditingSettings",
"name": "DefaultAuditingSettings",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', concat(variables('db-service-name'), parameters('app-friendly-names')[copyIndex()]))]",
"storageCopy"
],
"properties": {
"state": "Enabled",
"storageEndpoint": "[reference(concat('Microsoft.Storage/storageAccounts', '/', variables('storage-name'), parameters('app-friendly-names')[copyIndex()]), '2018-02-01').primaryEndpoints.blob]",
"storageAccountAccessKey": "[listKeys(concat(variables('storage-name'), parameters('app-friendly-names')[copyIndex()]), '2018-02-01').keys[0].value]",
"storageAccountSubscriptionId": "[subscription().subscriptionId]",
"isStorageSecondaryKeyInUse": false,
"retentionDays": "30"
}
}

how to debug dotnet application with running parameter

I can run from command line. But if I try to run in vscode, how to add parameter in launch.json? I am running on .dotnet 2.0
dotnet run --kestrelTransport Libuv
If running from vscode, how should I configure launch.json?
The demo launch.json is attached below.
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/Benchmarks.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
You can replace
"args": [],
with
"args": ["--kestrelTransport", "Libuv"],

Run grunt task with target/argument in VSCode

I have VSCode version 1.18.1, and this in my Gruntfile.js
grunt.registerTask('release', 'Release process', function(target) {
...
}
The target is there so that I can run grunt release:one or grunt release:two. However, I can't figure out how to make VSCode run the task with the one|two target.
This is tasks.json file VSCode created with Grunt task auto detected.
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "grunt",
"task": "release",
"problemMatcher": [],
"label": "Release Process",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
If I put release:one to the task attribute of the tasks.json file, VSCode will complain with something like
Error: The grunt task detection didn't contribute a task for the following configuration:
Anyone has done something similar to this? Can you please guide me on how to do it?
Thank you!
The way I solved this issue myself was by creating a Task of type shell instead, and putting in the full command. For example, you can do following:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "Release one",
"command": "grunt release:one",
"problemMatcher": [],
}, {
"type": "shell",
"label": "Release two",
"command": "grunt release:two",
"problemMatcher": [],
}
]
}

Resources