summaryrefslogtreecommitdiff
path: root/Tools/PublishContent.targets
blob: c4a732153f476e52f8fa0d3ecc6d92a54ba0c0c4 (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
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <UsingTask TaskName="CreateAzureContainer" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.CloudTestTasks.dll"/>
  <UsingTask TaskName="UploadToAzure" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.CloudTestTasks.dll"/>

  <PropertyGroup>
    <OverwriteOnPublish Condition="'$(OverwriteOnPublish)' == ''">false</OverwriteOnPublish>
  </PropertyGroup>

  <!-- gathers the items to be published -->
  <Target Name="GatherItemsForPattern">
    <Error Condition="'$(PublishPattern)' == ''" Text="Please specify a value for PublishPattern using standard msbuild 'include' syntax." />

    <PropertyGroup>
      <RelativeBlobPathBase>$(BlobNamePrefix)</RelativeBlobPathBase>
      <RelativeBlobPathBase Condition="'$(RelativeBlobPathBase)' != '' and !HasTrailingSlash('$(RelativeBlobPathBase)')">$(RelativeBlobPathBase)/</RelativeBlobPathBase>
    </PropertyGroup>
    <ItemGroup>
      <ForPublishing Include="$(PublishPattern)" />
    </ItemGroup>
    <!-- add relative blob path metadata -->
    <ItemGroup>
      <ForPublishing>
        <RelativeBlobPath>$(RelativeBlobPathBase)$([System.String]::Copy('%(RecursiveDir)%(Filename)%(Extension)').Replace('\' ,'/'))</RelativeBlobPath>
      </ForPublishing>
    </ItemGroup>
    <Error Condition="'@(ForPublishing)' == ''" Text="No items were found matching pattern '$(PublishPattern)'." />
  </Target>

  <!-- publishes items to blob storage in Azure -->
  <Target Name="UploadToAzure" DependsOnTargets="GatherItemsForPattern">
    <Error Condition="'$(ContainerName)' == ''" Text="Missing property ContainerName." />
    <Error Condition="'$(CloudDropAccountName)' == ''" Text="Missing property CloudDropAccountName." />
    <Error Condition="'$(CloudDropAccessToken)' == ''" Text="Missing property CloudDropAccessToken." />
    <!-- create the container if it doesn't exist -->
    <CreateAzureContainer
      AccountKey="$(CloudDropAccessToken)"
      AccountName="$(CloudDropAccountName)"
      ContainerName="$(ContainerName)" />
    <!-- now upload the items -->
    <UploadToAzure
      AccountKey="$(CloudDropAccessToken)"
      AccountName="$(CloudDropAccountName)"
      ContainerName="$(ContainerName)"
      Items="@(ForPublishing)"
      Overwrite="$(OverwriteOnPublish)" />
  </Target>

</Project>