dotnet / sourcelink

Source Link enables a great source debugging experience for your users, by adding source control metadata to your built assets
MIT License
1.25k stars 122 forks source link

.Net 8 Build fails when inside a particular git repository #1097

Open quixoticaxis opened 1 year ago

quixoticaxis commented 1 year ago

Description

When I try to build a new console project inside a particular git repository the build fails:

dotnet build MSBuild version 17.8.0-preview-23367-03+0ff2a83e9 for .NET Determining projects to restore... All projects are up-to-date for restore. /usr/local/dotnet-sdk-8.0.100-preview.7.23376.3-linux-x64/sdk/8.0.100-preview.7.23376.3/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(314,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [/home/user/folder/folder/repo/000000-папка-C#/Project/Project.csproj] /usr/local/dotnet-sdk-8.0.100-preview.7.23376.3-linux-x64/sdk/8.0.100-preview.7.23376.3/Sdks/Microsoft.Build.Tasks.Git/build/Microsoft.Build.Tasks.Git.targets(25,5): error : Error reading git repository information: Unsupported repository extension 'objectformat'. Only noop, preciousObjects, partialclone, worktreeConfig are supported. [/home/user/folder/folder/repo/000000-папка-C#/Project/Project.csproj]

Build FAILED.

/usr/local/dotnet-sdk-8.0.100-preview.7.23376.3-linux-x64/sdk/8.0.100-preview.7.23376.3/Sdks/Microsoft.Build.Tasks.Git/build/Microsoft.Build.Tasks.Git.targets(25,5): error : Error reading git repository information: Unsupported repository extension 'objectformat'. Only noop, preciousObjects, partialclone, worktreeConfig are supported. [/home/user/folder/folder/repo/000000-папка-C#/Project/Project.csproj] 0 Warning(s) 1 Error(s)

When the same project is moved out of git repository, it builds fine.

Reproduction Steps

I cannot reproduce the bug inside freshly initialized git repositories.

Expected behavior

The build cares not about whether the project is under the source control and succeeds.

Actual behavior

The build fails with cryptic error:

dotnet build MSBuild version 17.8.0-preview-23367-03+0ff2a83e9 for .NET Determining projects to restore... All projects are up-to-date for restore. /usr/local/dotnet-sdk-8.0.100-preview.7.23376.3-linux-x64/sdk/8.0.100-preview.7.23376.3/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(314,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [/home/user/folder/folder/repo/000000-папка-C#/Project/Project.csproj] /usr/local/dotnet-sdk-8.0.100-preview.7.23376.3-linux-x64/sdk/8.0.100-preview.7.23376.3/Sdks/Microsoft.Build.Tasks.Git/build/Microsoft.Build.Tasks.Git.targets(25,5): error : Error reading git repository information: Unsupported repository extension 'objectformat'. Only noop, preciousObjects, partialclone, worktreeConfig are supported. [/home/user/folder/folder/repo/000000-папка-C#/Project/Project.csproj]

Build FAILED.

/usr/local/dotnet-sdk-8.0.100-preview.7.23376.3-linux-x64/sdk/8.0.100-preview.7.23376.3/Sdks/Microsoft.Build.Tasks.Git/build/Microsoft.Build.Tasks.Git.targets(25,5): error : Error reading git repository information: Unsupported repository extension 'objectformat'. Only noop, preciousObjects, partialclone, worktreeConfig are supported. [/home/user/folder/folder/repo/000000-папка-C#/Project/Project.csproj] 0 Warning(s) 1 Error(s)

Regression?

Probably not, never experienced it with any version of .Net (or .Net Framework).

Known Workarounds

It is possible to work with the project out of source control and constantly moving it in and out of repository, but that's a hustle.

Configuration

dotnet: dotnet --version -> 8.0.100-preview.7.23376.3 OS: lsb_release -a -> Ubuntu 22.04.3 LTS (Actually, Kubuntu). Architecture: x64. I don't know whether it is specific to configuration. I do not use Blazor.

Other information

No response

vcsjones commented 1 year ago

Did you enable experimental SHA-256 support in your git repository? i.e. when you created your git repository, did you do git init --object-format sha256?

If you aren't sure, you can do git config extensions.objectformat. If it prints "sha256" then you are using the SHA256 extension.

I would guess that Microsoft.Build.Tasks.Git.targets does not support SHA256 Git repositories, which makes sense given that it is experimental.

You will need to re-initialize the Git repository without the objectformat extension to change back to SHA1 - you can't change it after the repository has been initialized.

I can reproduce this with a SHA256 repository:

~/Projects/sha256-repo                                                                                                            ❮ x64 
❯ dotnet build
MSBuild version 17.8.0-preview-23367-03+0ff2a83e9 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
/usr/local/share/dotnet/sdk/8.0.100-preview.7.23376.3/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(314,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [/Users/vcsjones/Projects/sha256-repo/sha256-repo.csproj]
/usr/local/share/dotnet/sdk/8.0.100-preview.7.23376.3/Sdks/Microsoft.Build.Tasks.Git/build/Microsoft.Build.Tasks.Git.targets(25,5): error : Error reading git repository information: Unsupported repository extension 'objectformat'. Only noop, preciousObjects, partialclone, worktreeConfig are supported. [/Users/vcsjones/Projects/sha256-repo/sha256-repo.csproj]
quixoticaxis commented 1 year ago

@vcsjones , thank you. Yes, I use SHA-256. Is it possible to somehow turn off the integration?

KalleOlaviNiemitalo commented 1 year ago

There's a condition on $(SuppressImplicitGitSourceLink) here: https://github.com/dotnet/sdk/blob/b9a275259a7a2e993ba6a21676a2679a7e128814/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.CrossTargeting.targets#L15

baronfel commented 1 year ago

More broadly you can disable SourceLink for a given project/repository by setting EnableSourceLink to false. See below, this isn't enough and other properties are needed.

baronfel commented 1 year ago

Hey @tmat should this get moved to dotnet/sourcelink and triaged?

baronfel commented 1 year ago

(also we're going to start tagging sourcelink-related issues with the Area-SourceLink label - can your team do periodic triage of these?)

vcsjones commented 1 year ago

More broadly you can disable SourceLink for a given project/repository by setting EnableSourceLink to false.

This does not work: <EnableSourceLink>false</EnableSourceLink>

This does: <SuppressImplicitGitSourceLink>true</SuppressImplicitGitSourceLink>

tmat commented 1 year ago

Yes, please move the issue to dotnet/sourcelink

tmat commented 1 year ago

EnableSourceLink wouldn't disable all git information reading as Source Link file generator is not the only build task that reads the git data. Setting EnableSourceControlManagerQueries to false should do.

SuppressImplicitGitSourceLink also works since it removes all implicitly added Source Link packages.

baronfel commented 1 year ago

@tmat I can't transfer (perhaps due to permissions?) - can you transfer from this repo to dotnet/sourcelink?