public ProjectRestoreMetadata Clone()
 {
     return(new ProjectRestoreMetadata
     {
         ProjectStyle = ProjectStyle,
         ProjectPath = ProjectPath,
         ProjectJsonPath = ProjectJsonPath,
         OutputPath = OutputPath,
         ProjectName = ProjectName,
         ProjectUniqueName = ProjectUniqueName,
         PackagesPath = PackagesPath,
         CacheFilePath = CacheFilePath,
         CrossTargeting = CrossTargeting,
         LegacyPackagesDirectory = LegacyPackagesDirectory,
         SkipContentFileWrite = SkipContentFileWrite,
         ValidateRuntimeAssets = ValidateRuntimeAssets,
         FallbackFolders = FallbackFolders != null ? new List <string>(FallbackFolders) : null,
         ConfigFilePaths = ConfigFilePaths != null ? new List <string>(ConfigFilePaths) : null,
         OriginalTargetFrameworks = OriginalTargetFrameworks != null ? new List <string>(OriginalTargetFrameworks) : null,
         Sources = Sources?.Select(c => c.Clone()).ToList(),
         TargetFrameworks = TargetFrameworks?.Select(c => c.Clone()).ToList(),
         Files = Files?.Select(c => c.Clone()).ToList(),
         ProjectWideWarningProperties = ProjectWideWarningProperties?.Clone()
     });
 }
Example #2
0
        public override bool Execute()
        {
            // We inspect the target frameworks available to find out an appropriate candidate to use for computing the list of
            // static web assets for packing.
            // Target frameworks have the following pattern {FrameworkIdentifier,FrameworkVersion,PlatformIdentifier?,PlatformVersion?}
            // for example: net6.0-windows.10.1980 or net-6.0-ios.14.2.
            // We don't deal with any parsing because that's handled by MSBuild. We also don't care about the platform identifier or the
            // platform version. The reason is explained below.
            // Static web assets don't support having different content based on the target framework. If you are multitargeting (for example,
            // in a Razor Class Library) we consider that all TFMs should produce the same set of static web assets and that we can, as a
            // result, pick any target framework to act as a representative when we are packing the assets into the package.
            // If a package is multitargeting across multiple versions of static web assets, (netstandard2.0 and net6.0 for example) we always
            // use as representative the framework with the highest static web assets version (net6.0 in this case).
            // Platform identifier and version, don't matter because as mentioned above, the list of assets should be identical in those cases
            // and we can pick among any of them to act as a representative for packing purposes.
            var selectedFramework = TargetFrameworks
                                    .Select(tf => new FrameworkItem(tf))
                                    .Select(fi => (version: fi.GetStaticWebAssetsVersion(), framework: fi))
                                    .OrderByDescending(p => p.version)
                                    .FirstOrDefault(p => p.version > 0);

            EffectiveTargetFramework = selectedFramework.framework?.Moniker;

            return(!Log.HasLoggedErrors);
        }
Example #3
0
 protected void FillClone(ProjectRestoreMetadata clone)
 {
     clone.ProjectStyle             = ProjectStyle;
     clone.ProjectPath              = ProjectPath;
     clone.ProjectJsonPath          = ProjectJsonPath;
     clone.OutputPath               = OutputPath;
     clone.ProjectName              = ProjectName;
     clone.ProjectUniqueName        = ProjectUniqueName;
     clone.PackagesPath             = PackagesPath;
     clone.CacheFilePath            = CacheFilePath;
     clone.CrossTargeting           = CrossTargeting;
     clone.LegacyPackagesDirectory  = LegacyPackagesDirectory;
     clone.SkipContentFileWrite     = SkipContentFileWrite;
     clone.ValidateRuntimeAssets    = ValidateRuntimeAssets;
     clone.FallbackFolders          = FallbackFolders != null ? new List <string>(FallbackFolders) : null;
     clone.ConfigFilePaths          = ConfigFilePaths != null ? new List <string>(ConfigFilePaths) : null;
     clone.OriginalTargetFrameworks = OriginalTargetFrameworks != null ? new List <string>(OriginalTargetFrameworks) : null;
     clone.Sources                                = Sources?.Select(c => c.Clone()).ToList();
     clone.TargetFrameworks                       = TargetFrameworks?.Select(c => c.Clone()).ToList();
     clone.Files                                  = Files?.Select(c => c.Clone()).ToList();
     clone.ProjectWideWarningProperties           = ProjectWideWarningProperties?.Clone();
     clone.RestoreLockProperties                  = RestoreLockProperties?.Clone();
     clone.CentralPackageVersionsEnabled          = CentralPackageVersionsEnabled;
     clone.CentralPackageVersionOverrideDisabled  = CentralPackageVersionOverrideDisabled;
     clone.CentralPackageTransitivePinningEnabled = CentralPackageTransitivePinningEnabled;
 }
Example #4
0
        public ProjectRestoreMetadata Clone()
        {
            var clonedObject = new ProjectRestoreMetadata();

            clonedObject.ProjectStyle             = ProjectStyle;
            clonedObject.ProjectPath              = ProjectPath;
            clonedObject.ProjectJsonPath          = ProjectJsonPath;
            clonedObject.OutputPath               = OutputPath;
            clonedObject.ProjectName              = ProjectName;
            clonedObject.ProjectUniqueName        = ProjectUniqueName;
            clonedObject.PackagesPath             = PackagesPath;
            clonedObject.CacheFilePath            = CacheFilePath;
            clonedObject.CrossTargeting           = CrossTargeting;
            clonedObject.LegacyPackagesDirectory  = LegacyPackagesDirectory;
            clonedObject.SkipContentFileWrite     = SkipContentFileWrite;
            clonedObject.ValidateRuntimeAssets    = ValidateRuntimeAssets;
            clonedObject.FallbackFolders          = FallbackFolders != null ? new List <string>(FallbackFolders) : null;
            clonedObject.ConfigFilePaths          = ConfigFilePaths != null ? new List <string>(ConfigFilePaths) : null;
            clonedObject.OriginalTargetFrameworks = OriginalTargetFrameworks != null ? new List <string>(OriginalTargetFrameworks) : null;
            clonedObject.Sources                      = Sources?.Select(c => c.Clone()).ToList();
            clonedObject.TargetFrameworks             = TargetFrameworks?.Select(c => c.Clone()).ToList();
            clonedObject.Files                        = Files?.Select(c => c.Clone()).ToList();
            clonedObject.ProjectWideWarningProperties = ProjectWideWarningProperties?.Clone();
            return(clonedObject);
        }
Example #5
0
        public override bool Execute()
        {
            int tfwCount = TargetFrameworks.Length;
            MSBuildFileSetResult fileSetResult = new()
            {
                Projects = WatchFiles
                           .GroupBy(item => item.GetMetadata("ProjectFullPath"))
                           .ToDictionary(
                    group => group.Key,
                    group => group
                    .GroupBy(item => item.GetMetadata("FullPath"))
                    .Select(group => new ProjectFiles
                {
                    FilePath         = group.Key,
                    TargetFrameworks =

                        /*group.Count() == tfwCount
                         * ? ""
                         * :*/string.Join(";", group.Select(group => group.GetMetadata("TFW")))
                })
                    .ToList()),
                TargetFrameworks = TargetFrameworks
                                   .Select(item => new TargetFrameworkItem()
                {
                    Name         = item.ItemSpec,
                    Identifier   = item.GetMetadata("Identifier"),
                    Version      = item.GetMetadata("Version").Substring(1),
                    AssemblyPath = item.GetMetadata("Path"),
                })
                                   .ToList(),
            };

            using FileStream fileStream = new(OutputPath.ItemSpec, FileMode.Create, FileAccess.Write, FileShare.None, 1, true);
            byte[] json = JsonSerializer.SerializeToUtf8Bytes(fileSetResult);
            fileStream.Write(json, 0, json.Length);

            return(!Log.HasLoggedErrors);
        }
        private bool Execute(TargetsDefinitions targets)
        {
            var allTargets = new List <string>();

            if (TargetFramework != null)
            {
                allTargets.Add(TargetFramework.ToString());
            }

            if (TargetFrameworks != null)
            {
                allTargets.AddRange(TargetFrameworks.Select(x => x.ToString()));
            }

            allTargets = allTargets.Distinct().ToList();

            // first, check required targets
            Log.LogMessage(
                MessageImportance.Low,
                $"Comparing TargetFramework[s] ({string.Join(";", allTargets)}) to required: {string.Join(",", targets.RequiredTargets.Select(x => x.Name))}.");

            foreach (var requiredTarget in targets.RequiredTargets)
            {
                if (Omitted != null && Omitted.Any(x => x.ToString().Equals(requiredTarget.Name, StringComparison.OrdinalIgnoreCase)))
                {
                    Log.LogMessage(MessageImportance.Low, $"Required TargetFramework '{requiredTarget.Name}' is set to omit.");
                    continue;
                }

                if (allTargets.Any(x => x.Equals(requiredTarget.Name, StringComparison.OrdinalIgnoreCase)))
                {
                    continue;
                }

                var found = requiredTarget.Alternatives?.Any(alternative => allTargets.Contains(alternative));
                if (found.GetValueOrDefault(false))
                {
                    continue;
                }

                Log.LogError(
                    null,
                    "CCG0007",
                    string.Empty,
                    ProjectFile ?? string.Empty,
                    0,
                    0,
                    0,
                    0,
                    "Missing required target: " + requiredTarget.Name);
                return(false);
            }

            // now, check suggested targets
            Log.LogMessage(
                MessageImportance.Low,
                $"Comparing TargetFramework[s] ({string.Join(";", allTargets)}) to suggested: {string.Join(",", targets.SuggestedTargets.Select(x => x.Name))}.");

            foreach (var suggestedTarget in targets.SuggestedTargets)
            {
                if (Omitted != null && Omitted.Any(x => x.ToString().Equals(suggestedTarget.Name, StringComparison.OrdinalIgnoreCase)))
                {
                    Log.LogMessage(MessageImportance.Low, $"Suggested TargetFramework '{suggestedTarget.Name}' is set to omit.");
                    continue;
                }

                if (allTargets.Any(x => x.Equals(suggestedTarget.Name, StringComparison.OrdinalIgnoreCase)))
                {
                    continue;
                }

                var found = suggestedTarget.Alternatives?.Any(alternative => allTargets.Contains(alternative));
                if (found.GetValueOrDefault(false))
                {
                    continue;
                }

                Log.LogWarning(
                    null,
                    "CCG0007",
                    string.Empty,
                    ProjectFile ?? string.Empty,
                    0,
                    0,
                    0,
                    0,
                    "Missing suggested target: " + suggestedTarget.Name);
            }

            return(true);
        }