-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
When a project specifies RepositoryUrl property the NuGet Pack target includes the URL in <repository> tag in the generated package nuspec, along with the commit SHA.
This URL is defined as an URL that can be used to clone the repository. When the package is available it is thus possible to retrieve the sources it was built from.
In some scenarios however, the package is not available. Only the binaries are available, yet there is a need for retrieving the sources or finding the repository they were built from. One of these scenarios is the ability to run source based Roslyn analyzers on binaries produced by a build. The analyzer runner needs to retrieve sources used to build the binary, but the build might not produce packages.
If the repository uses Source Link it is possible to retrieve the source files based on the Source Link record in the PDB. That information is however optimized for debugging scenarios. The debugger only needs to retrieve one source file at a time as the user is stepping thru the library. Although it is possible to retrive all sources by enumerating all source files listed in the PDB, mapping them to the git raw URL and fetching them from the git content server it is less efficient to do so in some scenarios than to clone the entire repository - especially when all sources for multiple projects contained in the repository are needed.
The SDK currently includes the commit SHA in AssemblyInformationalVersionAttribute (see Microsoft.NET.GenerateAssemblyInfo.targets).
It does not include the RepositoryUrl in an assembly-level attribute. This proposal is to emit [AssemblyMetadataAttribute("RepositoryUrl", $(RepositoryUrl))] to the generated AssemblyInfo.cs. The SDK should also take PublishRepositoryUrl and PrivateRepositoryUrl properties into account when emitting this attribute similarly to NuGet pack target implementation.
Having the URL in the binary would also make it easier to find the repository for human when looking at binaries.
Alternatively the attribute can be emitted by Source Link package, but since RepositoryUrl can be specified manually by the project (as opposed to set by Source Link target)
even without having Source Link package reference it seems like the SDK is the right layer for it.