I have created a Queue Trigger function. As mentioned in the microsoft docs, I also added packages "Microsoft.Azure.Functions.Worker", "Microsoft.Azure.Functions.Worker.Sdk" but project is not building, and giving error "Specified condition "$(SelfContained)" evaluates to "" instead of a boolean" in package Microsoft.Azure.Functions.Worker.Sdk.targets. Please see my csproj file below
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.10.4" />
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" Version="5.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="4.0.5" />
<PackageReference Include="SD.Dentaflows.Models" Version="1.1.10" />
</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>
This is my Program.cs class code and My function class code and my main purpose is to use methods of "RequestQueueWritebackHandler" in my function.
public class Program
{
public static void Main(string[] args)
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureAppConfiguration((hostContext, configBuilder) =>
{
configBuilder.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables();
})
.ConfigureServices((hostContext, services) =>
{
services.AddTransient<RequestQueueWritebackFunction>();
services.AddSingleton<IRequestQueueWritebackService, RequestQueueWritebackHandler>();
})
.ConfigureLogging(logging =>
{
logging.SetMinimumLevel(LogLevel.Information);
})
.Build();
host.Run();
}
}
public class RequestQueueWritebackFunction
{
private readonly IRequestQueueWritebackService requestWritebackService;
public RequestQueueWritebackFunction(IRequestQueueWritebackService requestWritebackService)
{
this.requestWritebackService = requestWritebackService;
}
[FunctionName("RequestQueueWritebackFunction")]
public void Run([QueueTrigger("%RequestWritebackQueueName%", Connection = "WritebackConnectionString")] string myQueueItem, ILogger log)
{
log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
var result = requestWritebackService.SaveRequestWritebackMessage();
}
}
You need to create local.settings.json like below: And make change from WritebackConnectionString to AzureWritebackConnectionString