azure-functions-dotnet-worker: AzureFunctionsVersion is set to an incompatible version
What version of .NET does your existing project use?
.NET 6
What version of .NET are you attempting to target?
.NET 8
Description
I’m trying to upgrade my second Function App project from .net 6 (in-process) to .net 8 (isolated). The first one succeeded, but the second no matter what I’ve tried has an error "AzureFunctionsVersion is set to an incompatible version".
The error is coming from C:\Users\<user>\.nuget\packages\microsoft.azure.functions.worker.sdk\1.17.2\build\Microsoft.Azure.Functions.Worker.Sdk.targets
This section:
<Target Name="_FunctionsPreBuild" BeforeTargets="BeforeBuild">
<Message Condition="'$(_AzureFunctionsNotSet)' == 'true'" Importance="high" Text="AzureFunctionsVersion not configured in the project. Setting AzureFunctionsVersion to v3"/>
<Error Condition="$(AzureFunctionsVersion.StartsWith('v1',StringComparison.OrdinalIgnoreCase))" Text="AzureFunctionsVersion is set to an incompatible version, Please set it to v4"/>
<Error Condition="$(AzureFunctionsVersion.StartsWith('v2',StringComparison.OrdinalIgnoreCase))" Text="AzureFunctionsVersion is set to an incompatible version, Please set it to v3"/>
<Error Condition="!$(AzureFunctionsVersion.StartsWith('v3',StringComparison.OrdinalIgnoreCase)) And !$(AzureFunctionsVersion.StartsWith('v4',StringComparison.OrdinalIgnoreCase))" Text="AzureFunctionsVersion is set to an incompatible version"/>
<Error Condition="'$(_ToolingSuffix)' == ''" Text="Invalid combination of TargetFramework and AzureFunctionsVersion is set."/>
<Error Condition="'$(_IsFunctionsSdkBuild)' == 'true'" Text="Microsoft.NET.Sdk.Functions package is meant to be used with in-proc function apps. Please remove the reference to this package in isolated function apps."/>
</Target>
As an experiment I put <Error Condition="true" Text="$(AzureFunctionsVersion)"/> at the top of the section and my first, working project is spitting out “v4”, but the second, failing project is spitting out “v0”!
The failing project csproj’s contents are attached but it has always had a value of v4 - it wasn’t changed by the upgrade assistant.
I tried copying the contents of csproj from of the working project and it still fails.
I tried unloading the first project; I tried cleaning the solution; deleting the .vs file for the sln; and deleting the bin and obj folders but that didn’t help.
I did see some strange warnings:
Severity Code Description Project File Line Suppression State Details
Warning (active) MSB4011 "C:\Program Files\dotnet\sdk\8.0.300-preview.24203.14\Sdks\Microsoft.NET.Sdk.Publish\Sdk\Sdk.props" cannot be imported again. It was already imported at "C:\Users\<user>\.nuget\packages\microsoft.net.sdk.functions\4.4.0\build\Microsoft.NET.Sdk.Functions.Publish.props (13,3)". This is most likely a build authoring error. This subsequent import will be ignored. [(path to).csproj] ProjectName C:\Users\<user>\.nuget\packages\microsoft.azure.functions.worker.sdk\1.17.2\build\Microsoft.Azure.Functions.Worker.Sdk.Publish.props 13
Warning (active) MSB4011 "C:\Program Files\dotnet\sdk\8.0.300-preview.24203.14\Sdks\Microsoft.NET.Sdk.Publish\Sdk\Sdk.targets" cannot be imported again. It was already imported at "C:\Users\<user>\.nuget\packages\microsoft.net.sdk.functions\4.4.0\build\Microsoft.NET.Sdk.Functions.Publish.targets (14,3)". This is most likely a build authoring error. This subsequent import will be ignored. [(path to).csproj] ProjectName C:\Users\<user>\.nuget\packages\microsoft.azure.functions.worker.sdk\1.17.2\build\Microsoft.Azure.Functions.Worker.Sdk.Publish.targets 15
Warning (active) MSB4011 "C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VisualStudio\Managed.Functions\Microsoft.Azure.Functions.Designtime.targets" cannot be imported again. It was already imported at "C:\Users\<user>\.nuget\packages\microsoft.net.sdk.functions\4.4.0\build\Microsoft.NET.Sdk.Functions.targets (65,3)". This is most likely a build authoring error. This subsequent import will be ignored. [(path to).csproj] ProjectName C:\Users\<user>\.nuget\packages\microsoft.azure.functions.worker.sdk\1.17.2\build\Microsoft.Azure.Functions.Worker.Sdk.targets 56
Project configuration and dependencies
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<UserSecretsId>(snipped)</UserSecretsId>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.4.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.2" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.22.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.1" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.2.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>
Link to a repository that reproduces the issue
No response
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 16 (3 by maintainers)
You should not be having a package reference to
Microsoft.NET.Sdk.Functionspackage in an isolated function. That package is for in-proc model apps.I suggest you to create a brand new .NET Isolated 8 function app using tooling (such as Visual studio) and use that for reference.
The V4 should be with a capital letter, otherwise it will throw the error 😃
Oddly, I had the same issue. I changed ‘v4’ to ‘V4’, which resulted in a clear error being produced, mentioning that ‘Microsoft.NET.Sdk.Functions’ should be removed. I did this, it built fine, and curiously, I can revert my version back to ‘v4’ and it still compiles. Odd.
This category I picked when creating the issue was to raise problems with the .NET Upgrade Assistant. In this case there’s possibly two problems.
Firstly, there’s the addition of
ImplicitUsingincorrectly having a value ofenabledwhen it should beenable(ref but perhaps that is a bug in the Function Apps SDK where it incorrectly expectsenabledand the Upgrade Assistant is having to play along?Secondly, leaving behind incorrect namespace(s) -
Microsoft.NET.Sdk.FunctionsIt seems the combination of these two things caused the error. Both of these are caused by the .NET Upgrade Assistant for Azure Function App projects. Please fix this part of the upgrade assistant.
Turns out the problem might have been that
<ImplicitUsings>should technically beenablebut theMicrosoft.Azure.Functions.Worker.Sdkis expectingenabled. Which isn’t the correct value for normal projects, but if it isn’t set toenabledfor Function Apps, then it breaks things. Seems like a bugAlthough there is an ignore case argument on the FunctionVersion, my error changed when I altered it.
It will no doubt not be a one size fits all example, but uninstalling
.Net.Sdk.Functionspackage and capitalizing theV4are what did it for me, and should be covered with the upgrade assistant.@MathiasSmedemark The check ignores case
!$(AzureFunctionsVersion.StartsWith('v4',StringComparison.OrdinalIgnoreCase))