How to run Azure Function locally within Visual St

2019-05-06 15:41发布

I have a C# library Azure Function (v1 .Net Framework 4.6.1) developed in Visual Studio.

I want to run this locally within Visual Studio on HTTPS. How can I achieve this?

I have set my application arguments as follows:

host start --port 7112 --pause-on-error --useHttps --cors * 

Adding --usehttps results in the application not starting correctly.

When the application starts it asks if I want to install a certificate, I click yes.

Then console window shows this and the application doesnt seem to load correctly - the final message just keeps repeating.

Listening on https://localhost:7112/
Hit CTRL-C to exit...
[10/07/2018 15:52:58] Reading host configuration file 'C:\GTFS\Girlguiding\Gapconsulting.Girlguiding.MSCRM\Gapconsulting.Girlguiding.MSCRM.Companion.Server\bin\Debug\net461\host.json'
[10/07/2018 15:52:58] Host configuration file read:
[10/07/2018 15:52:58] {}
The host is taking longer than expected to start.

(Aside; I am trying to do this because I think it might help with this).

2条回答
家丑人穷心不美
2楼-- · 2019-05-06 16:21

Please try creating a test cert using following commands in powershell

$cert = New-SelfSignedCertificate -Subject localhost -DnsName localhost -FriendlyName "Functions Development" -KeyUsage DigitalSignature -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.1")

Export-PfxCertificate -Cert $cert -FilePath certificate.pfx -Password (ConvertTo-SecureString -String <password> -Force -AsPlainText)

and here is the command to start functions host

func host start --port 7112 --useHttps --cors * --cert certificate.pfx --password <password>
查看更多
叛逆
3楼-- · 2019-05-06 16:33

After struggling for some time, I have found a workaround using ngrok.

Piotr Stapp describes the process.

Run .\ngrok authtoken aaa to generate a config file. Its location will be printed as output...replace content with following:

tunnels:  
  azurefunction:
    proto: http
    addr: 7071
    host_header: localhost

Run your Azure function on localhost from Visual Studio with F5 and in PowerShell (or cmd) type:

.\ngrok.exe start azurefunction

查看更多
登录 后发表回答