question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SourceLink doesn't work well with WPF projects

See original GitHub issue

Error

Microsoft.Managed.Core.targets(90,5): SourceRoot items must include at least one top-level (not nested) item when DeterministicSourcePaths is true [C:\Temp\WpfApp1\WpfApp1\WpfApp1_3qoc4wf0_wpftmp.csproj]

is reported when building with /p:ContinuousIntegrationBuild=true.

Due to https://github.com/NuGet/Home/issues/5894 - WPF projects do not import .props and .targets files from NuGet packages.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
tmatcommented, Jun 27, 2018

The issue in Newtonsoft.Json is related but different than the WPF issue.

When DeterministicSourcePaths is enabled the compiler needs to know the set of directories that all source code resides under. This set is specified by SourceRoot items. In projects that reference SourceLink package SourceRoot items are populated by SourceLink since it knows where the repository root is.

In projects that do not reference SourceLink package this SourceRoot is undefined and hence the compiler doesn’t know how to normalize the paths and reports the error [1].

The recommendation is to include the SourceLink package reference to all projects in the repo (even to test projects). This can be easily accomplished via adding Directory.Build.props file in the root of the repository that includes the SoruceLink package:

<Project>
  <PackageReference Include="Microsoft.SourceLink.GitHub" Version="..." PrivateAssets="all"/>
</Project>

[1] The compiler does not infer the source root(s) based on source file paths it is given as this might produce confusing results. Consider a repo with two projects:

.../src/ProjectA/ProjectA.csproj
.../src/ProjectA/Program.cs
.../src/ProjectB/ProjectB.csproj
.../src/ProjectB/Program.cs

If the compiler inferred the source roots for these projects they would be .../src/ProjectA/ and .../src/ProjectB/ and the paths embedded in DLLs and PDBs to Program.cs files would be /_/Program.cs for both .../src/ProjectA/Program.cs and .../src/ProjectB/Program.cs. So it would be impossible to distinguish which Program.cs is which.

1reaction
tmatcommented, Jun 13, 2018

The workaround is to add

<DeterministicSourcePaths Condition="'$(EnableSourceLink)' == ''">false</DeterministicSourcePaths>

to the .csproj file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Link /SOURCELINK option seems to do nothing
We are using SourceLink with c# projects and it is working just fine. When we try to use it on C++ projects the...
Read more >
View Source link does not work in Live Visual Tree ...
View Source link does not work in Live Visual Tree, Visual Studio 2017 ... Create WPF project, mine includes custom dialogs and buttons...
Read more >
Debug NuGet packages with SourceLink (no symbols package!)
WindowsDesktop” SDK) so I have moved our “WPF Components” package to .Net Core 3 too. Once we have installed the “Microsoft.SourceLink.Tfs.Git” ...
Read more >
Debugging External Sources with Visual Studio
This node appears while debugging and will show sources for managed modules with symbols loaded containing Source Link or Source Server ...
Read more >
How to debug NuGet packages using SourceLink
SourceLink is very simple to enable in your build. All you have to do is to add a reference to the NuGet package...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found