-
Notifications
You must be signed in to change notification settings - Fork 132
Open
Labels
enhancementNew feature or requestNew 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.
pakrym
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request