CCNet.Build.SetupPackages.LogPackagesExtensions.SaveReferences C# (CSharp) Method

SaveReferences() public static method

Updates local references folder to represent the actual dependencies for all referenced packages.
public static SaveReferences ( this packages, string referencesPath ) : void
packages this
referencesPath string
return void
		public static void SaveReferences(this LogPackages packages, string referencesPath)
		{
			referencesPath.CreateDirectoryIfNotExists();

			var after = packages.Values
				.Where(i => i.IsLocal)
				.ToDictionary(i => i.ProjectName);

			var before = Directory
				.GetFiles(referencesPath)
				.ToDictionary(Path.GetFileNameWithoutExtension);

			var toAdd = new List<string>();
			foreach (var reference in after)
			{
				if (before.ContainsKey(reference.Key))
					continue;

				var name = String.Format("{0}.txt", reference.Key);
				var path = Path.Combine(referencesPath, name);
				toAdd.Add(path);
			}

			var toRemove = new List<string>();
			foreach (var reference in before)
			{
				if (after.ContainsKey(reference.Key))
					continue;

				toRemove.Add(reference.Value);
			}

			foreach (var file in toRemove)
			{
				File.Delete(file);
			}

			foreach (var file in toAdd)
			{
				File.WriteAllText(file, String.Format("Created on {0}", DateTime.Now.ToDetailedString()));
			}
		}
LogPackagesExtensions