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

Setting BaseIntermediateOutputPath or IntermediateOutputPath MSBuild properties in WPF projects causes instrumentation to fail. #976

Closed
hymccord opened this issue Oct 24, 2020 · 8 comments
Labels
tracking-external-issue The issue is caused by external problem - nothing we can do to fix it directly

Comments

@hymccord
Copy link

I've debugged this quite a bit and the problem is simple. But I'm not sure if I need to take it up here or somewhere in the dotnet repos.

Minimal repro is simple.

  1. New solution
  2. New WPF (netcore) project
  3. New Test project (added coverlet.msbuild too)
  4. Create directory.build.props in the solution folder.
<Project>
  <PropertyGroup>
    <SolutionDir>$(MSBuildThisFileDirectory)</SolutionDir>
    <BaseIntermediateOutputPath>$(SolutionDir)bin\obj\$(Configuration)\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
    <!-- or -->
    <!--<IntermediateOutputPath>$(SolutionDir)bin\obj\$(Configuration)\$(MSBuildProjectName)\</IntermediateOutputPath> -->
  </PropertyGroup>
</Project>

Commands and whether it instrumented correctly.
> dotnet test /p:CollectCoverage=true
> dotnet test --collect "XPlat Code Coverage" -> fails
✔️ > dotnet test --collect "Code Coverage" -> works

I built coverlet.msbuild and set my environment flag to let me debug.
The problem occurs in Instrumenter.cs:L151.
It fails when it tries to verify that App.xaml and MainWindow.xaml exist. (any .xaml file I think)
In builds where $([Base]IntermediateOutput) is not set, the PE metadata indicates the source document will be at:
....\<SolutionDir>\WpfApp1\App.xaml
In builds where it IS set, the metadata indicates (incorrectly) it will be here:
....\<SolutionDir>\bin\obj\Debug\WpfApp1\Debug\netcoreapp3.1\App.xaml

And it's not really y'alls fault, just trying to figure a solution for people who want to have a single bin and obj folder.

I have a plan to chase down the MSBuild side of this but maybe you'll have some insight since one of the collectors works and the other two do not. I only debugged the coverlet.msbuild portion.

@MarcoRossignoli MarcoRossignoli added the untriaged To be investigated label Oct 27, 2020
@MarcoRossignoli
Copy link
Collaborator

In builds where it IS set, the metadata indicates (incorrectly) it will be here:

When you say metadata you mean data inside pdb?Or you mean this line

string docName = _sourceRootTranslator.ResolveFilePath(metadataReader.GetString(document.Name));
?

@MarcoRossignoli MarcoRossignoli added waiting for customer Waiting for customer action and removed untriaged To be investigated labels Oct 27, 2020
@hymccord
Copy link
Author

hymccord commented Oct 28, 2020 via email

@MarcoRossignoli
Copy link
Collaborator

fixed by the msbuild team

Can you link here external issues(msbuild team)?Usually if it's an external issue we link the issue and label as tracking-external-issue.

@hymccord
Copy link
Author

Sorry, I should I clarified that I highly suspect it's msbuild system or roslyn compilation engine, but not 100% confirmed. I don't have an issue tracking it as of this moment.

I will find the correct repo to file an issue in.

Were you able to repro and see the document path metadata in the PDB?

@hymccord
Copy link
Author

hymccord commented Oct 28, 2020

Here's a pic of the PDB metadata document table (program is dotPeek).

BaseIntermediateOutputPath not set.
So it defaults to $(RepoRoot)\$(MSBuildProjectName)\obj\$(Configuration)
image

BaseIntermediateOutputPath set.
Set to $(RepoRoot)\bin\obj\$(Configuration)\$(MSBuildProjectName)
image

@hymccord
Copy link
Author

hymccord commented Nov 2, 2020

Okay, after digging into the Roslyn compiler and seeing the root issue was actually due to the pragma paths in the generated WPF .g.cs files; it seems like this has been filed in the appropriate places already.

See initial bug report: dotnet/wpf#1718
A fix was merged in here: dotnet/wpf#3120
But was reverted: dotnet/wpf#3637 😢
Comment here says it will be fixed in VS 16.9 Preview 2: dotnet/wpf#3637 (comment)
More conversation here: dotnet/wpf#3628

TLDR; This should be fixed in the .NET 5.0.2xx servicing release.

Workaround til then: don't use BaseIntermediateOutputPath.

@MarcoRossignoli MarcoRossignoli added tracking-external-issue The issue is caused by external problem - nothing we can do to fix it directly and removed waiting for customer Waiting for customer action labels Nov 10, 2020
@MarcoRossignoli
Copy link
Collaborator

Thanks a lot for the investigation!
I'm going to mark external issue.
Feel free to close when will be fixed on runtime.

@MarcoRossignoli
Copy link
Collaborator

Close as external issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tracking-external-issue The issue is caused by external problem - nothing we can do to fix it directly
Projects
None yet
Development

No branches or pull requests

2 participants