Dan Parker
Dan Parker

Reputation: 843

Upgrading Azure functions project in Visual Studio

So Azure Functions v2 is out, if I create a new function in azure and set it to V2, but then I publish my old functions project in Visual Studio, it turns it back to V1.

I see if I create a new function project in visual studio, that it will ask me if I want V1 or V2. Is there anyway to upgrade the existing project, or do I have to create a new one? (It's not the end of world if I have to create a new one and copy flies over, but it would be nice)

Upvotes: 3

Views: 1148

Answers (1)

Jerry Liu
Jerry Liu

Reputation: 17790

Azure Function 2.x runtime is based on .NET Core 2 and requires function code to be targeted at .NET Standard. Your old functions are v1 which means their target framework is Full .NET Framework. Even though you set Function runtime version to ~2 on portal, Azure can tell the code is actually for runtime ~1.

I do recommend you to create a template v2 function and compare old content with new v2 template.

  1. Dependencies

    For v2, we need to install extensions for triggers and bindings except http and timer. When we create function project or add single function(right click on project>Add>New Azure Function) in VS, packages of corresponding extensions are installed automatically, we only have to manually install packages for v2 when we use input/output bindings.

  2. Function code

    Due to the difference of target framework, code modification is usually necessary(like type of log is changed from TraceWriter to ILogger).

  3. Configurations

    Check host.json if there are settings related to extensions and log, whose format has changed.

Apart from these changes for us to do manually, there are many feature changes we should pay attention to when migrating to 2.x runtime.

Upvotes: 4

Related Questions