summaryrefslogtreecommitdiff
path: root/.packages/microsoft.dotnet.arcade.sdk/1.0.0-beta.20113.5/tools/Publish.proj
blob: 2178b33bc05e4bb4423d17f3265b6b1d70c06449 (plain)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
<Project DefaultTargets="Publish">
  <!--
    Optional variables:
      AzureFeedUrl                      Target Azure feed URL.
      AzureAccountKey                   Azure account key.
      DotNetFinalVersionKind            Global property that stores the type of the current build: https://github.com/dotnet/arcade/blob/master/Documentation/CorePackages/Versioning.md#build-kind
      DotNetOutputBlobFeedDir           Source Build publishing directory
      DotNetSymbolServerTokenMsdl       Personal access token for MSDL symbol server. Available from variable group DotNet-Symbol-Publish.
      DotNetSymbolServerTokenSymWeb     Personal access token for SymWeb symbol server. Available from variable group DotNet-Symbol-Publish.
      DotNetSymbolExpirationInDays      Symbol expiration time in days (defaults to 10 years).
  -->

  <Import Project="BuildStep.props" />

  <!-- Allow for repo specific Publish properties such as add additional files to be published -->
  <Import Project="$(RepositoryEngineeringDir)Publishing.props" Condition="Exists('$(RepositoryEngineeringDir)Publishing.props')" />

  <PropertyGroup>
    <PublishToAzure>false</PublishToAzure>
    <PublishToAzure Condition="'$(AzureFeedUrl)' != ''">true</PublishToAzure>

    <PublishToSourceBuildStorage>false</PublishToSourceBuildStorage>
    <PublishToSourceBuildStorage Condition="'$(DotNetOutputBlobFeedDir)' != ''">true</PublishToSourceBuildStorage>
    
    <PublishToSymbolServer>false</PublishToSymbolServer>
    <PublishToSymbolServer Condition="'$(UsingToolSymbolUploader)' == 'true' and '$(AzureFeedUrl)' == '' and '$(ContinuousIntegrationBuild)' == 'true'">true</PublishToSymbolServer>

    <!-- Globally set property. -->
    <IsStableBuild>false</IsStableBuild>
    <IsStableBuild Condition="'$(DotNetFinalVersionKind)' == 'release'">true</IsStableBuild>

    <AssetManifestOS Condition="'$(AssetManifestOS)' == ''">$(OS)</AssetManifestOS>

    <AssetManifestFileName>$(AssetManifestOS)-$(PlatformName).xml</AssetManifestFileName>
    <AssetManifestFilePath>$(ArtifactsLogDir)AssetManifest\$(AssetManifestFileName)</AssetManifestFilePath>

    <SymbolPackagesDir>$(ArtifactsTmpDir)SymbolPackages\</SymbolPackagesDir>

    <PublishToBlobFeedFlatContainer Condition="'$(PublishToBlobFeedFlatContainer)' == ''">false</PublishToBlobFeedFlatContainer>

    <PublishDependsOnTargets Condition="$(PublishToAzure) and '$(PublishToAzureDevOpsArtifacts)' != 'true' and '$(PublishToBlobFeedFlatContainer)' != 'true'">$(PublishDependsOnTargets);PublishPackagesToBlobFeed</PublishDependsOnTargets>
    <PublishDependsOnTargets Condition="$(PublishToAzure) and '$(PublishToAzureDevOpsArtifacts)' != 'true' and '$(PublishToBlobFeedFlatContainer)' == 'true'">$(PublishDependsOnTargets);PublishFilesToBlobFeed</PublishDependsOnTargets>
    <PublishDependsOnTargets Condition="$(PublishToSymbolServer)">$(PublishDependsOnTargets);PublishSymbols</PublishDependsOnTargets>
    <PublishDependsOnTargets Condition="$(PublishToSourceBuildStorage)">$(PublishDependsOnTargets);PublishToSourceBuildStorage</PublishDependsOnTargets>
    <PublishDependsOnTargets Condition="$(PublishToAzure) and '$(PublishToAzureDevOpsArtifacts)' == 'true'">$(PublishDependsOnTargets);PublishToAzureDevOpsArtifacts</PublishDependsOnTargets>
    <PublishDependsOnTargets>BeforePublish;$(PublishDependsOnTargets)</PublishDependsOnTargets>
  </PropertyGroup>

  <Import Project="$(NuGetPackageRoot)microsoft.dotnet.build.tasks.feed\$(MicrosoftDotNetBuildTasksFeedVersion)\build\Microsoft.DotNet.Build.Tasks.Feed.targets" Condition="$(PublishToAzure)"/>
  <Import Project="$(NuGetPackageRoot)microsoft.symboluploader.build.task\$(MicrosoftSymbolUploaderBuildTaskVersion)\build\PublishSymbols.targets" Condition="$(PublishToSymbolServer)"/>

  <Target Name="Publish"
          DependsOnTargets="$(PublishDependsOnTargets)" />

  <Target Name="BeforePublish">
    <ItemGroup>
      <ExistingSymbolPackages Include="$(ArtifactsShippingPackagesDir)**/*.symbols.nupkg" IsShipping="true" />
      <ExistingSymbolPackages Include="$(ArtifactsNonShippingPackagesDir)**/*.symbols.nupkg" IsShipping="false" />

      <PackagesToPublish Include="$(ArtifactsShippingPackagesDir)*.nupkg" IsShipping="true" />
      <PackagesToPublish Include="$(ArtifactsNonShippingPackagesDir)*.nupkg" IsShipping="false" />
      <PackagesToPublish Remove="@(ExistingSymbolPackages)" />

      <PackagesToPublish Update="@(PackagesToPublish)">
        <SymbolPackageToGenerate Condition="!Exists('%(RootDir)%(Directory)%(Filename).symbols.nupkg')">$(SymbolPackagesDir)%(Filename).symbols.nupkg</SymbolPackageToGenerate>
      </PackagesToPublish>

      <SymbolPackagesToGenerate Include="@(PackagesToPublish->'%(SymbolPackageToGenerate)')" Condition="'%(PackagesToPublish.SymbolPackageToGenerate)' != ''" Exclude="@(ExistingSymbolPackages -> '$(SymbolPackagesDir)%(Filename)%(Extension)')">
        <OriginalPackage>%(PackagesToPublish.Identity)</OriginalPackage>
        <IsShipping>%(PackagesToPublish.IsShipping)</IsShipping>
      </SymbolPackagesToGenerate>
    </ItemGroup>

    <!--
      If a symbol package doesn't exist yet we assume that the regular package contains Portable PDBs.
      Such packages can act as symbol packages since they have the same structure.
      We just need to copy them to *.symbols.nupkg.
    -->
    <MakeDir Condition="'@(SymbolPackagesToGenerate)' != ''" Directories="$(SymbolPackagesDir)" />
    <Copy SourceFiles="@(SymbolPackagesToGenerate->'%(OriginalPackage)')" DestinationFiles="@(SymbolPackagesToGenerate)" />

    <!-- Orchestrated Build blob storage -->
    <ItemGroup>
      <ItemsToPushToBlobFeed Include="@(PackagesToPublish);@(ExistingSymbolPackages);@(SymbolPackagesToGenerate)">
        <ManifestArtifactData Condition="'%(IsShipping)' != 'true'">NonShipping=true</ManifestArtifactData>
      </ItemsToPushToBlobFeed>
    </ItemGroup>

    <!-- 
      Translate properties to those used by the feed package
      https://github.com/dotnet/arcade/blob/master/src/Microsoft.DotNet.Build.Tasks.Feed/build/Microsoft.DotNet.Build.Tasks.Feed.targets 
    -->
    <PropertyGroup>
      <ExpectedFeedUrl>$(AzureFeedUrl)</ExpectedFeedUrl>
      <AccountKey>$(AzureAccountKey)</AccountKey>
      <ManifestRepoUri>$(BUILD_REPOSITORY_URI)</ManifestRepoUri>
      <ManifestBranch>$(BUILD_SOURCEBRANCH)</ManifestBranch>
      <ManifestBuildData>Location=$(AzureFeedUrl)</ManifestBuildData>
      <ManifestBuildId>$(BUILD_BUILDNUMBER)</ManifestBuildId>
      <ManifestCommit>$(BUILD_SOURCEVERSION)</ManifestCommit>
    </PropertyGroup>

    <ItemGroup>
      <PackagesToPublish Remove="@(PackagesToPublish)" />
      <PackagesToPublish Include="@(ItemsToPushToBlobFeed)" />
    </ItemGroup>
  </Target>

  <Target Name="PublishToSourceBuildStorage">
    <!-- Source Build local storage -->    
    <Copy SourceFiles="@(PackagesToPublish)" DestinationFolder="$(DotNetOutputBlobFeedDir)packages" />
    <Copy SourceFiles="@(ExistingSymbolPackages);@(SymbolPackagesToGenerate)" DestinationFolder="$(DotNetOutputBlobFeedDir)assets" />
  </Target>

  <Target Name="PublishToAzureDevOpsArtifacts">
    <!-- 
      Sadly AzDO doesn't have a variable to tell the account name. Also
      the format of CollectionURI is not precise across different agent 
      configurations. Code below takes care of extracting the account 
      name from the CollectionURI in different formats.
    -->
    <PropertyGroup>
      <CollectionUri>$(SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)</CollectionUri>
      
			<!-- When we have dev.azure.com/<account>/ -->
      <AzureDevOpsAccount Condition="$(CollectionUri.IndexOf('dev.azure.com')) >= 0">$(CollectionUri.Split('/')[3])</AzureDevOpsAccount>
		
			<!-- When we have <account>.visualstudio.com -->
      <AzureDevOpsAccount Condition="$(CollectionUri.IndexOf('visualstudio.com')) >= 0">$(CollectionUri.Split('.')[0].Split('/')[2])</AzureDevOpsAccount>

      <TempWorkingDirectory>$(ArtifactsDir)\..\AssetsTmpDir\$([System.Guid]::NewGuid())</TempWorkingDirectory>

      <!-- Directory where pdbs pointed in `FilesToPublishToSymbolServer` are copied before publishing to AzDO artifacts. -->
      <PDBsToPublishTempLocation>$(ArtifactsTmpDir)PDBsToPublish/</PDBsToPublishTempLocation>
    </PropertyGroup>

    <!--
      The new Maestro/BAR build model keeps separate Azure DevOps and GitHub build information.
      The GitHub information will be extracted based on the Azure DevOps repository.
    -->
    <ItemGroup>
      <NewManifestBuildData Include="InitialAssetsLocation=$(SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$(SYSTEM_TEAMPROJECT)/_apis/build/builds/$(BUILD_BUILDID)/artifacts" />
      <NewManifestBuildData Include="AzureDevOpsBuildId=$(BUILD_BUILDID)" />
      <NewManifestBuildData Include="AzureDevOpsBuildDefinitionId=$(SYSTEM_DEFINITIONID)" />
      <NewManifestBuildData Include="AzureDevOpsAccount=$(AzureDevOpsAccount)" />
      <NewManifestBuildData Include="AzureDevOpsProject=$(SYSTEM_TEAMPROJECT)" />
      <NewManifestBuildData Include="AzureDevOpsBuildNumber=$(BUILD_BUILDNUMBER)" />
      <NewManifestBuildData Include="AzureDevOpsRepository=$(BUILD_REPOSITORY_URI)" />
      <NewManifestBuildData Include="AzureDevOpsBranch=$(BUILD_SOURCEBRANCH)" />

      <!-- 
        Adding this just to not fail the validation when creating the manifest. 
        TODO: Should be removed once PublishingUsingPipelines is the default.
      -->
      <NewManifestBuildData Include="Location=$(AzureFeedUrl)" />
    </ItemGroup>

    <!-- 
      Due to interferences with validate-sdk.ps1 we need to copy a 
      few files to some temporary location until they are published as AzDO artifacts. 
    -->
    <MakeDir Directories="$(TempWorkingDirectory)"/>
    
    <PushToAzureDevOpsArtifacts 
      ItemsToPush="@(ItemsToPushToBlobFeed)"
      ManifestBuildData="@(NewManifestBuildData)"
      ManifestRepoUri="$(BUILD_REPOSITORY_URI)"
      ManifestBranch="$(BUILD_SOURCEBRANCH)"
      ManifestBuildId="$(BUILD_BUILDNUMBER)"
      ManifestCommit="$(BUILD_SOURCEVERSION)"
      IsStableBuild="$(IsStableBuild)"
      PublishFlatContainer="false"
      AssetManifestPath="$(AssetManifestFilePath)"
      AssetsTemporaryDirectory="$(TempWorkingDirectory)" />

    <Message
      Text="##vso[artifact.upload containerfolder=ReleaseConfigs;artifactname=ReleaseConfigs]$(RepositoryEngineeringDir)common/PublishToPackageFeed.proj"
      Importance="high" />

    <!--
      The publishing pipeline (implemented by PublishToPackageFeed.proj) will use the Tasks.Feed package
      to publish packages. The version of Tasks.Feed used will come from DefaultVersions.props
    -->
    <Message
      Text="##vso[artifact.upload containerfolder=ReleaseConfigs;artifactname=ReleaseConfigs]$(MSBuildThisFileDirectory)DefaultVersions.props"
      Condition="Exists('$(MSBuildThisFileDirectory)DefaultVersions.props')"
      Importance="high" />

    <Copy 
      SourceFiles="$(AssetManifestFilePath)" 
      DestinationFolder="$(TempWorkingDirectory)\$(AssetManifestFileName)" />
    
    <Message
      Text="##vso[artifact.upload containerfolder=AssetManifests;artifactname=AssetManifests]$(TempWorkingDirectory)/$(AssetManifestFileName)"
      Importance="high" />

    <WriteLinesToFile
      File="$(MSBuildThisFileDirectory)ArtifactsCategory.props"
      Lines="&lt;Project>&lt;PropertyGroup>&lt;ArtifactsCategory>$(ArtifactsCategory)&lt;/ArtifactsCategory>&lt;/PropertyGroup>&lt;/Project>"
      Overwrite="true"
      Encoding="Unicode" />

    <Message
      Text="##vso[artifact.upload containerfolder=ReleaseConfigs;artifactname=ReleaseConfigs]$(MSBuildThisFileDirectory)ArtifactsCategory.props"
      Importance="high" />


    <!-- 
        Publish Windows PDBs produced by SymStore.targets (by default, only shipping PDBs are placed there).
        SymbolUploader doesn't support embedded PDBs yet, so let SymStore.targets do the conversion for now.
        https://github.com/dotnet/core-eng/issues/3645
      -->
    <ItemGroup>
      <FilesToPublishToSymbolServer Include="$(ArtifactsSymStoreDirectory)**\*.pdb"/>
    </ItemGroup>

    <!--
      The below lines comprise workarounds for two issues:
        - AzDO logging commands don't let us add subfolders by executing different `##vso` commands:
          https://github.com/microsoft/azure-pipelines-tasks/issues/11689 . Therefore a parent folder
          containing all desired subfolders is published. The primary goal of these artifacts isn't
          to be browsable by humans. The target that publish the symbols will filter and publish only
          the PDB files.
        - It's possible that the user have PDBs outside the Arcade.SDK standard folder 
           (artifacts/SymStore/$Configuration) and we need to maintain that support. For that reason,
           and the one mentioned above, we copy all files in `FilesToPublishToSymbolServer` to a temporary
           folder before adding them to the AzDO artifact container.
    -->
		<Copy
			SourceFiles="@(FilesToPublishToSymbolServer)"
			DestinationFiles="@(FilesToPublishToSymbolServer->'$(PDBsToPublishTempLocation)%(RecursiveDir)%(Filename)%(Extension)')" />

    <Message
      Text="##vso[artifact.upload containerfolder=PdbArtifacts;artifactname=PdbArtifacts]$(PDBsToPublishTempLocation)"
      Importance="high" 
      Condition="'@(FilesToPublishToSymbolServer)' != ''"/>

    <Message
      Text="##vso[artifact.upload containerfolder=ReleaseConfigs;artifactname=ReleaseConfigs]$(RepositoryEngineeringDir)common/PublishToSymbolServers.proj"
      Importance="high" />

    <Message
      Text="##vso[artifact.upload containerfolder=ReleaseConfigs;artifactname=ReleaseConfigs]$(RepositoryEngineeringDir)common/CheckSymbols.ps1"
      Importance="high" />

  </Target>

  <Target Name="PublishSymbols">
    <PropertyGroup>
      <DotNetSymbolExpirationInDays Condition="'$(DotNetSymbolExpirationInDays)' == ''">3650</DotNetSymbolExpirationInDays>
      <DryRun>false</DryRun>
    </PropertyGroup>

    <PropertyGroup Condition="'$(OfficialBuild)' != 'true'">
      <DryRun>true</DryRun>
      <DotNetSymbolServerTokenSymWeb>DryRunPTA</DotNetSymbolServerTokenSymWeb>
      <DotNetSymbolServerTokenMsdl>DryRunPTA</DotNetSymbolServerTokenMsdl>
    </PropertyGroup>

    <ItemGroup>
      <!-- 
        Publish Windows PDBs produced by SymStore.targets (by default, only shipping PDBs are placed there).
        SymbolUploader doesn't support embedded PDBs yet, so let SymStore.targets do the conversion for now.
        https://github.com/dotnet/core-eng/issues/3645
      -->
      <FilesToPublishToSymbolServer Include="$(ArtifactsSymStoreDirectory)**\*.pdb"/>

      <!--
        Publish Portable PDBs contained in symbol packages.
      -->
      <PackagesToPublishToSymbolServer Include="@(ExistingSymbolPackages);@(SymbolPackagesToGenerate)"/>
    </ItemGroup>

    <PropertyGroup>
      <PublishToSymbolServer Condition="'@(FilesToPublishToSymbolServer)' == '' and '@(PackagesToPublishToSymbolServer)' == ''">false</PublishToSymbolServer>
    </PropertyGroup>

    <!-- Symbol Uploader: MSDL -->
    <Message Importance="High" Text="Publishing symbol packages to MSDL ..." Condition="$(PublishToSymbolServer)" />
    <PublishSymbols PackagesToPublish="@(PackagesToPublishToSymbolServer)"
                    FilesToPublish="@(FilesToPublishToSymbolServer)"
                    PersonalAccessToken="$(DotNetSymbolServerTokenMsdl)"
                    SymbolServerPath="https://microsoftpublicsymbols.artifacts.visualstudio.com/DefaultCollection"
                    ExpirationInDays="$(DotNetSymbolExpirationInDays)"
                    VerboseLogging="true"
                    DryRun="$(DryRun)"
                    ConvertPortablePdbsToWindowsPdbs="false"
                    PdbConversionTreatAsWarning=""
                    Condition="$(PublishToSymbolServer)"/>

    <!-- 
      Symbol Uploader: SymWeb 
      Watson, VS insertion testings and the typical internal dev usage require SymWeb.
      Currently we need to call the task twice (https://github.com/dotnet/core-eng/issues/3489).
    -->
    <Message Importance="High" Text="Publishing symbol packages to SymWeb ..." Condition="$(PublishToSymbolServer)" />
    <PublishSymbols PackagesToPublish="@(PackagesToPublishToSymbolServer)"
                    FilesToPublish="@(FilesToPublishToSymbolServer)"
                    PersonalAccessToken="$(DotNetSymbolServerTokenSymWeb)"
                    SymbolServerPath="https://microsoft.artifacts.visualstudio.com/DefaultCollection"
                    ExpirationInDays="$(DotNetSymbolExpirationInDays)"
                    VerboseLogging="true"
                    DryRun="$(DryRun)"
                    ConvertPortablePdbsToWindowsPdbs="false"
                    PdbConversionTreatAsWarning=""
                    Condition="$(PublishToSymbolServer)"/>
  </Target>

</Project>