Does the .NET Core SDK 3.1.300 really solves the untracked files issue?
See original GitHub issueI 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:
- Created 3 years ago
- Reactions:3
- Comments:14 (3 by maintainers)
Top GitHub Comments
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
totrue
.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):I also had to modify the following file in the SourceLink repository:
Finally, I was able to debug the GetUntrackedFiles MSBuild task step by step with the debugger by inserting
System.Diagnostics.Debugger.Launch();
in itsExecute
method. I had the intuition that the root of the problem was there after looking at theSetEmbeddedFilesFromSourceControlManagerUntrackedFiles
target with MSBuild Structured Log Viewer. Once I was deep down a method namedIsIgnoredRecursive(string normalizedPosixPath, bool isDirectoryPath)
, I realized that SourceLink did not consider the files in theobj
directory as untracked files because I had no.gitignore
file.@0xced thank you very much for sharing that, guy.