Azure / azure-functions-vs-build-sdk

MSBuild task for Azure Functions
MIT License
96 stars 62 forks source link

Publishing from CMD fails due to Newtonsoft.Json version mismatch #623

Closed Zachwiany closed 5 months ago

Zachwiany commented 5 months ago

Recently I updated my functions dependency Microsoft.NET.Sdk.Functions from version 4.1.1 to 4.2.0, but it cause my publishing script to fail - I'm calling MSBuild command as follows: %MSBUILD% %PROJECT% /t:restore;rebuild /v:m /p:Platform=%PLATFORM% /p:Configuration=%CONFIGURATION% /p:DeployOnBuild=true /p:PublishProfile=%PUBLISH_PROFILE_NAME% /p:Password=%PUBLISH__PROFILE_PASSWORD%

It fails at ZipDeployTask (works fine when run from VS, I guess it uses different task at some point, doesn't work both from CMD and VS command prompt):

error MSB4018: The "ZipDeployTask" task failed unexpectedly. [PROJECT.csproj]
error MSB4018: System.AggregateException: One or more errors occurred. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified. [PROJECT.csproj]
error MSB4018:    at Microsoft.NET.Sdk.Functions.MSBuild.Tasks.ZipDeploymentStatus.GetDeploymentStatusAsync(String deploymentUrl, String userName, String password, Int32 retryCount, TimeSpan retryDelay, CancellationTokenSource cts) [PROJECT.csproj]
error MSB4018:    at Microsoft.NET.Sdk.Functions.MSBuild.Tasks.ZipDeploymentStatus.<PollDeploymentStatusAsync>d__9.MoveNext() in /_/src/Microsoft.NET.Sdk.Functions.MSBuild/Tasks/ZipDeploymentStatus.cs:line 50 [PROJECT.csproj]
error MSB4018: --- End of stack trace from previous location where exception was thrown --- [PROJECT.csproj]
error MSB4018:    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) [PROJECT.csproj]
error MSB4018:    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [PROJECT.csproj]
error MSB4018:    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) [PROJECT.csproj]
error MSB4018:    at Microsoft.NET.Sdk.Functions.Tasks.ZipDeployTask.<ZipDeployAsync>d__26.MoveNext() in /_/src/Microsoft.NET.Sdk.Functions.MSBuild/Tasks/ZipDeployTask.cs:line 111 [PROJECT.csproj]
error MSB4018:    --- End of inner exception stack trace --- [PROJECT.csproj]
error MSB4018:    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) [PROJECT.csproj]
error MSB4018:    at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) [PROJECT.csproj]
error MSB4018:    at Microsoft.NET.Sdk.Functions.Tasks.ZipDeployTask.Execute() in /_/src/Microsoft.NET.Sdk.Functions.MSBuild/Tasks/ZipDeployTask.cs:line 42 [PROJECT.csproj]
error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [PROJECT.csproj]
error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [PROJECT.csproj]
error MSB4018: ---> (Inner Exception #0) System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified. [PROJECT.csproj]
error MSB4018: File name: 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' [PROJECT.csproj]
error MSB4018:    at Microsoft.NET.Sdk.Functions.MSBuild.Tasks.ZipDeploymentStatus.GetDeploymentStatusAsync(String deploymentUrl, String userName, String password, Int32 retryCount, TimeSpan retryDelay, CancellationTokenSource cts) [PROJECT.csproj]
error MSB4018:    at Microsoft.NET.Sdk.Functions.MSBuild.Tasks.ZipDeploymentStatus.<PollDeploymentStatusAsync>d__9.MoveNext() in /_/src/Microsoft.NET.Sdk.Functions.MSBuild/Tasks/ZipDeploymentStatus.cs:line 50 [PROJECT.csproj]
error MSB4018: --- End of stack trace from previous location where exception was thrown --- [PROJECT.csproj]
error MSB4018:    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) [PROJECT.csproj]
error MSB4018:    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [PROJECT.csproj]
error MSB4018:    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) [PROJECT.csproj]
error MSB4018:    at Microsoft.NET.Sdk.Functions.Tasks.ZipDeployTask.<ZipDeployAsync>d__26.MoveNext() in /_/src/Microsoft.NET.Sdk.Functions.MSBuild/Tasks/ZipDeployTask.cs:line 111 [PROJECT.csproj]
error MSB4018:  [PROJECT.csproj]
error MSB4018: Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll [PROJECT.csproj]
error MSB4018: Running under executable  C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe [PROJECT.csproj]
error MSB4018: --- A detailed error log follows.  [PROJECT.csproj]
error MSB4018:  [PROJECT.csproj]
error MSB4018: === Pre-bind state information === [PROJECT.csproj]
error MSB4018: LOG: DisplayName = Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed [PROJECT.csproj]
error MSB4018:  (Fully-specified) [PROJECT.csproj]
error MSB4018: LOG: Appbase = file:///C:/Program Files/Microsoft Visual Studio/2022/Enterprise/MSBuild/Current/Bin/ [PROJECT.csproj]
error MSB4018: LOG: Initial PrivatePath = NULL [PROJECT.csproj]
error MSB4018: Calling assembly : Microsoft.NET.Sdk.Functions.MSBuild, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35. [PROJECT.csproj]
error MSB4018: === [PROJECT.csproj]
error MSB4018: LOG: This bind starts in LoadFrom load context. [PROJECT.csproj]
error MSB4018: WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load(). [PROJECT.csproj]
error MSB4018: LOG: Using application configuration file: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe.Config [PROJECT.csproj]
error MSB4018: LOG: Using host configuration file:  [PROJECT.csproj]
error MSB4018: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. [PROJECT.csproj]
error MSB4018: LOG: Post-policy reference: Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed [PROJECT.csproj]
error MSB4018: LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Enterprise/MSBuild/Current/Bin/Newtonsoft.Json.DLL. [PROJECT.csproj]
error MSB4018: LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Enterprise/MSBuild/Current/Bin/Newtonsoft.Json/Newtonsoft.Json.DLL. [PROJECT.csproj]
error MSB4018: LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Enterprise/MSBuild/Current/Bin/Newtonsoft.Json.EXE. [PROJECT.csproj]
error MSB4018: LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Enterprise/MSBuild/Current/Bin/Newtonsoft.Json/Newtonsoft.Json.EXE. [PROJECT.csproj]
error MSB4018: LOG: Attempting download of new URL file:///USER/.nuget/packages/microsoft.net.sdk.functions/4.2.0/tools/net6.0/Newtonsoft.Json.DLL. [PROJECT.csproj]
error MSB4018: WRN: Comparing the assembly name resulted in the mismatch: Major Version [PROJECT.csproj]
error MSB4018: LOG: Attempting download of new URL file:///USER/.nuget/packages/microsoft.net.sdk.functions/4.2.0/tools/net6.0/Newtonsoft.Json/Newtonsoft.Json.DLL. [PROJECT.csproj]
error MSB4018: LOG: Attempting download of new URL file:///USER/.nuget/packages/microsoft.net.sdk.functions/4.2.0/tools/net6.0/Newtonsoft.Json.EXE. [PROJECT.csproj]
error MSB4018: LOG: Attempting download of new URL file:///USER/.nuget/packages/microsoft.net.sdk.functions/4.2.0/tools/net6.0/Newtonsoft.Json/Newtonsoft.Json.EXE. [PROJECT.csproj]
error MSB4018: <--- [PROJECT.csproj]
error MSB4018:  [PROJECT.csproj]

Each line of call stack started with USER\.nuget\packages\microsoft.net.sdk.functions\4.2.0\build\Microsoft.NET.Sdk.Functions.Publish.ZipDeploy.targets(46,5): - removed it for clarity and replaced user directory name.

I found that in tools directory of the package there is Newtonsoft.Json.dll (version 11. for 4.1.1, 13. for 4.1.2 and later on) and three other dll's. The first one references Newtonsoft.Json.dll using proper version included in the package: image

The second one, which contains failing ZipDeployTask, refers to old version that is no longer there: image

Any fix or workaround?

bhagyshricompany commented 5 months ago

thanks for reporting pls share the funct app name.

microsoft-github-policy-service[bot] commented 5 months ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.