sourcelink: SourceLink doesn't work well with WPF projects

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.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (8 by maintainers)

Commits related to this issue

Most upvoted comments

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.

The workaround is to add

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

to the .csproj file.