|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#nullable disable
using Microsoft.Build.Framework;
namespace Microsoft.AspNetCore.StaticWebAssets.Tasks;
[MSBuildMultiThreadableTask]
public class ReadStaticWebAssetsManifestFile : Task, IMultiThreadableTask
{
[Required]
public string ManifestPath { get; set; }
[Output]
public ITaskItem[] Assets { get; set; }
[Output]
public ITaskItem[] Endpoints { get; set; }
[Output]
public ITaskItem[] DiscoveryPatterns { get; set; }
[Output]
public ITaskItem[] ReferencedProjectsConfiguration { get; set; }
public TaskEnvironment TaskEnvironment { get; set; } = TaskEnvironment.Fallback;
public override bool Execute()
{
string manifestPath = string.IsNullOrEmpty(ManifestPath) ? ManifestPath : TaskEnvironment.GetAbsolutePath(ManifestPath);
if (!File.Exists(manifestPath))
{
Log.LogError($"Manifest file at '{ManifestPath}' not found.");
return false;
}
try
{
var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(manifestPath));
Assets = manifest.Assets?.Select(a => a.ToTaskItem()).ToArray() ?? [];
Endpoints = manifest.Endpoints?.Select(a => a.ToTaskItem()).ToArray() ?? Array.Empty<ITaskItem>();
DiscoveryPatterns = manifest.DiscoveryPatterns?.Select(dp => dp.ToTaskItem()).ToArray() ?? [];
ReferencedProjectsConfiguration = manifest.ReferencedProjectsConfiguration?.Select(m => m.ToTaskItem()).ToArray() ?? [];
}
catch (Exception ex)
{
Log.LogErrorFromException(ex, showStackTrace: true, showDetail: true, file: ManifestPath);
}
return !Log.HasLoggedErrors;
}
}
|