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

msbuild silently ignores workload pack import, if the expected version of the pack is not found #21032

Open
radical opened this issue Sep 15, 2021 · 11 comments
Labels
Area-NetSDK Area-Workloads untriaged Request triage from a team member
Milestone

Comments

@radical
Copy link
Member

radical commented Sep 15, 2021

If I install wasm-tools workload. Then change the version of one of the packs, say packs/Microsoft.NET.Runtime.MonoTargets.Sdk to something other than the one mentioned in WorkloadManifest.json. And build a project that uses this, then dotnet build does not complain about the missing import, and continues on to fail at a later point because of missing properties etc.

To reproduce:

  1. install Wasm-tools workload
  2. mv packs/Microsoft.NET.Runtime.MonoTargets.Sdk/{version} packs/Microsoft.NET.Runtime.MonoTargets.Sdk/1.2.3
  3. dotnet new blazorwasm; dotnet build -p:RunAOTCompilation=true

.. it fails with

/usr/local/share/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/6.0.0-rc.2.21464.21/Sdk/WasmApp.Native.targets(538,39): error MSB4022: The result "" of evaluating the value "$(JsonToItemsTaskFactoryTasksAssemblyPath)" of the "AssemblyFile" attribute in element <UsingTask> is not valid. [/private/tmp/bl-tests/bl2/bl2.csproj]

The log has a single line for that pack - Resolving SDK 'Microsoft.NET.Runtime.MonoTargets.Sdk'....

I can reproduce this with dotnet 6.0.100-rc.2.21463.12.

cc @dsplaisted @sfoslund @rainersigwald @lewing @steveisok

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Sep 15, 2021
@marcpopMSFT marcpopMSFT added this to the 6.0.2xx milestone Sep 15, 2021
@radical radical changed the title msbuild silently ignores pack import, if the expected version of the pack is not found msbuild silently ignores workload pack import, if the expected version of the pack is not found Sep 16, 2021
@cheenamalhotra
Copy link
Member

Our test projects are also severely impacted by this error, as it effects projects building for target .NET Framework 4.6.1 intermittently using Dotnet SDK. Any guidance would be highly appreciated!

##[error]E:\nuget\microsoft.sourcelink.common\1.0.0\build\InitializeSourceControlInformation.targets(3,81): Error MSB4022: The result "" of evaluating the value "$(_MicrosoftSourceLinkCommonAssemblyFile)" of the "AssemblyFile" attribute in element <UsingTask> is not valid.

Logs for reference:
https://dev.azure.com/sqlclientdrivers-ci/sqlclient/_build/results?buildId=40578&view=logs&j=84415923-4175-5328-da83-e82a5e56172c&t=49618473-d27a-53ab-9569-89caaa80fae3&s=d654deb9-056d-50a2-1717-90c08683d50a

@radical
Copy link
Member Author

radical commented Oct 7, 2021

@cheenamalhotra that doesn't seem related to workloads. Please correct me if I'm wrong.
$(_MicrosoftSourceLinkCommonAssemblyFile) is being set in build/Microsoft.SourceLink.Common.props, which should get imported when you reference the package. I would suggest looking at the binlog to confirm that the props file is imported, and see why the property is not getting set.

@cheenamalhotra
Copy link
Member

The props file seems absent in binlog. (Strangely, this happens intermittently)

image

@cheenamalhotra
Copy link
Member

It is although available in NuGet: https://nuget.info/packages/Microsoft.SourceLink.Common/1.0.0

@radical
Copy link
Member Author

radical commented Oct 7, 2021

I would suggest filing an issue in https://github.com/dotnet/sourcelink .

@cheenamalhotra
Copy link
Member

I think there was one issue in that repo: dotnet/sourcelink#644 which seems to be tracked in dotnet/project-system#4781, I didn't get any response from them before so I left those threads.

But due to some reason the props file isn't loading and properties are missing, it seems an underlying msbuild/sdk issue to me.
I can also reproduce this issue fairly well on my laptop, incase anyone is interested to investigate further. Our project is open source and can be easily built to fail in 2 commands (once in 2-3 rounds - error happens)

@dsplaisted
Copy link
Member

The sourcelink error is different from the workload error. It sounds like the sourcelink issue may have to do with how Visual Studio NuGet restore works. If that's the case, then a full restore from the command line might work around the issue.

For the workload failure, what is going on is that the workload missing error comes from running a Target, while the failure about the empty value for AssemblyFile comes from evaluation. So you get the AssemblyFile failure before it gets a chance to tell you about the missing workload.

Is there a scenario where this would happen besides someone manually renaming things in the packs directory?

If you wanted to fix this specific issue, an easy fix might be to move the ReadEmccProps UsingTask from WasmApp.Native.targets to RuntimeComponentManifest.props where the assembly path is defined.

@marcpopMSFT marcpopMSFT modified the milestones: 6.0.2xx, 6.0.3xx Dec 11, 2021
@marcpopMSFT
Copy link
Member

closing older issues as this isn't a mainline scenario. If this is still impacting, please reactivate.

@radical
Copy link
Member Author

radical commented Dec 12, 2022

This is hit on dotnet/runtime#78237 by upgrading from VS 17.3.6 to 17.4.2 . There was no manual renaming done here.

cc @lewing

@radical radical reopened this Dec 12, 2022
@radical
Copy link
Member Author

radical commented Dec 12, 2022

It would be useful to get the errors in such a case.

If you wanted to fix this specific issue, an easy fix might be to move the ReadEmccProps UsingTask from WasmApp.Native.targets to RuntimeComponentManifest.props where the assembly path is defined.

I will backport this fix for 6.0 . We already have this in newer versions.

@radical
Copy link
Member Author

radical commented Dec 12, 2022

It would be useful to get the errors in such a case.

If you wanted to fix this specific issue, an easy fix might be to move the ReadEmccProps UsingTask from WasmApp.Native.targets to RuntimeComponentManifest.props where the assembly path is defined.

I will backport this fix for 6.0 . We already have this in newer versions.

I was mistaken. The fix you suggested would move ReadEmccProps UsingTask (which is for wasm specific case) to MonoTargets sdk, which is used by the mobile workloads too. And that's still the case in 7.0, and main.

I will move the UsingTask to the MonoTargets sdk for 6.0 as a workaround, that would hopefully work.

radical added a commit to radical/runtime that referenced this issue Dec 12, 2022
Upgrading from VS 17.3.6 to 17.4.2 caused wasm project builds to break
with:

```
Unhandled exception: Microsoft.Build.Exceptions.InvalidProjectFileException: The result “” of evaluating the value “$(JsonToItemsTaskFactoryTasksAssemblyPath)” of the “AssemblyFile” attribute in element  is not valid. C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.11\Sdk\WasmApp.Native.targets
    at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
    at Microsoft.Build.Shared.ProjectErrorUtilities.VerifyThrowInvalidProject[T1,T2,T3,T4](Boolean condition, String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, T1 arg0, T2 arg1, T3 arg2, T4 arg3)
    at Microsoft.Build.Shared.ProjectErrorUtilities.VerifyThrowInvalidProject[T1,T2,T3,T4](Boolean condition, IElementLocation elementLocation, String resourceName, T1 arg0, T2 arg1, T3 arg2, T4 arg3)
    at Microsoft.Build.Execution.TaskRegistry.RegisterTasksFromUsingTaskElement[P,I](ILoggingService loggingService, BuildEventContext buildEventContext, String directoryOfImportingFile, ProjectUsingTaskElement projectUsingTaskXml, TaskRegistry taskRegistry, Expander`2 expander, ExpanderOptions expanderOptions, IFileSystem fileSystem) at Microsoft.Build.Evaluation.Evaluator`4.EvaluateUsingTaskElement(String directoryOfImportingFile, ProjectUsingTaskElement projectUsingTaskElement)
    at Microsoft.Build.Evaluation.Evaluator`4.Evaluate() at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(IEvaluatorData`4 data, Project project, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary`1 environmentProperties, ILoggingService loggingService, IItemFactory`2 itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCacheBase projectRootElementCache, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, EvaluationContext evaluationContext, Boolean interactive) at Microsoft.Build.Execution.ProjectInstance.Initialize(ProjectRootElement xml, IDictionary`2 globalProperties, String explicitToolsVersion, String explicitSubToolsetVersion, Int32 visualStudioVersionFromSolution, BuildParameters buildParameters, ILoggingService loggingService, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, Nullable`1 projectLoadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Execution.ProjectInstance..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, Nullable`1 projectLoadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Execution.ProjectInstance..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion)
    at Microsoft.DotNet.Workloads.Workload.Restore.WorkloadRestoreCommand.RunTargetToGetWorkloadIds(IEnumerable`1 allProjects)
    at Microsoft.DotNet.Workloads.Workload.Restore.WorkloadRestoreCommand.Execute()
    at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<b__0>d.MoveNext()
    — End of stack trace from previous location —
    at Microsoft.DotNet.Cli.Parser.<>c__DisplayClass17_0.<b__0>d.MoveNext()
    — End of stack trace from previous location —
    at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<b__0>d.MoveNext()
    — End of stack trace from previous location —
    at System.CommandLine.CommandLineBuilderExtensions.<>c.<b__17_0>d.MoveNext()
    — End of stack trace from previous location —
    at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass15_0.<b__0>d.MoveNext()
    — End of stack trace from previous location —
    at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass7_0.<b__0>d.MoveNext()
```

There are two issues here:

1. The error seen by the user (seen above)
2. And the real error underneath which is that some workload packs fail
   to load (possibly because they are missing), but the error gets
   swallowed by msbuild.

This is explained in
dotnet/sdk#21032 (comment) .

```
For the workload failure, what is going on is that the workload missing
error comes from running a Target, while the failure about the empty
value for AssemblyFile comes from evaluation. So you get the
AssemblyFile failure before it gets a chance to tell you about the
missing workload.
```

Details:

- the `MonoTargets` pack is missing, or doesn't have the correct
version, and the SDK cannot be loaded (see (2))

- And this in turn causes (1) because:
    - the `UsingTask` for `ReadEmccProps` in `WebAssembly.Sdk`'s
      `WasmApp.Native.targets` uses
      `AssemblyFile=$(JsonToItemsTaskFactoryTasksAssemblyPath)`
    - and `$(JsonToItemsTaskFactoryTasksAssemblyPath)` is set in the
      `MonoTargets.Sdk` pack
    - because of the missing pack the above property is unset, causing
      the `UsingTask` evaluation to fail.

As a workaround, we move the `UsingTask` to `MonoTargets.Sdk` too, which
should cause the real error to surface.
carlossanlop pushed a commit to dotnet/runtime that referenced this issue Jan 13, 2023
)

* [wasm] Work around an issue in VS upgrade

Upgrading from VS 17.3.6 to 17.4.2 caused wasm project builds to break
with:

```
Unhandled exception: Microsoft.Build.Exceptions.InvalidProjectFileException: The result “” of evaluating the value “$(JsonToItemsTaskFactoryTasksAssemblyPath)” of the “AssemblyFile” attribute in element  is not valid. C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.11\Sdk\WasmApp.Native.targets
    at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
    at Microsoft.Build.Shared.ProjectErrorUtilities.VerifyThrowInvalidProject[T1,T2,T3,T4](Boolean condition, String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, T1 arg0, T2 arg1, T3 arg2, T4 arg3)
    at Microsoft.Build.Shared.ProjectErrorUtilities.VerifyThrowInvalidProject[T1,T2,T3,T4](Boolean condition, IElementLocation elementLocation, String resourceName, T1 arg0, T2 arg1, T3 arg2, T4 arg3)
    at Microsoft.Build.Execution.TaskRegistry.RegisterTasksFromUsingTaskElement[P,I](ILoggingService loggingService, BuildEventContext buildEventContext, String directoryOfImportingFile, ProjectUsingTaskElement projectUsingTaskXml, TaskRegistry taskRegistry, Expander`2 expander, ExpanderOptions expanderOptions, IFileSystem fileSystem) at Microsoft.Build.Evaluation.Evaluator`4.EvaluateUsingTaskElement(String directoryOfImportingFile, ProjectUsingTaskElement projectUsingTaskElement)
    at Microsoft.Build.Evaluation.Evaluator`4.Evaluate() at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(IEvaluatorData`4 data, Project project, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary`1 environmentProperties, ILoggingService loggingService, IItemFactory`2 itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCacheBase projectRootElementCache, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, EvaluationContext evaluationContext, Boolean interactive) at Microsoft.Build.Execution.ProjectInstance.Initialize(ProjectRootElement xml, IDictionary`2 globalProperties, String explicitToolsVersion, String explicitSubToolsetVersion, Int32 visualStudioVersionFromSolution, BuildParameters buildParameters, ILoggingService loggingService, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, Nullable`1 projectLoadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Execution.ProjectInstance..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, Nullable`1 projectLoadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Execution.ProjectInstance..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion)
    at Microsoft.DotNet.Workloads.Workload.Restore.WorkloadRestoreCommand.RunTargetToGetWorkloadIds(IEnumerable`1 allProjects)
    at Microsoft.DotNet.Workloads.Workload.Restore.WorkloadRestoreCommand.Execute()
    at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<b__0>d.MoveNext()
    — End of stack trace from previous location —
    at Microsoft.DotNet.Cli.Parser.<>c__DisplayClass17_0.<b__0>d.MoveNext()
    — End of stack trace from previous location —
    at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<b__0>d.MoveNext()
    — End of stack trace from previous location —
    at System.CommandLine.CommandLineBuilderExtensions.<>c.<b__17_0>d.MoveNext()
    — End of stack trace from previous location —
    at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass15_0.<b__0>d.MoveNext()
    — End of stack trace from previous location —
    at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass7_0.<b__0>d.MoveNext()
```

There are two issues here:

1. The error seen by the user (seen above)
2. And the real error underneath which is that some workload packs fail
   to load (possibly because they are missing), but the error gets
   swallowed by msbuild.

This is explained in
dotnet/sdk#21032 (comment) .

```
For the workload failure, what is going on is that the workload missing
error comes from running a Target, while the failure about the empty
value for AssemblyFile comes from evaluation. So you get the
AssemblyFile failure before it gets a chance to tell you about the
missing workload.
```

Details:

- the `MonoTargets` pack is missing, or doesn't have the correct
version, and the SDK cannot be loaded (see (2))

- And this in turn causes (1) because:
    - the `UsingTask` for `ReadEmccProps` in `WebAssembly.Sdk`'s
      `WasmApp.Native.targets` uses
      `AssemblyFile=$(JsonToItemsTaskFactoryTasksAssemblyPath)`
    - and `$(JsonToItemsTaskFactoryTasksAssemblyPath)` is set in the
      `MonoTargets.Sdk` pack
    - because of the missing pack the above property is unset, causing
      the `UsingTask` evaluation to fail.

As a workaround, we move the `UsingTask` to `MonoTargets.Sdk` too, which
should cause the real error to surface.

* Add UsingTask for ReadEmccProps to LocalBuild targets, because WBT/EMSDK run doesn't have monotargets props on CI

* Add UsingTask to InTree targets also
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK Area-Workloads untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

4 participants