-
Notifications
You must be signed in to change notification settings - Fork 347
/
RepositoryInfo.targets
132 lines (111 loc) · 8.29 KB
/
RepositoryInfo.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. -->
<Project>
<!-- Opt-in switch to disable source link (i.e. for local builds). -->
<PropertyGroup Condition="'$(DisableSourceLink)' == 'true'">
<EnableSourceLink>false</EnableSourceLink>
<EnableSourceControlManagerQueries>false</EnableSourceControlManagerQueries>
<DeterministicSourcePaths>false</DeterministicSourcePaths>
</PropertyGroup>
<!--
Set the SourceRoot to repo root to facilitate deterministic source paths when SCM queries are disabled, unless during design-time build.
Set the RepositoryUrl to the Build.Repository.Uri Azure DevOps build variable if on CI, otherwise to local repo path.
Do not set these properties during design-time build to avoid differences between design-time and reuglar builds.
-->
<ItemGroup Condition="'$(EnableSourceControlManagerQueries)' != 'true' and '$(DesignTimeBuild)' != 'true'">
<SourceRoot Include="$(RepoRoot)" />
</ItemGroup>
<PropertyGroup Condition="'$(EnableSourceControlManagerQueries)' != 'true' and '$(DesignTimeBuild)' != 'true' and '$(RepositoryUrl)' == ''">
<RepositoryUrl Condition="'$(BUILD_REPOSITORY_URI)' != '' and '$(DisableSourceLinkUrlTranslation)' != 'true'">$([System.Text.RegularExpressions.Regex]::Replace($(BUILD_REPOSITORY_URI), $(_TranslateUrlPattern), $(_TranslateUrlReplacement)))</RepositoryUrl>
<RepositoryUrl Condition="'$(BUILD_REPOSITORY_URI)' != '' and '$(DisableSourceLinkUrlTranslation)' == 'true'">$(BUILD_REPOSITORY_URI)</RepositoryUrl>
<RepositoryUrl Condition="'$(BUILD_REPOSITORY_URI)' == ''">file://$(RepoRoot)</RepositoryUrl>
</PropertyGroup>
<PropertyGroup Condition="'$(EnableSourceControlManagerQueries)' != 'true' and '$(DesignTimeBuild)' != 'true' and '$(RepositoryCommit)' == ''">
<RepositoryCommit Condition="'$(BUILD_SOURCEVERSION)' != ''">$(BUILD_SOURCEVERSION)</RepositoryCommit>
<RepositoryCommit Condition="'$(BUILD_SOURCEVERSION)' == ''">0000000000000000000000000000000000000000</RepositoryCommit>
</PropertyGroup>
<PropertyGroup Condition="'$(EnableSourceControlManagerQueries)' != 'true' and '$(DesignTimeBuild)' != 'true' and '$(RepositoryType)' == ''">
<RepositoryType>git</RepositoryType>
</PropertyGroup>
<!--
The convention for names of Azure DevOps repositories mirrored from GitHub is "{GitHub org name}-{GitHub repository name}"
In the legacy devdiv.visualstudio instance, it is instead "{GitHub org name}-{GitHub repository name}-Trusted" with no guarantees for casing.
-->
<PropertyGroup>
<!-- There are quite a few git repo forms:
https://dnceng@dev.azure.com/dnceng/internal/_git/dotnet-arcade-services
https://dev.azure.com/dnceng/internal/_git/dotnet-arcade-services
https://dnceng.visualstudio.com/internal/_git/dotnet-arcade-services
https://devdiv.visualstudio.com/DevDiv/_git/DotNet-msbuild-Trusted
dnceng@vs-ssh.visualstudio.com:v3/dnceng/internal/dotnet-arcade-services
git@ssh.dev.azure.com:v3/dnceng/internal/dotnet-arcade-services
-->
<!-- Set DisableSourceLinkUrlTranslation to true when building a tool for internal use where sources only come from internal URIs -->
<DisableSourceLinkUrlTranslation Condition="'$(DisableSourceLinkUrlTranslation)' == ''">false</DisableSourceLinkUrlTranslation>
<_TranslateUrlPattern>(https://dnceng%40dev\.azure\.com/dnceng/internal/_git|https://dev\.azure\.com/dnceng/internal/_git|https://dnceng\.visualstudio\.com/internal/_git|dnceng%40vs-ssh\.visualstudio\.com:v3/dnceng/internal|git%40ssh\.dev\.azure\.com:v3/dnceng/internal|https://devdiv\.visualstudio\.com/devdiv/_git)/([^/-]+)-(.+)</_TranslateUrlPattern>
<_TranslateUrlReplacement>https://github.com/$2/$3</_TranslateUrlReplacement>
</PropertyGroup>
<Target Name="_TranslateAzureDevOpsUrlToGitHubUrl"
Condition="'$(DisableSourceLinkUrlTranslation)' == 'false'"
DependsOnTargets="$(SourceControlManagerUrlTranslationTargets)"
BeforeTargets="SourceControlManagerPublishTranslatedUrls">
<PropertyGroup>
<!-- Repositories mirrored on devdiv.visualstudio will have '-Trusted' added to their name and this needs to be stripped off before translation
Eventually, all repos should move to dnceng/internal when possible. -->
<ScmRepositoryUrl Condition=" '$([MSBuild]::ValueOrDefault(`%(SourceRoot.ScmRepositoryUrl)`, ``).Contains(`devdiv.visualstudio`))' == 'true' ">$([MSBuild]::ValueOrDefault(`%(SourceRoot.ScmRepositoryUrl)`, ``).ToLower().Replace(`-trusted`,``))</ScmRepositoryUrl>
<ScmRepositoryUrl>$([System.Text.RegularExpressions.Regex]::Replace($(ScmRepositoryUrl), $(_TranslateUrlPattern), $(_TranslateUrlReplacement)))</ScmRepositoryUrl>
</PropertyGroup>
<ItemGroup>
<SourceRoot Update="@(SourceRoot)">
<ScmRepositoryUrl Condition="$([MSBuild]::ValueOrDefault(`%(SourceRoot.ScmRepositoryUrl)`, ``).Contains(`devdiv.visualstudio`))">$([MSBuild]::ValueOrDefault(`%(SourceRoot.ScmRepositoryUrl)`, ``).ToLower().Replace(`-trusted`,``))</ScmRepositoryUrl>
</SourceRoot>
<SourceRoot Update="@(SourceRoot)">
<ScmRepositoryUrl>$([System.Text.RegularExpressions.Regex]::Replace(%(SourceRoot.ScmRepositoryUrl), $(_TranslateUrlPattern), $(_TranslateUrlReplacement)))</ScmRepositoryUrl>
</SourceRoot>
</ItemGroup>
</Target>
<!--
Generates and adds {PackageId}.SourceLink.targets file to the build directory of the source package.
-->
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.GenerateSourcePackageSourceLinkTargetsFile" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" />
<PropertyGroup Condition="'$(IsPackable)' == 'true' and '$(IsSourcePackage)' == 'true' and '$(EnableSourceLink)' == 'true'">
<BeforePack>$(BeforePack);_AddSourcePackageSourceLinkFile</BeforePack>
</PropertyGroup>
<Target Name="_AddSourcePackageSourceLinkFile" DependsOnTargets="_GenerateSourcePackageSourceLinkFile">
<ItemGroup>
<!-- Add a packable item if the project builds the package with auto-generated .nuspec file -->
<None Include="$(_SourcePackageSourceLinkTargetsFilePath)" PackagePath="build" Pack="true" Condition="'$(NuspecFile)' == ''"/>
<!-- Include path in the nuspec properties if the project builds package using custom .nuspec -->
<NuspecProperty Include="SourceLinkTargetsFilePath=$(_SourcePackageSourceLinkTargetsFilePath)" Condition="'$(NuspecFile)' != ''"/>
</ItemGroup>
</Target>
<Target Name="_CalculateGenerateSourcePackageSourceLinkFileOutputs">
<PropertyGroup>
<_SourcePackageSourceLinkTargetsFileName>$([MSBuild]::ValueOrDefault($(SourcePackageSourceLinkTargetsFileName), '$(PackageId).targets'))</_SourcePackageSourceLinkTargetsFileName>
<_SourcePackageSourceLinkTargetsFilePath>$(IntermediateOutputPath)$(_SourcePackageSourceLinkTargetsFileName)</_SourcePackageSourceLinkTargetsFilePath>
</PropertyGroup>
</Target>
<Target Name="_GenerateSourcePackageSourceLinkFile"
DependsOnTargets="InitializeSourceControlInformation;$(SourceLinkUrlInitializerTargets);_CalculateGenerateSourcePackageSourceLinkFileOutputs"
Inputs="$(MSBuildAllProjects)"
Outputs="$(_SourcePackageSourceLinkTargetsFilePath)">
<Microsoft.DotNet.Arcade.Sdk.GenerateSourcePackageSourceLinkTargetsFile
ProjectDirectory="$(MSBuildProjectDirectory)"
PackageId="$(PackageId)"
SourceRoots="@(SourceRoot)"
OutputPath="$(_SourcePackageSourceLinkTargetsFilePath)"/>
<ItemGroup>
<FileWrites Include="$(_SourcePackageSourceLinkTargetsFilePath)"/>
</ItemGroup>
</Target>
<!--
Validates repository-wide requirements.
MSBuild only evaluates the target project once per each set of values of global properties and caches the results.
-->
<Target Name="_RepositoryValidation" BeforeTargets="Build" Condition="'$(ContinuousIntegrationBuild)' == 'true'">
<MSBuild Projects="$(MSBuildThisFileDirectory)RepositoryValidation.proj"
Targets="Validate"
RemoveProperties="TargetFramework;Platform"
Properties="RepoRoot=$(RepoRoot);PackageLicenseExpression=$(PackageLicenseExpression);PackageLicenseExpressionInternal=$(PackageLicenseExpressionInternal);SuppressLicenseValidation=$(SuppressLicenseValidation)"
UseResultsCache="true" />
</Target>
</Project>