dotnet / vblang

The home for design of the Visual Basic .NET programming language and runtime library.
288 stars 66 forks source link

VB.NET in Azure Functions #475

Open InteXX opened 5 years ago

InteXX commented 5 years ago

FYI I was able to get a pure-VB.NET Azure Function working. It was pretty simple, really—here's what I did:

  1. Created a C# sample using this guidance

  2. Created a new VB.NET project (in .NET Standard 2.0 instead of .NET Core 2.2—I ran into missing dependency problems while trying it in Core)

  3. Converted the C# sample class using Telerik's Code Converter

  4. Added the converted code to the VB.NET project (being careful to remove the redundant namespace declaration)

  5. Per this advice, added the AzureFunctionsVersion element to the VB.NET project's XML:

    <PropertyGroup>
      <RootNamespace>FunctionApp1</RootNamespace>
      <TargetFramework>netstandard2.0</TargetFramework>
      <AzureFunctionsVersion>v2</AzureFunctionsVersion>
    </PropertyGroup>
  6. Published and tested as normal

If you're using WebDeploy (uncheck the 'Run from package file' checkbox at first publish), you'll see a warning during deployment:

Could not evaluate 'Microsoft.CSharp.dll' for extension metadata. Exception message: Could not load file or assembly 'Microsoft.CSharp, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

This warning can be safely ignored. Best guess, the assembly is probably only necessary as an interpreter for C# Script functions.

Due to my limited bandwidth I can only publish via WebDeploy, so I'm not aware of whether the warning occurs during a ZipDeploy (checking the Package checkbox).

And there we have it—an Azure Function in pure VB.NET.

aarondglover commented 4 years ago

Does the local debugger and such work?

InteXX commented 4 years ago

Yes.

aarondglover commented 4 years ago

No that I expect it to change but have your tested with azure function be (and .net core 3.1?)

InteXX commented 4 years ago

I haven't.

rrvenki commented 4 years ago

No that I expect it to change but have your tested with azure function be (and .net core 3.1?)

Perhaps I did not clearly understand what @aarondglover asks, but I'm converted full C# based azure function into full VB.NET with .NET Core 3.1 and test it, deploy it in App Service also.

aarondglover commented 4 years ago

I meant to say "Azure Function 3.0 (and .NET Core 3.1)"

aarondglover commented 4 years ago

@InteXX or @rrvenki

Can either of you please publish an empty/sample project to GitHub which I can clone to get started?

InteXX commented 4 years ago

@aarondglover

Did you run into problems with the steps above? They may be in need of revision if so.

InteXX commented 4 years ago

@aarondglover

How did you fare with this? Were you able to get it working?

rrvenki commented 4 years ago

@aarondglover if you require a simple sample Azure functions project in VB I can share it.

InteXX commented 4 years ago

@rrvenki

Thank you, yes please.

SilverfoxSystems commented 4 years ago

ahh.. Finally... I've ended up using a different approach. Here's my result:


2020-05-08T18:45:40.538 [Info] Function started (Id=XXXXXXXX-XXXX-XXXX-XXXX-cbc5XXXXX7)
2020-05-08T18:45:40.538 [Info] VB 64bit (Framework 4.8) HTTP trigger function processed a request.
2020-05-08T18:45:40.538 [Info] Function completed (Success, Id=XXXXXXXX-XXXX-XXXX-XXXX-cbc5XXXXX7, Duration=10ms)
InteXX commented 4 years ago

@SilverfoxSystems

Could you provide some more detail?

SilverfoxSystems commented 4 years ago

I've created a new function in VS2019 and there I've examined the "MS.NET.Sdk.Functions" package. Using VS2015, I created a Class Library and manually imported each package from the mentioned package. Converted the VS2019 C# code into VB and so on... Further details (and maybe a step-by-step procedure) will be available on my website.

InteXX commented 4 years ago

I found this:

http://silverfox.systems/

Will you be publishing something there?

SilverfoxSystems commented 4 years ago

Yes, that's it. I will notify you here when it will be ready.

InteXX commented 4 years ago

@SilverfoxSystems

Sounds good, thanks. I'm looking forward to it.

SilverfoxSystems commented 4 years ago

There we go:

http://silverfox.systems/Azure_VB_Function.aspx

The page still needs a bit of styling, but it'll do for now... You're welcome.

InteXX commented 4 years ago

@SilverfoxSystems

Looks good, I like it!

I think I'm going to work up a template based on this. With your permission, of course.

SilverfoxSystems commented 4 years ago

@InteXX Sure, go ahead... I'm considering automating the whole process myself.

SilverfoxSystems commented 4 years ago

Oh man, thanks for the donation there! Fair play to you, it's really gonna help me out in my current situation.

SilverfoxSystems commented 4 years ago

I think I'm going to work up a template based on this.

Why should C# coders have it any more comfortable anyway :)

SilverfoxSystems commented 4 years ago

I've added a repo, if someone's interested...

Padanian commented 4 years ago

Watched and starred. I'll fork it in the next few days. Thanks

SilverfoxSystems commented 4 years ago

Watched and starred. I'll fork it in the next few days. Thanks

Good man! You're welcome.

Padanian commented 4 years ago

for as much as I would be interested, I'm not even considering an ecosystem that carries along 49 (fortynine) dlls for a hello world proof of concept. A 12kb executable carries along 23MB of libraries and descriptors. Thanks, but no thanks.

InteXX commented 4 years ago

@Padanian

That's Azure Functions for you ;-)

paul1956 commented 4 years ago

@Padanian That is only if you don't use Pack, with Core 5.0 the total app of Hello World size is 155KB on Windows.

InteXX commented 4 years ago

@paul1956

Are you referring to this?

paul1956 commented 4 years ago

@InteXX never mind it is smaller but not that small. The feature is PublishTrimmed

InteXX commented 4 years ago

@paul1956

OK, got it.

Padanian commented 4 years ago

Sorry to disappoint you, The OP repository is for net fw 48. Compiling the project, without even touching it, it generates 76 files, 23MBs in total in 10 folders. I decorated it with a console app, which is 12kb.

paul1956 commented 4 years ago

@Padanian try using TryConvert to make is a Core project it does an excellent job or try Core 5.

InteXX commented 4 years ago

@Padanian

These are the dependencies for an Azure Functions Core 3.1 project (VB or C#). They can be found in the local cache at %UserProfile%\.nuget\packages.

microsoft.net.sdk.functions                                         6.38 MB
  Microsoft.Azure.WebJobs                                           1.71 MB
  Microsoft.Azure.WebJobs.Extensions                                0.35 MB
  Microsoft.Azure.WebJobs.Extensions.Http                           0.29 MB
  Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator       12.10 MB
  Newtonsoft.Json                                                  72.00 MB
                                                             ---------------
  Total                                                            92.83 MB

That said, I'm not sure why the FW 4.8 repo in question calls for sixty-three packages in its Packages.config file. I did a nuget restore just now and it brought in 392 MB worth.

SilverfoxSystems commented 4 years ago

Compiling the project, without even touching it, it generates 76 files, 23MBs in total in 10 folders.

Please complete steps 4. and 4a. on my updated page and see how that helps :)

I will probably update the git repo soon.

Padanian commented 4 years ago

Ok, wait for the repo to update

SilverfoxSystems commented 4 years ago

What I was trying to point out: You only need to upload "Function Test VB.dll" , "Function Test VB.dll.config" and the two JSON files (Function1\function.json and host.json) for the function to work, bringing the zip file size down to 6kB. I guess the other DLLs are there only for compilation and local testing. Apparently they exist in the AZ Functions infrastructure itself.

rrvenki commented 4 years ago

@rrvenki

Thank you, yes please. @aarondglover I'm sorry i'm too late to see your comment. Let me know how to send to you i'll send you a working project for Azure Functions in VB.NET

consciouspnm commented 3 years ago

Does this still work in VS2019 with the latest libraries? The C# example now seems to differ from the one @SilverfoxSystems used.

InteXX commented 3 years ago

@consciouspnm

Would you try the package found here and let me know if it works for you.

consciouspnm commented 3 years ago

Ok, what project type did you use for VB from the original post?

InteXX commented 3 years ago

.NET Standard 2.0, if I recall correctly. The package uses netcoreapp3.1.

consciouspnm commented 3 years ago

I meant did you pick a Console App, Webjob template, Class Library etc.

InteXX commented 3 years ago

No need to pick a project type—the template provides it for you.

Installation instructions are at the repo.

consciouspnm commented 3 years ago

The template works, though I'd still be interested in which one you picked from the default list when you first tried this as I don't have one called .NET Standard unless it comes from somewhere else.

InteXX commented 3 years ago

You should be able to find it like so:

image