Azure / Azure-Functions

1.11k stars 195 forks source link

[VSCode] - Unable to change target framework version after initial selection #860

Open brandonh-msft opened 6 years ago

brandonh-msft commented 6 years ago

When using VS Code + Azure Functions extension, the first time you create a new Azure Function you are prompted whether you want to use the Beta templates or v1 templates. After making this selection, on every subsequent creation of an Azure Function you no longer are prompted for v1 or beta, and instead your previous selection has "stuck" and is (seemingly) unchangeable.

Repro Steps

  1. Perform a fresh installation of VSCode (latest stable) and the Azure Functions extension for VSCode
  2. Create a new Azure Function via the Extension's UI

You'll be prompted to install the templates: image Which then asks you which version: image

Choose either, but take note which one you pick. You'll see in your output window:

Downloading .NET templates for Azure Functions...
Installing "microsoft.azurefunctions.projecttemplates.1.0.3.10168"
Installing "azure.functions.templates.1.0.3.10168"
Finished installing Azure Functions templates.
...
The template "Azure Functions" was created successfully.
Finished running command: "dotnet new azureFunctionsProjectTemplates ".
Using "C#" as the project language...
Using "~1" as the project runtime...
  1. Open a new VSCode workspace in an empty folder
  2. Create a new Azure Function project via the Extension UI, observe you don't get to pick beta or v1

Expected behavior

I'd expect to be prompted each time which type of Function I want to create. Sometimes I may be ok with a beta/preview Function runtime, other times I may be creating one for production and therefore want to be using v1/stable. This is consistent with how VS2017 prompts the user each time upon Function Project Creation.

Workarounds

One must uninstall the templates before creating a new Azure Function Project that targets a different Functions SDK version.

ahmelsayed commented 6 years ago

You can change that using ctrl + shift + p -> Azure Functions: Install/Uninstall templates for .NET CLI

jeffhollan commented 6 years ago

Currently the version is stored as a user setting in the project / workspace. You should be able to see it / change it by navigating to the .vscode/settings.json file under the azureFunctions.projectRuntime setting.

jeffhollan commented 6 years ago

@brandonh-msft let me know if that setting doesn't give you the config you needed

brandonh-msft commented 6 years ago

My 2 cents:

jeffhollan commented 6 years ago

I don’t think you have to reinstall templates to select new runtime. Updating or choosing setting should be enough.

Agree this setting is likely not discoverable as this seems to be a common ask - however in general switching version after a project is already created is general discouraged (also why VS doesn’t allow you to change after initial create) given the number of breaks between versions. So in that sense the behavior is consistent.

I think one challenge here is I expect you are adding multiple functions in the same folder/workspace - where maybe the prompt doesn’t come up every time? Not sure what behavior is today but I believe whenever you create a new app in a new folder you get the version selector, not sure what behavior is if adding new app in existing folder with other apps (based on fact it’s storing project settings in workspace settings I suspect may not prompt as originally reported). Potentially that is something we can track. @fiveisprime to check out issue and weigh in

brandonh-msft commented 6 years ago

@jeffhollan in this case we're not changing the runtime afterwards, we simply want to be able to create a v1 Function project today, then create a v2 Function project tomorrow.

If you create a new proj in a new folder you are not prompted for functions version again; it uses what you selected the first time you did it. to get prompted again you must uninstall the "templates" I'll add an additional step before 3 above: "create an empty workspace in an empty folder"

jeffhollan commented 6 years ago

Ah yes that does sound like not the desired behavior. @fiveisprime can we track to provide behavior what @brandonh-msft described as that does sound like what should occur.

ejizba commented 6 years ago

So yeah VS Code's current behavior assumes users only have one version of the runtime installed on their machine and it always uses the runtime on their path. To that end, we recently did some work so that we will automatically detect the version of the runtime installed locally and use that for the templates rather than prompting as you described. This feature was not released yet, but we were trying to fix the scenario where the user picks the wrong runtime that didn't match what was on their path.

I tried the VS experience and it seems they will install both versions of the runtime side by side and use whichever version of the runtime matches your opened project. It feels like we would have to implement this if we were to prompt for the runtime every time. Before we make that investment, I'd love to get some data (from VS or from Azure) in terms of how many people actually use both runtimes. Do you guys have any idea? We've admittedly prioritized the cross-plat scenario in VS Code, which is obviously only one runtime

brandonh-msft commented 6 years ago

I'd add that not only will VS detect the runtime of the open project, you can create a project for either runtime; it prompts during the New Project wizard.

I'd also argue it's worth the investment now as today's beta is tomorrow's GA so you'll likely hit this in the future anyway ;)

jeffhollan commented 6 years ago

Yes I’m piecing together where I misunderstood previously. The challenge is VS today actually installs BOTH versions today as part of extension and they then call. VS Code expects the core tools to already exist and just calls “func.” Since VS Code isn’t actually in charge of the bits like VS is I see why it exists as it does today. In fact I think it’s safe to say VS Code as a whole doesn’t really ever install libraries or CLIs but just interfaces with them (same is true for other azure extensions).

Today the core tools doesn’t provide a way that I know of to have both versions installed - at least automatically (there is no ‘func’ and ‘func-v2’ alias. So likely not realistic to expect BOTH core tools runtimes could exist simultaneously in same machine with rapid switching by project.

@ahmedelnably correct me if wrong here - but given how VS Code interacts with core tools and how core tools distributed each version as an independent package (via NPM for example) I’m not exactly sure if or how VS Code could enable switching without installing its own copy of binaries like what VS does (which I expect is outside the scope of an extension)

ahmedelnably commented 6 years ago

Mentioning the right @ahmelsayed

ahmelsayed commented 6 years ago

Yes, they'll have to do something similar to what VS is doing to support both on Windows.

If I had to make the call, I'd say vscode should only support v2 apps. V1 apps are Windows only and you can use VS Community 2017 for that if you really needed to. As we shift the focus to v2, it makes sense to not invest too much in a complicated story for v1

brandonh-msft commented 6 years ago

Rock on, I'm totally not against saying "VS Code is xplat; so only xplat fxns are able to be developed". But I do wonder what that would mean for a v3 of Functions and VS Code...

jeffhollan commented 6 years ago

Yeah I think point in time it is a bit strange as we have both v1 and v2 as "recommended" for different scenarios (v1 is GA, v2 is preview and x-plat). Hopefully in the near future we can just say "all net-new functions should be v2 as it is now GA and x-plat where hopefully this becomes less challenging. In terms of future if/when there may be a v3 we could tackle then.

So for now maybe this is "by design" - we should try to make that user setting of the currently installed runtime a little bit more obvious or potentially even self-discoverable (extension checks to see if core tools installed, and also checks if v1 core tools or v2 core tools and prompts to set or update the app setting accordingly). Open to thoughts on if this issue specifically should stay open and if so what actionable next step is.

nzthiago commented 6 years ago

Think of what caused the initial confusion: getting the choice between the two versions and then not getting it again. Could we add a warning that once you make a choice, that'll install that version, and it'll use that version from then on, and if they want to change they'll have to uninstall the templates + core tools that they chose originally?

brandonh-msft commented 6 years ago

That verbiage is present after first selection, but only as part of the console output during template installation. That said, it's still less desirable than what you get with VS; being able to choose the target framework upon Functions project creation.

ejizba commented 6 years ago

I created an issue in the functions extension repo to improve the messaging: https://github.com/Microsoft/vscode-azurefunctions/issues/432

@brandonh-msft you're welcome to create another issue in our repo specifically for "being able to choose the target framework upon Functions project creation." - but that would be a larger investment on our side and less likely to get done for the reasons above. I'm certainly not opposed to having the issue around and getting people to comment/upvote it to help us prioritize, though.