I am trying to upgrade a .NET Core 3.1 Azure Functions v3 function to use .NET 7 and Azure Functions v4.
I am following the guide from Microsoft here.
Old .csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.5" />
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.4.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="1.3.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.3" />
<PackageReference Include="RestSharp" Version="106.10.1" />
<PackageReference Include="Sendgrid" Version="9.12.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
New .csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.5" />
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.4.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="1.3.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.10.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="RestSharp" Version="106.10.1" />
<PackageReference Include="Sendgrid" Version="9.12.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
</ItemGroup>
</Project>
I have also created a Program.cs
using Microsoft.Extensions.Hosting;
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.Build();
host.Run();
But whenever I try to Debug through Visual Studio I am greeted with the following errors. I am not using Visual Studio Code.
Can't determine project language from files. Please use one of [--csharp, --javascript]
No job functions found. Try making your job classes and methods public. If you're using extensions e.g Azure Storage, ServiceBus etc.) make sure you've called the registration method for the exteion in your startup code (e.g builder.AddAzureStorage() etc.)
The 'User' function is in error: Invalid script file name configuration. The 'scriptFile' property is set to a file that does not exist.
All the functions are HTTP triggers so I don't believe I need to add any start-up code, plus I don't have any so where would this go?
Well the script file error makes sense as I can see the output file is looking for a DLL but with the upgrade not producing an .exe how on earth do I update this, these files are all generated by the compiler?
Any advice would be greatly appreciated. To confirm I can create a new function from the template and run it without any error.