public bool Check(ProjectBuildCheckContext context, out string failureMessage)
        {
            context.Logger.LogVerbose(string.Empty);
            context.Logger.LogVerbose("CheckUpToDateCheckBuiltItems:");

            foreach (ProjectItemInstance copiedOutputFiles in context.Instance.GetItems("UpToDateCheckBuilt").Where(i => i.HasMetadata("Original") && !string.IsNullOrEmpty(i.GetMetadataValue("Original"))))
            {
                var source      = ConvertToAbsolutePath(copiedOutputFiles.GetMetadataValue("Original"), Path.GetDirectoryName(context.Instance.FullPath));
                var destination = copiedOutputFiles.GetMetadataValue("FullPath");

                context.Logger.LogVerbose($"    Checking copied output (UpToDateCheckBuilt with Original property) file '{source}':");

                DateTime?sourceTime = Utilities.GetTimestampUtc(source, context.TimeStampCache);

                if (sourceTime != null)
                {
                    context.Logger.LogVerbose($"        Source {sourceTime}: '{source}'.");
                }
                else
                {
                    failureMessage = $"Source '{source}' does not exist, not up to date.";
                    context.Logger.LogVerbose($"    {failureMessage}");
                    return(false);
                }

                DateTime?destinationTime = Utilities.GetTimestampUtc(destination, context.TimeStampCache);

                if (destinationTime != null)
                {
                    context.Logger.LogVerbose($"        Destination {destinationTime}: '{destination}'.");
                }
                else
                {
                    failureMessage = "Destination '{destination}' does not exist, not up to date.";
                    context.Logger.LogVerbose($"    {failureMessage}");
                    return(false);
                }

                if (destinationTime < sourceTime)
                {
                    failureMessage = "Source is newer than build output destination, not up to date.";
                    context.Logger.LogVerbose($"    {failureMessage}");
                    return(false);
                }
            }

            context.Logger.LogVerbose("    Up to date.");

            failureMessage = string.Empty;
            return(true);
        }
Exemple #2
0
        public bool Check(ProjectBuildCheckContext context, out string failureMessage)
        {
            context.Logger.LogVerbose(string.Empty);
            context.Logger.LogVerbose("CheckOutputsAreValid:");

            (DateTime? outputTime, string outputPath) = GetEarliestOutput(context.Outputs, context.TimeStampCache);

            if (outputTime != null)
            {
                // Search for an input that's either missing or newer than the earliest output.
                // As soon as we find one, we can stop the scan.
                // Due to some recently introduced issues (https://github.com/dotnet/project-system/issues/4736),
                // explicitly skip the CoreCompileInputs.cache file.
                foreach (string input in context.Inputs.Where(i => !i.EndsWith(".CoreCompileInputs.cache", StringComparison.OrdinalIgnoreCase)))
                {
                    DateTime?time = Utilities.GetTimestampUtc(input, context.TimeStampCache);

                    if (time == null)
                    {
                        failureMessage = $"Input '{input}' does not exist, not up to date.";
                        context.Logger.LogVerbose($"    {failureMessage}");
                        return(false);
                    }

                    if (time > outputTime)
                    {
                        failureMessage = $"Input '{input}' is newer ({time.Value:O}) than earliest output '{outputPath}' ({outputTime.Value:O}), not up to date.";
                        context.Logger.LogVerbose($"    {failureMessage}");
                        return(false);
                    }
                }

                context.Logger.LogVerbose($"    No inputs are newer than earliest output '{outputPath}' ({outputTime.Value}).");
            }
            else if (outputPath != null)
            {
                failureMessage = $"Output '{outputPath}' does not exist, not up to date.";
                context.Logger.LogVerbose($"    {failureMessage}");
                return(false);
            }
            else
            {
                context.Logger.LogVerbose("    No build outputs defined.");
            }

            context.Logger.LogVerbose("    Up to date.");

            failureMessage = string.Empty;
            return(true);
        }
Exemple #3
0
        public bool Check(ProjectBuildCheckContext context, out string failureMessage)
        {
            context.Logger.LogVerbose(string.Empty);
            context.Logger.LogVerbose("CheckAlwaysCopyToOutput:");

            IEnumerable <ProjectItemInstance> itemsUpToDateCheckInput = context.Instance.Items.Where(i => _itemTypesForUpToDateCheckInput.Contains(i.ItemType));

            foreach (ProjectItemInstance a in itemsUpToDateCheckInput)
            {
                if (a.HasMetadata("CopyToOutputDirectory") && a.GetMetadataValue("CopyToOutputDirectory").Equals("Always", StringComparison.OrdinalIgnoreCase))
                {
                    failureMessage = $"Item '{a.GetMetadataValue("FullPath")}' has CopyToOutputDirectory set to 'Always', not up to date.";
                    context.Logger.LogVerbose($"    {failureMessage}");
                    return(false);
                }
            }

            context.Logger.LogVerbose("    Up to date.");

            failureMessage = string.Empty;
            return(true);
        }
        public bool Check(ProjectBuildCheckContext context, out string failureMessage)
        {
            failureMessage = string.Empty;

            context.Logger.LogVerbose(string.Empty);
            context.Logger.LogVerbose("CheckCopyUpToDateMarkersValid:");

            ProjectItemInstance markerFileItem = context.Instance.GetItems("CopyUpToDateMarker").FirstOrDefault();

            if (string.IsNullOrWhiteSpace(markerFileItem?.EvaluatedInclude))
            {
                // This should happen on non-SDK Projects
                context.Logger.LogVerbose("    Not an SDK project. Marker files aren't used. Up to date.");
                return(true);
            }

            // Get all of the reference assemblies.
            List <string> copyReferenceInputs = context.Instance.GetItems("ReferencePathWithRefAssemblies").Select(i => i.GetMetadataValue("FullPath")).ToList();

            if (copyReferenceInputs.Count == 0)
            {
                context.Logger.LogVerbose("    No input markers exist, skipping marker check. Up to date.");
                return(true);
            }

            context.Logger.LogVerbose("    Adding input reference copy markers:");
            foreach (string referenceMarkerFile in copyReferenceInputs.OrderBy(i => i))
            {
                context.Logger.LogVerbose($"        '{referenceMarkerFile}'");
            }

            (DateTime latestInputMarkerTime, string latestInputMarkerPath) = GetLatestInput(copyReferenceInputs, context.TimeStampCache);
            context.Logger.LogVerbose($"    Latest write timestamp on input marker is {latestInputMarkerTime} on '{latestInputMarkerPath}'.");

            // Get the marker file.
            string markerFile = markerFileItem.GetMetadataValue("FullPath");

            context.Logger.LogVerbose("    Adding output reference copy marker:");
            context.Logger.LogVerbose($"        '{markerFile}'");

            DateTime?outputMarkerTime = Utilities.GetTimestampUtc(markerFile, context.TimeStampCache);

            if (outputMarkerTime != null)
            {
                context.Logger.LogVerbose($"    Write timestamp on output marker is {outputMarkerTime} on '{markerFile}'.");
            }
            else
            {
                context.Logger.LogVerbose($"    Output marker '{markerFile}' does not exist, skipping marker check. Up to date.");
                return(true);
            }

            if (outputMarkerTime < latestInputMarkerTime)
            {
                failureMessage = $"Input marker ('{latestInputMarkerPath}': {latestInputMarkerTime:O}) is newer than output marker ('{markerFile}': {outputMarkerTime:O}), not up to date.";
                context.Logger.LogVerbose($"    {failureMessage}");
                return(false);
            }

            context.Logger.LogVerbose("    Up to date.");
            return(true);
        }
        public bool Check(ProjectBuildCheckContext context, out string failureMessage)
        {
            context.Logger.LogVerbose(string.Empty);
            context.Logger.LogVerbose("CheckAreCopyToOutputDirectoryFilesValid:");

            IEnumerable <ProjectItemInstance> items = context.Instance.Items.Where(i => i.HasMetadata("CopyToOutputDirectory") && i.GetMetadataValue("CopyToOutputDirectory").Equals("PreserveNewest", StringComparison.OrdinalIgnoreCase));

            IEnumerable <ProjectItemInstance> itemsUpToDateCheckInput = items.Where(i => _itemTypesForUpToDateCheckInput.Contains(i.ItemType));

            foreach (ProjectItemInstance item in itemsUpToDateCheckInput)
            {
                var rootedPath = item.GetMetadataValue("FullPath");
                var link       = item.GetMetadataValue("Link");

                string filename = rootedPath;

                if (string.IsNullOrEmpty(filename))
                {
                    continue;
                }

                context.Logger.LogVerbose($"    Checking PreserveNewest file '{rootedPath}':");

                DateTime?itemTime = Utilities.GetTimestampUtc(filename, context.TimeStampCache);

                if (itemTime != null)
                {
                    context.Logger.LogVerbose($"        Source {itemTime}: '{filename}'.");
                }
                else
                {
                    failureMessage = $"Source '{filename}' does not exist, not up to date.";
                    context.Logger.LogVerbose($"        {failureMessage}");
                    return(false);
                }

                string   outputFullPath = GetOutputFolder(context.Instance);
                string   outputFileItem = string.IsNullOrEmpty(link) ? Path.Combine(outputFullPath, filename.Replace(context.Instance.Directory, string.Empty).Trim('\\')) : Path.Combine(outputFullPath, link);
                DateTime?outputItemTime = Utilities.GetTimestampUtc(outputFileItem, context.TimeStampCache);

                if (outputItemTime != null)
                {
                    context.Logger.LogVerbose($"        Destination {outputItemTime}: '{filename}'.");
                }
                else
                {
                    failureMessage = $"Destination '{outputFileItem}' does not exist, not up to date.";
                    context.Logger.LogVerbose($"        {failureMessage}");
                    return(false);
                }

                if (outputItemTime < itemTime)
                {
                    failureMessage = "PreserveNewest source is newer than destination, not up to date.";
                    context.Logger.LogVerbose($"        {failureMessage}");
                    return(false);
                }
            }

            context.Logger.LogVerbose("    Up to date.");

            failureMessage = string.Empty;
            return(true);
        }