Reputation: 729
I wrote a simple Azure Function from the template using the .NET CORE 3.1 as target framework.
After that I migrated the target framework to .NET 5.0 using the guide
After the migration I'm not able to debug the Azure Function. I get the usual message "the breakpoint will not currently be hit".
The csproj is this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
local.settings.json is this:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
}
}
program.cs is this:
class Program
{
static Task Main(string[] args)
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(s =>
{
})
.Build();
return host.RunAsync();
}
}
The simple function is:
using System.Threading.Tasks;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
namespace FunctionAppNet50
{
public static class Function1
{
[Function("Function1")]
public static async Task<HttpResponseData> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req)
{
var response = req.CreateResponse(System.Net.HttpStatusCode.OK);
return response;
}
}
}
Is this related to the ".NET isolated process" model or did I do something wrong?
Upvotes: 1
Views: 1133
Reputation: 729
Thanks... found the solution in the suggested articles by marc_c and Douglas.
I installed the Azure Function Core Tools using choco with the command "choco install azure-functions-core-tools-3";
run the function in a shell with "func start –-dotnet-isolated-debug";
attached the debugger at the PID showed in the window
here is an article that similar steps: https://dev.to/kenakamu/debug-net-5-function-with-visual-studio-visual-studio-code-5235
Upvotes: 2