public override bool Execute() { try { var currentProjectAssets = Assets .Where(asset => StaticWebAsset.HasSourceId(asset, Source)) .Select(StaticWebAsset.FromTaskItem) .GroupBy( a => a.ComputeTargetPath("", '/'), (key, group) => (key, StaticWebAsset.ChooseNearestAssetKind(group, AssetKind))); var resultAssets = new List <StaticWebAsset>(); foreach (var(key, group) in currentProjectAssets) { if (!TryGetUniqueAsset(group, out var selected)) { if (selected == null) { Log.LogMessage(MessageImportance.Low, "No compatible asset found for '{0}'", key); continue; } else { Log.LogError("More than one compatible asset found for '{0}'.", selected.Identity); return(false); } } if (!selected.IsForReferencedProjectsOnly()) { resultAssets.Add(selected); } else { Log.LogMessage(MessageImportance.Low, "Skipping asset '{0}' because it is for referenced projects only.", selected.Identity); } } StaticWebAssets = resultAssets .Select(a => a.ToTaskItem()) .Concat(Assets.Where(asset => !StaticWebAsset.HasSourceId(asset, Source))) .ToArray(); } catch (Exception ex) { Log.LogError(ex.ToString()); } return(!Log.HasLoggedErrors); }
internal static bool ValidateAssetGroup(string path, StaticWebAsset [] group, string assetKind, out string reason) { StaticWebAsset prototypeItem = null; StaticWebAsset build = null; StaticWebAsset publish = null; StaticWebAsset all = null; foreach (var item in group) { prototypeItem ??= item; if (!prototypeItem.HasSourceId(item.SourceId)) { reason = $"Conflicting assets with the same target path '{path}'. For assets '{prototypeItem}' and '{item}' from different projects."; return(false); } build ??= item.IsBuildOnly() ? item : build; if (build != null && item.IsBuildOnly() && !ReferenceEquals(build, item)) { reason = $"Conflicting assets with the same target path '{path}'. For 'Build' assets '{build}' and '{item}'."; return(false); } publish ??= item.IsPublishOnly() ? item : publish; if (publish != null && item.IsPublishOnly() && !ReferenceEquals(publish, item)) { reason = $"Conflicting assets with the same target path '{path}'. For 'Publish' assets '{publish}' and '{item}'."; return(false); } all ??= item.IsBuildAndPublish() ? item : all; if (all != null && item.IsBuildAndPublish() && !ReferenceEquals(all, item)) { reason = $"Conflicting assets with the same target path '{path}'. For 'All' assets '{all}' and '{item}'."; return(false); } } reason = null; return(true); }
public override bool Execute() { try { var existingAssets = Assets .Where(asset => StaticWebAsset.HasSourceId(asset, Source)) .Select(StaticWebAsset.FromTaskItem) .GroupBy( a => a.ComputeTargetPath("", '/'), (key, group) => (key, StaticWebAsset.ChooseNearestAssetKind(group, AssetKind))); var resultAssets = new List <StaticWebAsset>(); foreach (var(key, group) in existingAssets) { if (!TryGetUniqueAsset(group, out var selected)) { if (selected == null) { Log.LogMessage("No compatible asset found for '{0}'", key); continue; } else { Log.LogError("More than one compatible asset found for '{0}'.", selected.Identity); return(false); } } if (ShouldIncludeAssetAsReference(selected, out var reason)) { selected.SourceType = StaticWebAsset.SourceTypes.Project; resultAssets.Add(selected); } Log.LogMessage(reason); } var patterns = new List <StaticWebAssetsManifest.DiscoveryPattern>(); if (Patterns != null) { foreach (var pattern in Patterns) { if (!StaticWebAssetsManifest.DiscoveryPattern.HasSourceId(pattern, Source)) { Log.LogMessage("Skipping pattern '{0}' because is not defined in the current project.", pattern.ItemSpec); } else { Log.LogMessage("Including pattern '{0}' because is defined in the current project.", pattern.ToString()); patterns.Add(StaticWebAssetsManifest.DiscoveryPattern.FromTaskItem(pattern)); } } } StaticWebAssets = resultAssets.Select(a => a.ToTaskItem()).ToArray(); DiscoveryPatterns = patterns.Select(p => p.ToTaskItem()).ToArray(); } catch (Exception ex) { Log.LogErrorFromException(ex, showStackTrace: true, showDetail: true, file: null); } return(!Log.HasLoggedErrors); }
internal bool IsCurrentProjectAsset(StaticWebAsset asset) => asset.HasSourceId(Source);
internal bool HasSourceId(string source) => StaticWebAsset.HasSourceId(SourceId, source);