Adding a task to set the blob properties correctly based on type.

This commit is contained in:
Livar Cunha 2016-07-15 11:40:56 -07:00
parent 6d7f110122
commit 03a17a9b76
4 changed files with 75 additions and 1 deletions

View file

@ -5,6 +5,7 @@
<UsingTask TaskName="UploadToAzure" AssemblyFile="$(BuildToolsTaskDir)/Microsoft.DotNet.Build.CloudTestTasks.dll"/>
<UsingTask TaskName="FinalizeBuildTask" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="SetBlobPropertiesBasedOnFileTypeTask" AssemblyFile="$(CLIBuildDll)" />
<!-- PUBLISH_TO_AZURE_BLOB env variable set by CI -->
<Target Name="Publish"
@ -97,5 +98,10 @@
AccountName="$(CloudDropAccountName)"
ContainerName="$(ContainerName)"
Items="@(CliVersionBadgeToUpload)" />
<SetBlobPropertiesBasedOnFileTypeTask
AccountKey="$(CloudDropAccessToken)"
AccountName="$(CloudDropAccountName)"
Items="@(CliVersionBadgeToUpload)" />
</Target>
</Project>

View file

@ -30,7 +30,8 @@ namespace Microsoft.DotNet.Cli.Build
[Required]
public string BranchName { get; set; }
private AzurePublisher AzurePublisherTool {
private AzurePublisher AzurePublisherTool
{
get
{
if(_azurePublisher == null)

View file

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace Microsoft.DotNet.Cli.Build
{
public class SetBlobPropertiesBasedOnFileTypeTask : Task
{
private AzurePublisher _azurePublisher;
[Required]
public string AccountName { get; set; }
[Required]
public string AccountKey { get; set; }
[Required]
public ITaskItem[] Items { get; set; }
private AzurePublisher AzurePublisherTool
{
get
{
if(_azurePublisher == null)
{
_azurePublisher = new AzurePublisher(AccountName, AccountKey);
}
return _azurePublisher;
}
}
public override bool Execute()
{
if (Items.Length == 0)
{
Log.LogError("No items were provided for upload.");
return false;
}
foreach(var item in Items)
{
string relativeBlobPath = item.GetMetadata("RelativeBlobPath");
if (string.IsNullOrEmpty(relativeBlobPath))
{
throw new Exception(string.Format(
"Metadata 'RelativeBlobPath' is missing for item '{0}'.",
item.ItemSpec));
}
AzurePublisherTool.SetBlobPropertiesBasedOnFileType(relativeBlobPath);
}
return true;
}
}
}

View file

@ -92,6 +92,12 @@ namespace Microsoft.DotNet.Cli.Build
target.StartCopyAsync(source).Wait();
}
public void SetBlobPropertiesBasedOnFileType(string path)
{
CloudBlockBlob blob = _blobContainer.GetBlockBlobReference(path);
SetBlobPropertiesBasedOnFileType(blob);
}
private void SetBlobPropertiesBasedOnFileType(CloudBlockBlob blockBlob)
{
if (Path.GetExtension(blockBlob.Uri.AbsolutePath.ToLower()) == ".svg")