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.

Does the .NET Core SDK 3.1.300 really solves the untracked files issue?

See original GitHub issue

I already asked this question on https://github.com/dotnet/sdk/issues/10614#issuecomment-634029130 but did not get a response yet, so I’m trying here since it looks like a good place with Claire being very knowledgeable about deterministic builds.

Let’s describe the problem with a concrete example. Here’s how I’m packing https://github.com/0xced/DockerRunner, commit d6d8917e7f208dbaacd9dd6ff25a439031d5dfd1 (current master branch as of writing):

dotnet --version
3.1.300
dotnet pack -c Release /p:ContinuousIntegrationBuild=true
  Successfully created package '[...]DockerRunner\src\bin\Release\DockerRunner.0.9.0-alpha.0.21.nupkg'.

When I open the resulting DockerRunner.0.9.0-alpha.0.21.nupkg in NuGet Package Explorer, Source Link and Deterministic health items have a warning sign with this tooltip:

Contains untracked sources: To Fix: <EmbedUntrackedSources>true</EmbedUntrackedSources>

Also, use 3.1.300 SDK to build or workaround in: https://github.com/dotnet/sourcelink/issues/572 Assembly: lib\netstandard2.0\DockerRunner.dll /_/src/obj/Release/netstandard2.0/.NETStandard,Version=v2.0.AssemblyAttributes.cs /_/src/obj/Release/netstandard2.0/DockerRunner.AssemblyInfo.cs

Now, let’s add the workaround described on https://github.com/dotnet/sourcelink/issues/572 in DockerRunner.csproj:

<PropertyGroup>
  <TargetFrameworkMonikerAssemblyAttributesPath>$([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)'))</TargetFrameworkMonikerAssemblyAttributesPath>
</PropertyGroup>
<ItemGroup>
  <EmbeddedFiles Include="$(GeneratedAssemblyInfoFile)" />
</ItemGroup>

Then I try to pack again with dotnet pack -c Release /p:ContinuousIntegrationBuild=true and with this workaround, NuGet Package Explorer reports that Source Link and Determinisc are valid with a checkmark icon.

To me, it seems that the .NET Core SDK 3.1.300 does not actually solve the untracked sources issue. Am I missing something? (Note that I have <EmbedUntrackedSources> set to true in the csproj)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
0xcedcommented, Jun 2, 2020

I finally figured out why the AssemblyAttributes and AssemblyInfo files were not embedded in the pdb by SourceLink even when using the .NET Core SDK 3.1.300 and setting EmbedUntrackedSources to true.

The git repository was missing a .gitignore file.

I have a global .gitignore file with common git ignore patterns such as bin, obj, node_modules etc. but the repository did not have its own .gitignore file. After adding it, SourceLink works as expected and NuGet Package Explorer reports that the package health is ✅.


For the record, I built SourceLink from source code and integrated it in my project by removing <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" /> and adding those 6 imports instead (at the top of the my csproj file):

<Project Sdk="Microsoft.NET.Sdk">

  <Import Project="C:\Projects\GitHub\sourcelink\src\Microsoft.Build.Tasks.Git\build\Microsoft.Build.Tasks.Git.props" />
  <Import Project="C:\Projects\GitHub\sourcelink\src\Microsoft.Build.Tasks.Git\build\Microsoft.Build.Tasks.Git.targets" />
  <Import Project="C:\Projects\GitHub\sourcelink\src\SourceLink.Common\build\Microsoft.SourceLink.Common.props" />
  <Import Project="C:\Projects\GitHub\sourcelink\src\SourceLink.Common\build\Microsoft.SourceLink.Common.targets" />
  <Import Project="C:\Projects\GitHub\sourcelink\src\SourceLink.GitHub\build\Microsoft.SourceLink.GitHub.props" />
  <Import Project="C:\Projects\GitHub\sourcelink\src\SourceLink.GitHub\build\Microsoft.SourceLink.GitHub.targets" />

  <PropertyGroup>

I also had to modify the following file in the SourceLink repository:

diff --git a/src/Microsoft.Build.Tasks.Git/build/Microsoft.Build.Tasks.Git.props b/src/Microsoft.Build.Tasks.Git/build/Microsoft.Build.Tasks.Git.props
index 2078031..12be647 100644
--- a/src/Microsoft.Build.Tasks.Git/build/Microsoft.Build.Tasks.Git.props
+++ b/src/Microsoft.Build.Tasks.Git/build/Microsoft.Build.Tasks.Git.props
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project>
   <PropertyGroup>
-    <MicrosoftBuildTasksGitAssemblyFile Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tools\net461\Microsoft.Build.Tasks.Git.dll</MicrosoftBuildTasksGitAssemblyFile>
-    <MicrosoftBuildTasksGitAssemblyFile Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tools\netcoreapp2.0\Microsoft.Build.Tasks.Git.dll</MicrosoftBuildTasksGitAssemblyFile>
+    <MicrosoftBuildTasksGitAssemblyFile Condition="'$(MSBuildRuntimeType)' != 'Core'">C:\Projects\GitHub\sourcelink\artifacts\bin\Microsoft.Build.Tasks.Git\Debug\net461\Microsoft.Build.Tasks.Git.dll</MicrosoftBuildTasksGitAssemblyFile>
+    <MicrosoftBuildTasksGitAssemblyFile Condition="'$(MSBuildRuntimeType)' == 'Core'">C:\Projects\GitHub\sourcelink\artifacts\bin\Microsoft.Build.Tasks.Git\Debug\netcoreapp2.0\Microsoft.Build.Tasks.Git.dll</MicrosoftBuildTasksGitAssemblyFile>
   </PropertyGroup>
 </Project>
diff --git a/src/SourceLink.Common/build/Microsoft.SourceLink.Common.props b/src/SourceLink.Common/build/Microsoft.SourceLink.Common.props
index 1e2e1f2..1a2b041 100644
--- a/src/SourceLink.Common/build/Microsoft.SourceLink.Common.props
+++ b/src/SourceLink.Common/build/Microsoft.SourceLink.Common.props
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project>
   <PropertyGroup>
-    <_MicrosoftSourceLinkCommonAssemblyFile Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tools\net461\Microsoft.SourceLink.Common.dll</_MicrosoftSourceLinkCommonAssemblyFile>
-    <_MicrosoftSourceLinkCommonAssemblyFile Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tools\netcoreapp2.0\Microsoft.SourceLink.Common.dll</_MicrosoftSourceLinkCommonAssemblyFile>
+    <_MicrosoftSourceLinkCommonAssemblyFile Condition="'$(MSBuildRuntimeType)' != 'Core'">C:\Projects\GitHub\sourcelink\artifacts\bin\Microsoft.SourceLink.Common\Debug\net461\Microsoft.SourceLink.Common.dll</_MicrosoftSourceLinkCommonAssemblyFile>
+    <_MicrosoftSourceLinkCommonAssemblyFile Condition="'$(MSBuildRuntimeType)' == 'Core'">C:\Projects\GitHub\sourcelink\artifacts\bin\Microsoft.SourceLink.Common\Debug\netcoreapp2.0\Microsoft.SourceLink.Common.dll</_MicrosoftSourceLinkCommonAssemblyFile>
   </PropertyGroup>
 
   <PropertyGroup>
diff --git a/src/SourceLink.GitHub/build/Microsoft.SourceLink.GitHub.targets b/src/SourceLink.GitHub/build/Microsoft.SourceLink.GitHub.targets
index f0a0c1d..9cd038a 100644
--- a/src/SourceLink.GitHub/build/Microsoft.SourceLink.GitHub.targets
+++ b/src/SourceLink.GitHub/build/Microsoft.SourceLink.GitHub.targets
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project>
   <PropertyGroup>
-    <_SourceLinkGitHubAssemblyFile Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tools\net461\Microsoft.SourceLink.GitHub.dll</_SourceLinkGitHubAssemblyFile>
-    <_SourceLinkGitHubAssemblyFile Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tools\netcoreapp2.0\Microsoft.SourceLink.GitHub.dll</_SourceLinkGitHubAssemblyFile>
+    <_SourceLinkGitHubAssemblyFile Condition="'$(MSBuildRuntimeType)' != 'Core'">C:\Projects\GitHub\sourcelink\artifacts\bin\Microsoft.SourceLink.GitHub\Debug\net461\Microsoft.SourceLink.GitHub.dll</_SourceLinkGitHubAssemblyFile>
+    <_SourceLinkGitHubAssemblyFile Condition="'$(MSBuildRuntimeType)' == 'Core'">C:\Projects\GitHub\sourcelink\artifacts\bin\Microsoft.SourceLink.GitHub\Debug\netcoreapp2.0\Microsoft.SourceLink.GitHub.dll</_SourceLinkGitHubAssemblyFile>
   </PropertyGroup>
 
   <UsingTask TaskName="Microsoft.SourceLink.GitHub.GetSourceLinkUrl" AssemblyFile="$(_SourceLinkGitHubAssemblyFile)"/>

Finally, I was able to debug the GetUntrackedFiles MSBuild task step by step with the debugger by inserting System.Diagnostics.Debugger.Launch(); in its Execute method. I had the intuition that the root of the problem was there after looking at the SetEmbeddedFilesFromSourceControlManagerUntrackedFiles target with MSBuild Structured Log Viewer. Once I was deep down a method named IsIgnoredRecursive(string normalizedPosixPath, bool isDirectoryPath), I realized that SourceLink did not consider the files in the obj directory as untracked files because I had no .gitignore file.

1reaction
higher-order-programmercommented, Apr 17, 2022

@0xced thank you very much for sharing that, guy.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue with .Net Core SDK 3.1.300 installation after ...
I am not sure if this is an issue with the visual studio installation that did the upgrade of .net core sdk from...
Read more >
Getting "NETSDK1045 The current .NET SDK does not ...
I got the same error and resolve it with checking the option "Use previews of the .NET Core SDK (requires restart)". Open Tools...
Read more >
A Deep Dive into How .NET Builds and Ships
This is a deep technical dive into the machinery and processes used by the .NET Team to build and ship .NET. It will...
Read more >
Chocolatey Software | .NET Core SDK 3.1.101
NET Core is a blazing fast, lightweight and modular platform for creating web applications and services that run on Windows, Linux and Mac....
Read more >
Breaking changes in .NET Core 3.1
Lists the breaking changes in version 3.1 of .NET Core and ASP.NET Core.
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