Repository navigation
Open
Labels
enhancementNew feature or request
Milestone
Description
To provide SourceLink information for a source package to the project that references such package one can write a task that generates .props file below and include it in the build directory of the source package (the below example is from Microsoft.CodeAnalysis.PooledObjects package):
<ItemGroup>
<SourceRoot Include="$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\contentFiles\cs\$(TargetFramework)\'))"
SourceLinkUrl="https://raw.githubusercontent.com/dotnet/roslyn/3590c5574234ecac536c98d69d8a892e61feb4e3/src/Dependencies/PooledObjects/*"/>
</ItemGroup>The target in Roslyn repository that generates the above props is:
<Target Name="GenerateSourcePackagePropsFile"
BeforeTargets="Build"
Condition="'$(TargetFrameworks)' == '' or '$(IsCrossTargetingBuild)' == 'true'"
Outputs="$(_SourcePackagePropsFilePath)">
<PropertyGroup>
<_RelativePath>$([MSBuild]::MakeRelative($(RepoRoot), $(MSBuildProjectDirectory)))</_RelativePath>
<!-- TODO: Proper URL escaping -->
<_RawUrl>$(RepositoryRawUrl)/$(GitHeadSha)/$(_RelativePath.Replace('\', '/'))/*</_RawUrl>
<_Content>
<![CDATA[<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<SourceRoot Include="%24([System.IO.Path]::GetFullPath('%24(MSBuildThisFileDirectory)..\contentFiles\cs\%24(TargetFramework)\'))"
SourceLinkUrl="$(_RawUrl)"/>
</ItemGroup>
</Project>]]>
</_Content>
</PropertyGroup>
<MakeDir Directories="$(_SourcePackagePropsDirPath)" />
<WriteLinesToFile File="$(_SourcePackagePropsFilePath)" Lines="$(_Content)" Overwrite="true" Encoding="UTF-8"/>
<ItemGroup>
<FileWrites Include="$(_SourcePackagePropsFilePath)" />
</ItemGroup>
</Target>Generalize this target to a build task and expose it from Microsoft.SourceLink.Common package.
To complete the end-to-end scenario we would want to also have NuGet Pack support for source packages. Then we could integrate the above task into the build system automatically when Microsoft.SourceLink.* package is referenced.
Reacted by Pavel Krymets
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
tmat commentedon Jun 22, 2019
Implementation: https://github.com/dotnet/arcade/blob/master/src/Microsoft.DotNet.Arcade.Sdk/tools/RepositoryInfo.targets#L76-L117
clairernovotny commentedon Apr 1, 2020
This works if the source package is published on GitHub and rebuilt. What about existing source packages or those where the source isn't published?
Source Link does embed them as untracked sources currently but does not have a source root for it so the path is not deterministic.
Adding this to the targets worked and handles all source packages.