Skip to content

Commit 85de4d8

Browse files
author
Javad Rahnama
authored
[5.2] Fix | Enable source link translation (#2718)
1 parent da39103 commit 85de4d8

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/Directory.Build.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
7979
<PublishRepositoryUrl>true</PublishRepositoryUrl>
8080
<EmbedUnTrackedSources>true</EmbedUnTrackedSources>
81+
<DisableSourceLinkTranslation Condition="'$(DisableSourceLinkTranslation)' == ''">false</DisableSourceLinkTranslation>
8182
</PropertyGroup>
8283
<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
8384
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
@@ -96,4 +97,6 @@
9697
<!-- Provides Build properties -->
9798
<Import Project="$(ToolsDir)props\AssemblyInfo.props" />
9899
<Import Project="$(ToolsDir)props\AssemblyRef.props" />
100+
<Import Project="$(ToolsDir)targets\RepositoryInfo.targets" />
101+
99102
</Project>

tools/targets/RepositoryInfo.targets

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this
2+
file to you under the MIT license. -->
3+
<Project>
4+
5+
<!-- Opt-in switch to disable source link (i.e. for local builds). -->
6+
<PropertyGroup Condition="'$(DisableSourceLink)' == 'true'">
7+
<EnableSourceLink>false</EnableSourceLink>
8+
<EnableSourceControlManagerQueries>false</EnableSourceControlManagerQueries>
9+
<DeterministicSourcePaths>false</DeterministicSourcePaths>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<SourceRoot Include="$(RepoRoot)" />
14+
</ItemGroup>
15+
16+
<PropertyGroup>
17+
<_TranslateUrlPattern>https://[^/]+/ADO.Net/_git/([^/-]+)-(.+)</_TranslateUrlPattern>
18+
<_TranslateUrlReplacement>https://github.com/dotnet/SqlClient</_TranslateUrlReplacement>
19+
</PropertyGroup>
20+
21+
<Target Name="_TranslateAzureDevOpsUrlToGitHubUrl"
22+
Condition="'$(DisableSourceLinkTranslation)' == 'false'"
23+
DependsOnTargets="$(SourceControlManagerUrlTranslationTargets)"
24+
BeforeTargets="SourceControlManagerPublishTranslatedUrls">
25+
26+
<PropertyGroup>
27+
<ScmRepositoryUrl>$([System.Text.RegularExpressions.Regex]::Replace($(ScmRepositoryUrl), $(_TranslateUrlPattern), $(_TranslateUrlReplacement)))</ScmRepositoryUrl>
28+
</PropertyGroup>
29+
30+
<ItemGroup>
31+
<SourceRoot Update="@(SourceRoot)">
32+
</SourceRoot>
33+
<SourceRoot Update="@(SourceRoot)">
34+
<ScmRepositoryUrl>$([System.Text.RegularExpressions.Regex]::Replace(%(SourceRoot.ScmRepositoryUrl),
35+
$(_TranslateUrlPattern), $(_TranslateUrlReplacement)))</ScmRepositoryUrl>
36+
</SourceRoot>
37+
</ItemGroup>
38+
<Message Text="Final Translated ScmRepositoryUrl to $(ScmRepositoryUrl)" Importance="high" />
39+
</Target>
40+
</Project>

0 commit comments

Comments
 (0)