Reputation: 935
I have a build pipeline in azure devops that worked fine for net core 3.1, then I upgraded this project to .net 5.0 and the build doesn't work anymore, it stops on the nuget restore step
this is the error log
MSBuild auto-detection: using msbuild version '16.200.19.31001' from 'D:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
MSBuild P2P timeout [ms]: 120000
D:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\bin\msbuild.exe "C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp\NuGetScratch\xbcsorbg.z0f.nugetinputs.targets" /t:GenerateRestoreGraphFile /nologo /nr:false /v:q /p:NuGetRestoreTargets="C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp\NuGetScratch\p0q3isxq.jbq.nugetrestore.targets" /p:RestoreUseCustomAfterTargets="True" /p:RestoreTaskAssemblyFile="C:\agent\_work\_tool\NuGet\5.7.0\x64\nuget.exe" /p:RestoreSolutionDirectory="C:\agent\_work\12\s\Framework\\" /p:RestoreConfigFile="C:\agent\_work\12\Nuget\tempNuGet_1947.config" /p:SolutionDir="C:\agent\_work\12\s\Framework\\" /p:SolutionName="Tenper Core"
NuGet.CommandLine.ExitCodeException: Exception of type 'NuGet.CommandLine.ExitCodeException' was thrown.
at NuGet.CommandLine.MsBuildUtility.<GetProjectReferencesAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NuGet.CommandLine.RestoreCommand.<GetDependencyGraphSpecAsync>d__68.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NuGet.CommandLine.RestoreCommand.<DetermineInputsFromMSBuildAsync>d__63.MoveNext()
##[error]The nuget command failed with exit code(1) and error(C:\agent\_work\_tool\dotnet\sdk\5.0.100-rc.1.20452.10\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(54,5): error MSB4186: Invalid static method invocation syntax: "[MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')". Method '[MSBuild]::GetTargetFrameworkIdentifier' not found. Static method invocation should be of the form: $([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(`a`, `b`)). Check that all parameters are defined, are of the correct type, and are specified in the right order. [C:\agent\_work\12\s\Framework\Interfaces\Interfaces.csproj]
C:\agent\_work\_tool\dotnet\sdk\5.0.100-rc.1.20452.10\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(54,5): error MSB4186: Invalid static method invocation syntax: "[MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')". Method '[MSBuild]::GetTargetFrameworkIdentifier' not found. Static method invocation should be of the form: $([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(`a`, `b`)). Check that all parameters are defined, are of the correct type, and are specified in the right order. [C:\agent\_work\12\s\Framework\DI\DI.csproj]
Upvotes: 1
Views: 5580
Reputation: 1144
I also had a similar issue. I upgraded my project from 3.1 -> 5.0, and the restore option failed. However, I was using the dotnet cli to restore the nuget packages.
Turns out, there was some project called WorkerExtensions.csproj
that was being restored, and was built using 3.1. I'm not sure where this project was referenced at all, as it isn't anywhere in the project I was building.
Project.AzureFunction -> /home/vsts/work/1/s/publish_output/Project.AzureFunction.dll
Determining projects to restore...
Restored /tmp/o0lv1ony.pel/WorkerExtensions.csproj (in 6.89 sec).
WorkerExtensions -> /tmp/o0lv1ony.pel/buildout/Microsoft.Azure.Functions.Worker.Extensions.dll
##[error]/home/vsts/.nuget/packages/microsoft.net.sdk.functions/3.0.11/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): Error : It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '3.1.0' was not found.
- The following frameworks were found:
5.0.8 at [/opt/hostedtoolcache/dotnet/shared/Microsoft.NETCore.App]
The only thing I found close was the Microsoft.Azure.Functions.Worker.Extensions.Http
nuget. After investigation, I still can't figure it out.
Regardless, to get the build working and to deploy it, I included both .NET Core 3.1 and .NET 5 in the YAML as following. I'm hoping to properly address the issue in the future.
# For some reason, Azure Functions still require .NET Core 3.x even with .NET 5. Maybe it won't be needed in the future.
- task: UseDotNet@2
displayName: "Install .NET Core 3.x"
inputs:
version: '3.x'
packageType: sdk
- task: UseDotNet@2
displayName: 'Install .NET 5.x'
inputs:
packageType: sdk
version: '5.x'
Upvotes: 1
Reputation: 28086
Try using Use .net core task
+Dotnet core task
with restore command.
- task: UseDotNet@2
displayName: 'Use .NET Core sdk 5.0.100-rc.1.20452.10'
inputs:
packageType: 'sdk'
version: '5.0.100-rc.1.20452.10'
includePreviewVersions: true
- task: DotNetCoreCLI@2
displayName: 'dotnet restore'
inputs:
command: restore
projects: '**/*.csproj'
It's strongly recommended to use dotnet restore
and dotnet build
tasks for projects that target .net core
. See this statement from Nuget task:
If you are working with .NET Core
or .NET Standard
, use the .NET Core task, which has full support for all package scenarios and it's currently supported by dotnet.
Also, you should use 5.0.100-rc.1.20452.10
in UseDotNet@2
task according to the error message.
Upvotes: 1
Reputation: 5182
The issue arises because the agent you are not using .Net Core sdk 5.0 preview 8.
According to your error log, you are using SDK 5.0.100-rc.1
which is not supported [MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')
.
How to solve this issue:
You can replace your original .Net Core download tasks with the following download task:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '5.0.100-preview.8.20417.9'
includePreviewVersions: true
Then rebuild your pipeline.
Upvotes: 1