dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.68k stars 1.06k forks source link

NET SDK with Microsoft.VisualStudio.JavaScript.SDK dependency results in System.Text.Json - File not found through when specifying NET SDK Version #39152

Open jonmeyerson opened 7 months ago

jonmeyerson commented 7 months ago

Describe the bug

Building a .NET 6 App that references a Microsoft.VisualStudio.JavaScript.SDK fails on Azure DevOps and produces an error indicating a missing dependency to System.Text.Json

Note: Deploying through Visual Studio 2022 Publish works as expected to Azure Resource.

To Reproduce

A simple project created following the guide here, https://learn.microsoft.com/en-us/visualstudio/javascript/tutorial-asp-net-core-with-vue?view=vs-2022

  1. Started a new project in VS 2022 of type "Vue and ASP.NET Core (Javascript)"
  2. Upgraded Microsoft.VisualStudio.JavaScript.SDK to 1.0.586930
  3. Changed Port in vite.config to match generated port in server. (step does not matter for build)
  4. Created .azureDevops folder with yaml for building the project.
  5. Imported yaml as a new pipeline and run the pipeline.

https://github.com/jonmeyerson/Microsoft.VisualStudio.JavaScript.Sdk-AzureDeploy

Exceptions (if any)

`Build FAILED.

   "D:\a\1\s\AzureDeploymentTest.sln" (Restore target) (1) ->
   "D:\a\1\s\azuredeploymenttest.client\azuredeploymenttest.client.esproj" (_GenerateProjectRestoreGraph target) (3:6) ->
   (GeneratePackageJsonProps target) -> 
     C:\Users\VssAdministrator\.nuget\packages\microsoft.visualstudio.javascript.sdk\1.0.586930\Sdk\Sdk.targets(259,5): error MSB4018: The "GeneratePackageJsonProps" task failed unexpectedly. [D:\a\1\s\azuredeploymenttest.client\azuredeploymenttest.client.esproj]
   C:\Users\VssAdministrator\.nuget\packages\microsoft.visualstudio.javascript.sdk\1.0.586930\Sdk\Sdk.targets(259,5): error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'System.Text.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. [D:\a\1\s\azuredeploymenttest.client\azuredeploymenttest.client.esproj]
   C:\Users\VssAdministrator\.nuget\packages\microsoft.visualstudio.javascript.sdk\1.0.586930\Sdk\Sdk.targets(259,5): error MSB4018: File name: 'System.Text.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' [D:\a\1\s\azuredeploymenttest.client\azuredeploymenttest.client.esproj]
   C:\Users\VssAdministrator\.nuget\packages\microsoft.visualstudio.javascript.sdk\1.0.586930\Sdk\Sdk.targets(259,5): error MSB4018:    at Microsoft.VisualStudio.JavaScript.Tasks.GeneratePackageJsonProps.Execute() [D:\a\1\s\azuredeploymenttest.client\azuredeploymenttest.client.esproj]
   C:\Users\VssAdministrator\.nuget\packages\microsoft.visualstudio.javascript.sdk\1.0.586930\Sdk\Sdk.targets(259,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [D:\a\1\s\azuredeploymenttest.client\azuredeploymenttest.client.esproj]
   C:\Users\VssAdministrator\.nuget\packages\microsoft.visualstudio.javascript.sdk\1.0.586930\Sdk\Sdk.targets(259,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [D:\a\1\s\azuredeploymenttest.client\azuredeploymenttest.client.esproj]

0 Warning(s)
1 Error(s)`

Further technical details

.NET SDK 6.0.419 Microsoft.VisualStudio.JavaScript.Sdk/1.0.586930 dev.azure.com - Azure Devops ( Version Dev19.M234.1 (AzureDevOps_M234_20240228.4) )

baronfel commented 7 months ago

@joj here's another - I've made a new label called 'Area-esproj' for tickets related to the javascript project system. It would be great if your team could periodically check this label for untriaged items.

jonmeyerson commented 7 months ago

This was related to

   - task: UseDotNet@2
      inputs:
        packageType: 'sdk'
        version: '6.0.419'

after removing the explicit SDK version in the yaml pipeline, I followed the workaround here: https://github.com/dotnet/sdk/issues/39148 and it build successfully.

Workaround branch: https://github.com/jonmeyerson/Microsoft.VisualStudio.JavaScript.Sdk-AzureDeploy/tree/workaround

Also, i noticed if i did the build of the client app before setting the sdk version it worked, without https://github.com/dotnet/sdk/issues/39148 - but then the build later on for server that references client would still have the issue. Also, besides the dotnet task, having a global.json in the server project with

{
  "sdk": {
    "version": "6.0.419"
  }
}

Will also indicate the System.Text.Json is not found.

System.IO.FileNotFoundException: Could not load file or assembly 'System.Text.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
File name: 'System.Text.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
   at Microsoft.VisualStudio.JavaScript.Tasks.GeneratePackageJsonProps.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
C:\Users\VssAdministrator\.nuget\packages\microsoft.visualstudio.javascript.sdk\1.0.586930\Sdk\Sdk.targets(259,5): error MSB4018: The "GeneratePackageJsonProps" task failed unexpectedly. [D:\a\1\s\azuredeploymenttest.client\azuredeploymenttest.client.esproj]
C:\Users\VssAdministrator\.nuget\packages\microsoft.visualstudio.javascript.sdk\1.0.586930\Sdk\Sdk.targets(259,5): error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'System.Text.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. [D:\a\1\s\azuredeploymenttest.client\azuredeploymenttest.client.esproj]
C:\Users\VssAdministrator\.nuget\packages\microsoft.visualstudio.javascript.sdk\1.0.586930\Sdk\Sdk.targets(259,5): error MSB4018: File name: 'System.Text.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' [D:\a\1\s\azuredeploymenttest.client\azuredeploymenttest.client.esproj]
C:\Users\VssAdministrator\.nuget\packages\microsoft.visualstudio.javascript.sdk\1.0.586930\Sdk\Sdk.targets(259,5): error MSB4018:    at Microsoft.VisualStudio.JavaScript.Tasks.GeneratePackageJsonProps.Execute() [D:\a\1\s\azuredeploymenttest.client\azuredeploymenttest.client.esproj]
C:\Users\VssAdministrator\.nuget\packages\microsoft.visualstudio.javascript.sdk\1.0.586930\Sdk\Sdk.targets(259,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [D:\a\1\s\azuredeploymenttest.client\azuredeploymenttest.client.esproj]
C:\Users\VssAdministrator\.nuget\packages\microsoft.visualstudio.javascript.sdk\1.0.586930\Sdk\Sdk.targets(259,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [D:\a\1\s\azuredeploymenttest.client\azuredeploymenttest.client.esproj]
lorenyaSICKAG commented 4 months ago

I have the same problem/error, I don't understand the workaround? Can you explain how you got it to work?

jonmeyerson commented 4 months ago

I have the same problem/error, I don't understand the workaround? Can you explain how you got it to work?

You can see the first branch here that has the issue, and the commit that fixes it. https://github.com/jonmeyerson/Microsoft.VisualStudio.JavaScript.Sdk-AzureDeploy/commit/d47af92d67f742700806e3b38d096f66e86d3802

lorenyaSICKAG commented 4 months ago

Unfortunately I don't use Azure Pipelines, but an Dockerfile to build an image with the dotnet application. I only could fix it by upgrading to .NET 8. I don't know if it works with .NET 7 as well, but switching the SDK worked for me. It seems that the .NET 6 SDK have a problem building an Docker image with the JavaScript SDK.

Forgind commented 3 months ago

/cc: @joj

It sounds like this might be resolved in later versions. Can you triage this when you get the chance?

cuongwf1711 commented 3 months ago

I am facing a similar issue. Please help me and provide a solution.

f36ac5ab-e1b8-435c-9f94-f58dd214c3c2