Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

rainersigwald
Copy link
Member

@rainersigwald rainersigwald commented Sep 29, 2020

Fixes microsoft/vstest#2570 by moving _ComputeTargetFrameworkItems outside the CallTargets used inside the VSTest target. This means that @(_InnerBuildProjects) is available in all CallTarget scopes.

What happened in a tiny sample project with a multitargeted library and a test assembly that @dsplaisted used was this:

  1. The VSTest target runs in the library, creating a CallTarget scope.
  2. Inside that scope, BuildProject runs, creating a CallTarget scope.
  3. Inside that scope, _ComputeTargetFrameworkItems runs, populating @(_InnerBuildProjects).
  4. Inside that scope again, the inner builds are dispatched to and built.
  5. The VSTest target runs in the test project, and eventually calls down to the normal build process.
  6. That process calls GetTargetFrameworks on the library project.
  7. The library project sees that _ComputeTargetFrameworkItems has already run and skips it.
  8. The library project proceeds to GetTargetFrameworksWithPlatformFromInnerBuilds, but doesn't have access to @(_InnerBuildProjects) because it's trapped in a scope, so the dispatch fails.
  9. The test project then tries to directly reference the outer build of the library, which has no primary output.
  10. The compiler fails because the library wasn't passed to it.

Step 8 is what's new. That was computed before dotnet/msbuild#5657 with only evaluation-time data, but now requires multitargeting dispatch.

Ideally, we'll eliminate CallTarget entirely. At this late time, however, this is a safer choice: ensure that @(_InnerBuildProjects) is populated in the biggest possible scope before any of the VSTest machinery runs by depending on it from VSTest.

Fixes microsoft/vstest#2570 by moving _ComputeTargetFrameworkItems outside
the CallTargets used inside the VSTest target. This means that @(_InnerBuildProjects)
is available in all CallTarget scopes.
@dsplaisted
Copy link
Member

Awesome. I would like to add a test to cover this though. It can be based off of https://github.com/ap0llo/repro-net5-dotnet-test-error

@dsplaisted dsplaisted mentioned this pull request Sep 29, 2020
5 tasks
Copy link
Member

@dsplaisted dsplaisted left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a test case to cover this.

@rainersigwald
Copy link
Member Author

Test looks good to me, thanks!

@ViktorHofer
Copy link
Member

Ideally, we'll eliminate CallTarget entirely. At this late time, however, this is a safer choice: ensure that @(_InnerBuildProjects) is populated in the biggest possible scope before any of the VSTest machinery runs by depending on it from VSTest.

Agreed. Can we log an issue or do the more involved change in master now?

@dsplaisted
Copy link
Member

Ideally, we'll eliminate CallTarget entirely. At this late time, however, this is a safer choice: ensure that @(_InnerBuildProjects) is populated in the biggest possible scope before any of the VSTest machinery runs by depending on it from VSTest.

Agreed. Can we log an issue or do the more involved change in master now?

I've filed #13927. Master is .NET 6, and we don't yet have a branch for 5.0.2xx. That shouldn't block work on this though, you could create the PR against 5.0.1xx and we can retarget it once we create the new branch.

@dsplaisted dsplaisted merged commit 40ec9a1 into dotnet:release/5.0.1xx Sep 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants