0

.Net 6

VS 2022

I have a solution containing an API, Class container, and a WASM application. I was able to publish the API, however when I try and publish the WASM application I receive these errors:

1>Done building project "ForgeCalculator.Web.csproj".
2>------ Publish started: Project: ForgeCalculator.Web, Configuration: Debug Any CPU ------
Determining projects to restore...
C:\Program Files\dotnet\sdk\7.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): Error NETSDK1147: To build this project, the following workloads must be installed: wasm-tools-net6
To install these workloads, run the following command: dotnet workload restore
C:\Program Files\dotnet\sdk\7.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): Error NETSDK1004: Assets file 'C:\Users\dtujo\source\repos\ForgeCalculator.Web\ForgeCalculator.Web\obj\publish\browser-wasm\project.assets.json' not found. Run a NuGet package restore to generate this file.

2>Build failed. Check the Output window for more details.
========== Build: 1 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
========== Build started at 5:07 PM and took 03.533 seconds ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========
========== Publish started at 5:07 PM and took 03.534 seconds ==========

I have done the following: Made sure wasm-tools-net6 was installed Ran dotnet workload restore

When I look inside the obj folder I do not see a publish folder where project.assets.json is supposed to be found. The project.assets.json file is within the object folder itself.

enter image description here

Publish Settings: enter image description here

I can't figure out how either the publish folder is not there or how it isn't being created when I try and publish the application.

Workload list: enter image description here

Dotnet Restore enter image description here

Alphatrazz
  • 33
  • 1
  • 8

2 Answers2

1

The errors you get indicate that the project is missing dependencies or packages that need to be installed or restored in order to successfully build or publish.

You can use the following command to view the list of installed workloads and check if the wasm-tools-net6 workload is installed correctly.

dotnet workload list

If it is missing, you can install it with the following command.

dotnet workload install wasm-tools-net6

The project.assets.json file is generated during the NuGet package restore process, if this file is lost, you need to fix this error from Tools > NuGet Package Manager > Package Manager Console simply run:

dotnet restore

If "dotnet restore" doesn't work, you can try cleaning the solution and rebuilding it.

You can also try some other workarounds mentioned in this thread: Assets file project.assets.json not found. Run a NuGet package restore

workaround 1

  • Visual Studio >> Tools >> Options >> Nuget Manager >> Package Sources
  • Uncheck any third-party package sources.
  • Rebuild the solution.

workaround 2

  • Tool -> NuGet Package Maneger -> Package Manager settings -> click on "Clear all NuGet Cache(s)"
  • dotnet restore

workaround 3

  • select Tool=>Options=>NuGet Package Manager=> Package Sources then uncheck Microsoft Visual Studio Offline Packages Option.
  • open Tool=>NuGet Package Maneger=>Package Manager Console.
  • execute command in PM>dotnet restore.
YurongDai
  • 1,362
  • 1
  • 2
  • 7
  • I have done everything you mentioned and put more screenshots in my post. Question I have is that it is trying to look for the project.assets.json in the obj\publish\browser-wasm folder. My project.assets.json file is just in the obj folder and doesn't have any subfolders. Is something not being run to genereate those publish folders? – Alphatrazz May 16 '23 at 12:56
  • Maybe you can try to solve the problem by cleaning and rebuilding the project. – YurongDai Jun 06 '23 at 09:37
0

Ran into this same exact issue today with the publish directory not existing in the obj folder. Credit to @YurongDai for their suggestions. Since I'm using .NET 7, running dotnet workload install wasm-tools-net7 in Package Manager Console fixed the issue (restart Visual Studio afterwards).

Tangere Apps
  • 216
  • 4
  • 5