Skip to content

Multiple function projects

Eric Jizba edited this page Nov 20, 2020 · 6 revisions

The Azure Functions extension for VS Code assumes you have one function project per workspace folder. This assumption affects actions such as "Create new function", "Debug", and "Deploy". You have the following two options to set up your projects for use with the Azure Functions extension.

Option 1: Set default project

Set azureFunctions.projectSubpath to the subpath matching the default project you want to use. All actions mentioned above will automatically use this project going forward.

Option 2: Use multi-root workspace

If you want to run or debug multiple function projects at the same time, use a multi-root workspace. First, create the multi-root workspace:

  1. Open a single project in VS Code.
  2. Select File -> Add Folder to Workspace... to add the second project.
  3. Select File -> Save Workspace As... to create a *.code-workspace file in the parent folder containing both projects.

Once you have your multi-root workspace, you need to configure your projects to run at the same time. Specifically, each project needs to run on a separate port so that there are no conflicts. Follow these steps or check out the sample commits for your language below:

  1. Add a compound launch config to the *.code-workspace file. It should look like this:

    {
        "folders": [
            {
                "path": "app1"
            },
            {
                "path": "app2"
            }
        ],
        "settings": {
            "debug.internalConsoleOptions": "neverOpen"
        },
        "launch": {
            "configurations": [],
            "compounds": [
                {
                    "name": "Attach to both apps",
                    "configurations": [
                        "Attach to app1",
                        "Attach to app2"
                    ]
                }
            ]
        }
    }
  2. Modify one project to use different ports.

    1. Debug port: If you are using a language that attaches to a debug port (as opposed to attaching to a process), change the port specified in your launch.json (The value doesn't really matter as long as it's different from the other project)
    2. Func host port: For all languages, add --port 7072 to the func: host start task in your tasks.json. You may also need to add this in your launch.json. (Again, the port doesn't matter as long as it's different than the default value 7071 used by your other project)
  3. In the debug window, you can now select to run a single project or both projects at the same time:

    Screen Shot 2019-03-28 at 12 05 17 PM

Example commit per language: