diff options
author | Doug Bunting (AAPT) <dougbu@microsoft.com> | 2021-11-29 22:00:32 +0300 |
---|---|---|
committer | Doug Bunting (AAPT) <dougbu@microsoft.com> | 2021-11-29 22:00:32 +0300 |
commit | 220d4d14e05e15b4cd8a19a0da23c88a90ccd37d (patch) | |
tree | 42c0efdb0e5553ab05abac869f02bad1c07e9b53 | |
parent | e49ee2b6fee42d780f4c1ee71714e745d4d63125 (diff) |
[release/2.1] Use new packages in RepoTasks.csproj (#20077)
- use Azure.Storage.Blobs v12.10.0
- WindowsAzure.Storage v8.7.0 brings in packages w/ expired certificates
- avoid earlier versions because they attempt to bring in Newtonsoft.Json v10.0.2 or later
- this version eliminates that dependency
- i.e. don't attempt to override Newtonsoft.Json v9.0.1 used in NuGet.* packages
- react to breaking changes between Microsoft.Azure.Storage.Blob and Azure.Storage.Blobs
- WindowsAzure.Storage and Microsoft.Azure.Storage.Blob API surface was similar
!debug! Spit out RestoreTask inputs
-rw-r--r-- | build/dependencies.props | 2 | ||||
-rw-r--r-- | build/tasks/PublishToAzureBlob.cs | 41 | ||||
-rw-r--r-- | build/tasks/RepoTasks.csproj | 15 |
3 files changed, 42 insertions, 16 deletions
diff --git a/build/dependencies.props b/build/dependencies.props index 1f51bae966..d35a02f380 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -101,7 +101,7 @@ <CastleCorePackageVersion>4.2.1</CastleCorePackageVersion> <DevDependency_MicrosoftDotNetBuildTasksFeedPackageVersion>2.1.0-prerelease-02430-04</DevDependency_MicrosoftDotNetBuildTasksFeedPackageVersion> <DevDependency_MicrosoftExtensionsDependencyModelPackageVersion>2.1.0</DevDependency_MicrosoftExtensionsDependencyModelPackageVersion> - <DevDependency_WindowsAzureStoragePackageVersion>8.7.0</DevDependency_WindowsAzureStoragePackageVersion> + <DevDependency_AzureStorageBlobsPackageVersion>12.10.0</DevDependency_AzureStorageBlobsPackageVersion> <FSharpCorePackageVersion>4.2.3</FSharpCorePackageVersion> <GoogleProtobufPackageVersion>3.1.0</GoogleProtobufPackageVersion> <LibuvPackageVersion>1.10.0</LibuvPackageVersion> diff --git a/build/tasks/PublishToAzureBlob.cs b/build/tasks/PublishToAzureBlob.cs index 86150d0be3..f109065ab8 100644 --- a/build/tasks/PublishToAzureBlob.cs +++ b/build/tasks/PublishToAzureBlob.cs @@ -7,9 +7,11 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Azure; +using Azure.Storage.Blobs; +using Azure.Storage.Blobs.Models; +using Azure.Storage.Blobs.Specialized; using Microsoft.Build.Framework; -using Microsoft.WindowsAzure.Storage; -using Microsoft.WindowsAzure.Storage.Blob; namespace RepoTasks { @@ -58,11 +60,10 @@ namespace RepoTasks { var connectionString = $"BlobEndpoint=https://{AccountName}.blob.core.windows.net;SharedAccessSignature={SharedAccessToken}"; - var account = CloudStorageAccount.Parse(connectionString); - var client = account.CreateCloudBlobClient(); - var container = client.GetContainerReference(ContainerName); + var client = new BlobServiceClient(connectionString); + var container = client.GetBlobContainerClient(ContainerName); + await container.CreateIfNotExistsAsync(); - var ctx = new OperationContext(); var tasks = new List<Task>(); using (var throttler = new SemaphoreSlim(MaxParallelism)) @@ -76,7 +77,7 @@ namespace RepoTasks { try { - await PushFileAsync(ctx, container, item, _cts.Token); + await PushFileAsync(container, item, _cts.Token); } finally { @@ -91,7 +92,7 @@ namespace RepoTasks return !Log.HasLoggedErrors; } - private async Task PushFileAsync(OperationContext ctx, CloudBlobContainer container, ITaskItem item, CancellationToken cancellationToken) + private async Task PushFileAsync(BlobContainerClient container, ITaskItem item, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -108,27 +109,39 @@ namespace RepoTasks return; } - var blob = container.GetBlockBlobReference(dest); + var blob = container.GetBlockBlobClient(dest); + var headers = new BlobHttpHeaders(); if (!string.IsNullOrEmpty(cacheControl)) { - blob.Properties.CacheControl = cacheControl; + headers.CacheControl = cacheControl; } if (!string.IsNullOrEmpty(contentType)) { - blob.Properties.ContentType = contentType; + headers.ContentType = contentType; } Log.LogMessage(MessageImportance.High, $"Beginning push of {item.ItemSpec} to https://{AccountName}.blob.core.windows.net/{ContainerName}/{dest}"); var accessCondition = bool.TryParse(item.GetMetadata("Overwrite"), out var overwrite) && overwrite - ? AccessCondition.GenerateEmptyCondition() - : AccessCondition.GenerateIfNotExistsCondition(); + ? null + : new BlobRequestConditions + { + IfNoneMatch = ETag.All, + }; + var uploadOptions = new BlobUploadOptions + { + Conditions = accessCondition, + HttpHeaders = headers, + }; try { - await blob.UploadFromFileAsync(item.ItemSpec, accessCondition, new BlobRequestOptions(), ctx, cancellationToken); + await blob.UploadAsync( + new FileStream(item.ItemSpec, FileMode.Open, FileAccess.Read), + uploadOptions, + cancellationToken); } catch (Exception ex) { diff --git a/build/tasks/RepoTasks.csproj b/build/tasks/RepoTasks.csproj index 0b7fe229f0..3aa413c522 100644 --- a/build/tasks/RepoTasks.csproj +++ b/build/tasks/RepoTasks.csproj @@ -11,9 +11,22 @@ <PackageReference Include="Microsoft.DotNet.Archive" Version="$(MicrosoftDotNetArchivePackageVersion)" /> <PackageReference Include="NuGet.Build.Tasks" Version="$(NuGetInMSBuildVersion)" /> <PackageReference Include="Microsoft.Extensions.DependencyModel" Version="$(DevDependency_MicrosoftExtensionsDependencyModelPackageVersion)" /> - <PackageReference Include="WindowsAzure.Storage" Version="$(DevDependency_WindowsAzureStoragePackageVersion)" /> + <PackageReference Include="Azure.Storage.Blobs" Version="$(DevDependency_AzureStorageBlobsPackageVersion)" /> <PackageReference Include="Microsoft.DotNet.Build.Tasks.Feed" Version="$(DevDependency_MicrosoftDotNetBuildTasksFeedPackageVersion)" ExcludeAssets="Build" /> </ItemGroup> + <Target Name="DebugRestore" BeforeTargets="Restore"> + <Message Importance="High" Text="HideWarningsAndErrors: '$(HideWarningsAndErrors)'" /> + <Message Importance="High" Text="NuGetInteractive: '$(NuGetInteractive)'" /> + <Message Importance="High" Text="RestoreDisableParallel: '$(RestoreDisableParallel)'" /> + <Message Importance="High" Text="RestoreForce: '$(RestoreForce)'" /> + <Message Importance="High" Text="RestoreForceEvaluate: '$(RestoreForceEvaluate)'" /> + <Message Importance="High" Text="RestoreIgnoreFailedSources: '$(RestoreIgnoreFailedSources)'" /> + <Message Importance="High" Text="RestoreNoCache: '$(RestoreNoCache)'" /> + <Message Importance="High" Text="RestoreRecursive: '$(RestoreRecursive)'" /> + <Message Importance="High" Text="_RestoreGraphEntry: @(_RestoreGraphEntry -> '%(Id) %(VersionRange)')" + Condition=" '%(_RestoreGraphEntry.Type)' == 'Dependency' AND '%(_RestoreGraphEntry.Id)' != '' " /> + </Target> + <Import Project="$(RepoTasksSdkPath)\Sdk.targets" Condition="'$(RepoTasksSdkPath)' != '' "/> </Project> |