Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emcc-props.json leads to wrong path for JsonToItemsTaskFactory.dll #59619

Closed
GeorgeS2019 opened this issue Sep 26, 2021 · 8 comments
Closed

emcc-props.json leads to wrong path for JsonToItemsTaskFactory.dll #59619

GeorgeS2019 opened this issue Sep 26, 2021 · 8 comments
Assignees
Milestone

Comments

@GeorgeS2019
Copy link

GeorgeS2019 commented Sep 26, 2021

When building the project: blazor native

This error happens

Error MSB4175:
The task factory "JsonToItemsTaskFactory.JsonToItemsTaskFactory" could not be loaded from the assembly "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.MonoTargets.Sdk\6.0.0-rtm.21474.5\Sdk..\tasks\net472\JsonToItemsTaskFactory.dll". Could not load file or assembly 'System.Text.Json, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.

net472\JsonToItemsTaskFactory.dll is in the directory

"C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.MonoTargets.Sdk\6.0.0-rtm.21474.5\tasks\net472\JsonToItemsTaskFactory.dll"

instead of

"C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.MonoTargets.Sdk\6.0.0-rtm.21474.5\Sdk..\tasks\net472\JsonToItemsTaskFactory.dll"

The report problem is in the WasmApp.Native.targets line => 408

C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rtm.21474.5\Sdk\WasmApp.Native.targets line => 408

WasmApp.Native.targets line 408

<ReadEmccProps JsonFilePath="$(_WasmRuntimePackSrcDir)emcc-props.json">
  <Output TaskParameter="EmccProperties" ItemName="_EmccPropItems" />
</ReadEmccProps>

The content of emcc-props.json

{
  "items": {
    "EmccProperties": [
      { "identity": "RuntimeEmccVersion",     "value": "2.0.23" },
      { "identity": "RuntimeEmccVersionRaw",  "value": "emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 2.0.23 (b15ca40ca02f469de3bf9a4de67a2655aede8974)" },
      { "identity": "RuntimeEmccVersionHash", "value": "b15ca40ca02f469de3bf9a4de67a2655aede8974" }
    ]
  }
}

Configuration

6.0.0-rtm.21474.5
VS Enterprise 2022 preview (64bit) version 17.0.0 Preview 4.1

Regression?

Other information

@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels Sep 26, 2021
@ghost
Copy link

ghost commented Sep 26, 2021

Tagging subscribers to this area: @eiriktsarpalis, @layomia
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Error MSB4175:
The task factory "JsonToItemsTaskFactory.JsonToItemsTaskFactory" could not be loaded from the assembly "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.MonoTargets.Sdk\6.0.0-rtm.21474.5\Sdk..\tasks\net472\JsonToItemsTaskFactory.dll". Could not load file or assembly 'System.Text.Json, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.

net472\JsonToItemsTaskFactory.dll is in the directory

"C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.MonoTargets.Sdk\6.0.0-rtm.21474.5\tasks\net472\JsonToItemsTaskFactory.dll"

instead of

"C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.MonoTargets.Sdk\6.0.0-rtm.21474.5\Sdk..\tasks\net472\JsonToItemsTaskFactory.dll"

The report problem is in the WasmApp.Native.targets line => 408

C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rtm.21474.5\Sdk\WasmApp.Native.targets line => 408

WasmApp.Native.targets line 408

<ReadEmccProps JsonFilePath="$(_WasmRuntimePackSrcDir)emcc-props.json">
  <Output TaskParameter="EmccProperties" ItemName="_EmccPropItems" />
</ReadEmccProps>

The content of emcc-props.json

{
  "items": {
    "EmccProperties": [
      { "identity": "RuntimeEmccVersion",     "value": "2.0.23" },
      { "identity": "RuntimeEmccVersionRaw",  "value": "emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 2.0.23 (b15ca40ca02f469de3bf9a4de67a2655aede8974)" },
      { "identity": "RuntimeEmccVersionHash", "value": "b15ca40ca02f469de3bf9a4de67a2655aede8974" }
    ]
  }
}

Configuration

6.0.0-rtm.21474.5
VS Enterprise 2022 preview (64bit) version 17.0.0 Preview 4.1

Regression?

Other information

Author: GeorgeS2019
Assignees: -
Labels:

area-System.Text.Json, untriaged

Milestone: -

@mattleibow
Copy link
Member

mattleibow commented Sep 27, 2021

We are also getting this on Windows now after bumping the SDK: dotnet/maui#2659

However, we are using the full msbuild to build the solution - which is what the IDE uses. This does not seem to be a problem on macOS.

@eiriktsarpalis
Copy link
Member

cc @lewing. Not sure what the appropriate area label might be for this one.

@lewing lewing added area-Build-mono and removed untriaged New issue has not been triaged by the area owner area-System.Text.Json labels Sep 27, 2021
@lewing lewing added this to the 6.0.0 milestone Sep 27, 2021
@lambdageek
Copy link
Member

lambdageek commented Sep 27, 2021

/cc @steveisok I might need help investigating this one. We might need to either include STJ with the task or use one that is already with Visual Studio MSBuild

@radical radical removed their assignment Sep 27, 2021
@mattleibow
Copy link
Member

I figured out the issue. It is because the public preview of VS/MSBuild has older dlls. It works locally for me because I am also running the main build of VS.

However, since we use the public previews of VS on CI, I created this script to update the dlls in place in a VS install. I believe this goes away once P5 of VS is released: https://github.com/dotnet/maui/blob/2c1b919cf5132262a2328adba59a67141d0f12d0/eng/scripts/patch-vs.ps1

@lambdageek
Copy link
Member

tl;dr - @mattleibow is right this is gonna be fixed by VS2022 Preview 5.


Details:

  • There are 2 versions of MSBuild: a modern one using .NET 6 libraries that runs when you use the dotnet build CLI; and a .NET Framework 4.x MSBuild that ships with Visual Studio
  • When MSBuild loads tasks, they go into the same process and should also be either the net6 or net472 versions.
  • So when we build the Microsoft.NET.Runtime.MonoTargets.Sdk nuget, we put two copies of the tasks in there. Fore net6 and for net472
  • System.Text.Json is part of the .NET 6 runtime, but on .NET Framework it's an extra assembly. MSBuild doesn't know anything about nuget, so we bundle this assembly with the net472 task.
  • Visual Studio MSBuild also bundles System.Text.Json now because it uses it internally for something.
  • When we build Microsoft.NET.Runtime.MonoTargets.Sdk it includes 2 task assemblies: RuntimeConfigParser.dll and JsonToItemsTaskFactory.dll
  • Both our assemblies depend on System.Text.Json - JsonToItemsTaskFactory explicitly, and RuntimeConfigParser.dll implicitly through its dependency on MSBuild.
  • When we put the Microsoft.NET.Runtime.MonoTargets.Sdk.nupkg together we copy files from a build directory into a package directory
  • RuntimeConfigParser implicitly depends on STJ 4.0.1 apparently; but JsonToItemsTaskFactory explicitly depends on 5.0.0.
  • For whatever reason we copy the STJ (4.0.1) from the RuntimeConfigParser build dir into the package (probably it just happens to copy it second).
  • When we install the runtime pack, we end up in a situation where JsonToItemsTaskFactory has a reference to STJ 5.0.0, but next to it on disk is STJ 4.0.1
  • With VS 2022 Preview 4 this is a problem because MSBuild in that preview bundles STJ 4.0.1, too. So there's nowhere to find STJ 5.0.0. So the JsonToItemsTaskFactory assembly can't be loaded.
  • But with VS 2022 Preview 5, MSBuild started to bundle STJ 5.0.0. So when we try to load the JsonToItemsTaskFactory.dll it will resolve the reference for STJ 5.0.0 to the one that is in the MSBuild directory. So the assembly is loaded and life goes on.

I discussed with @steveisok and we think it's too risky to change how the runtime is packaging JsonToItemsTaskFactory.dll and RuntimeConfigParser.dll tasks for .NET 6 RTM.

For .NET 7+ we need to:

  • (good) Ship the version of STJ that JsonToItemsTaskFactory actually needs.
  • (Better) don't create a situation where RuntimeConfigParser and JsonToItemsTaskFactory need different assemblies. Actually just package both tasks into a single assembly. That will also speed up builds a little because there is fewer DLLs to load.
  • (best) there's also something going on where we bundle a copy of Microsoft.Build.dll into the net472 (but not the net6) tasks directory. Stop doing that.

@lambdageek lambdageek modified the milestones: 6.0.0, 7.0.0 Sep 29, 2021
lambdageek added a commit to lambdageek/runtime that referenced this issue Sep 29, 2021
…Sdk pack

Instead of 3 assemblies for some tiny tasks.

Building a single assembly also ensures that everything in the pack depends on
and bundles identical versions of dependent assemblies.  For example on net472,
a single version of System.Text.Json with a single fixed version shared by both
the JsonToItemsTaskFactory task factory and the RuntimeConfigParser task.

Related to dotnet#59619
lambdageek added a commit that referenced this issue Sep 30, 2021
…gets.Sdk pack (#59720)

* Build one MonoTargetsTasks assembly for Mono.NET.Runtime.MonoTargets.Sdk pack

   Instead of 3 assemblies for some tiny tasks.

   Building a single assembly also ensures that everything in the pack depends on and bundles identical versions of dependent assemblies.  For example on net472, a single version of System.Text.Json with a single fixed version shared by both the JsonToItemsTaskFactory task factory and the RuntimeConfigParser task.

   Related to #59619

* Update testing and wasm to use MonoTargetsTasks.dll

* Move assembly stripper to a separate assembly

   Build it with nullability checking disabled.

   Build the main MonoTargetsTasks assembly with nullability enabled

* Don't include msbuild assemblies in MonoTargets package

* re-enable analyzers for the MonoTargetsTasks assembly

* Include *.dll in the MonoTargetsTasks nupkg

   In particular, pick up all the dependent assemblies for the net472 build

* Update various READMEs

* remove unneeded target

* Switch ILStrip to use the same Parallel.ForEach logic as MonoAOTCompiler

* Remove unneeded NoWarn warnings

* rearrange package references in MonoTargetsTask.csproj for readabilty

* More ItemGroup reformatting

* fix nits

* Use SystemThreadingTasksExtensionsVersion instead of hardcoding

Co-authored-by: Ankit Jain <radical@gmail.com>
@GeorgeS2019
Copy link
Author

@mattleibow and other Webssembly experts here.

I need links and milestones which I can follow to eventually port e.g. TorchShrp c++ dlls to WebAssembly in the same way as SkiaSharp native assets

@lambdageek
Copy link
Member

The runtime pack packaging of the tasks was improved in #59720

@ghost ghost locked as resolved and limited conversation to collaborators Aug 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants