Example #1
0
        private async Task CommitAssetsFileAsync(
            LockFileFormat lockFileFormat,
            IRestoreResult result,
            ILogger log,
            bool toolCommit,
            CancellationToken token)
        {
            // Commit targets/props to disk before the assets file.
            // Visual Studio typically watches the assets file for changes
            // and begins a reload when that file changes.
            var buildFilesToWrite = result.MSBuildOutputFiles
                                    .Where(e => BuildAssetsUtils.HasChanges(e.Content, e.Path, log));

            BuildAssetsUtils.WriteFiles(buildFilesToWrite, log);

            // Avoid writing out the lock file if it is the same to avoid triggering an intellisense
            // update on a restore with no actual changes.
            if (result.PreviousLockFile == null ||
                !result.PreviousLockFile.Equals(result.LockFile))
            {
                if (toolCommit)
                {
                    if (result.LockFilePath != null && result.LockFile != null)
                    {
                        log.LogInformation(string.Format(CultureInfo.CurrentCulture,
                                                         Strings.Log_ToolWritingLockFile,
                                                         result.LockFilePath));

                        await FileUtility.ReplaceWithLock(
                            (outputPath) => lockFileFormat.Write(outputPath, result.LockFile),
                            result.LockFilePath);
                    }
                }
                else
                {
                    log.LogInformation(string.Format(CultureInfo.CurrentCulture,
                                                     Strings.Log_WritingLockFile,
                                                     result.LockFilePath));

                    FileUtility.Replace(
                        (outputPath) => lockFileFormat.Write(outputPath, result.LockFile),
                        result.LockFilePath);
                }
            }
            else
            {
                if (toolCommit)
                {
                    log.LogInformation(string.Format(CultureInfo.CurrentCulture,
                                                     Strings.Log_ToolSkippingAssetsFile,
                                                     result.LockFilePath));
                }
                else
                {
                    log.LogInformation(string.Format(CultureInfo.CurrentCulture,
                                                     Strings.Log_SkippingAssetsFile,
                                                     result.LockFilePath));
                }
            }
        }
Example #2
0
        private static async Task CommitAsync(
            LockFileFormat lockFileFormat,
            IRestoreResult result,
            ILogger log,
            bool forceWrite,
            bool toolCommit,
            CancellationToken token)
        {
            // Commit targets/props to disk before the assets file.
            // Visual Studio typically watches the assets file for changes
            // and begins a reload when that file changes.
            var buildFilesToWrite = result.MSBuildOutputFiles
                                    .Where(e => forceWrite || BuildAssetsUtils.HasChanges(e.Content, e.Path, log));

            BuildAssetsUtils.WriteFiles(buildFilesToWrite, log);

            // Avoid writing out the lock file if it is the same to avoid triggering an intellisense
            // update on a restore with no actual changes.
            if (forceWrite ||
                result.PreviousLockFile == null ||
                !result.PreviousLockFile.Equals(result.LockFile))
            {
                if (toolCommit)
                {
                    if (result.LockFilePath != null && result.LockFile != null)
                    {
                        log.LogDebug($"Writing tool lock file to disk. Path: {result.LockFilePath}");

                        await FileUtility.ReplaceWithLock(
                            (outputPath) => lockFileFormat.Write(outputPath, result.LockFile),
                            result.LockFilePath);
                    }
                }
                else
                {
                    log.LogMinimal($"Writing lock file to disk. Path: {result.LockFilePath}");

                    FileUtility.Replace(
                        (outputPath) => lockFileFormat.Write(outputPath, result.LockFile),
                        result.LockFilePath);
                }
            }
            else
            {
                if (toolCommit)
                {
                    log.LogDebug($"Tool lock file has not changed. Skipping lock file write. Path: {result.LockFilePath}");
                }
                else
                {
                    log.LogMinimal($"Lock file has not changed. Skipping lock file write. Path: {result.LockFilePath}");
                }
            }
        }