public override bool Execute() { // Log inputs var log = new MSBuildLogger(Log); log.LogDebug($"(in) ProjectUniqueName '{ProjectUniqueName}'"); log.LogDebug($"(in) TargetFrameworks '{TargetFrameworks}'"); log.LogDebug($"(in) ProjectReferences '{string.Join(";", ProjectReferences.Select(p => p.ItemSpec))}'"); log.LogDebug($"(in) ParentProjectPath '{ParentProjectPath}'"); var entries = new List <ITaskItem>(); // Filter obvious duplicates without considering OS case sensitivity. // This will be filtered further when creating the spec. var seen = new HashSet <string>(StringComparer.Ordinal); var parentDirectory = Path.GetDirectoryName(ParentProjectPath); foreach (var project in ProjectReferences) { var refOutput = BuildTasksUtility.GetPropertyIfExists(project, "ReferenceOutputAssembly"); // Match the same behavior as NuGet.targets // ReferenceOutputAssembly == '' OR ReferenceOutputAssembly == 'true' if (string.IsNullOrEmpty(refOutput) || Boolean.TrueString.Equals(refOutput, StringComparison.OrdinalIgnoreCase)) { // Get the absolute path var referencePath = Path.GetFullPath(Path.Combine(parentDirectory, project.ItemSpec)); if (!seen.Add(referencePath)) { // Skip already processed projects continue; } var properties = new Dictionary <string, string>(); properties.Add("ProjectUniqueName", ProjectUniqueName); properties.Add("Type", "ProjectReference"); properties.Add("ProjectPath", referencePath); properties.Add("ProjectReferenceUniqueName", referencePath); if (!string.IsNullOrEmpty(TargetFrameworks)) { properties.Add("TargetFrameworks", TargetFrameworks); } BuildTasksUtility.CopyPropertyIfExists(project, properties, "IncludeAssets"); BuildTasksUtility.CopyPropertyIfExists(project, properties, "ExcludeAssets"); BuildTasksUtility.CopyPropertyIfExists(project, properties, "PrivateAssets"); entries.Add(new TaskItem(Guid.NewGuid().ToString(), properties)); } } RestoreGraphItems = entries.ToArray(); return(true); }
public override bool Execute() { var log = new MSBuildLogger(Log); log.LogDebug($"(in) ProjectPath '{ProjectPath}'"); log.LogDebug($"(in) DotnetCliToolReferences '{string.Join(";", DotnetCliToolReferences.Select(p => p.ItemSpec))}'"); var entries = new List <ITaskItem>(); foreach (var msbuildItem in DotnetCliToolReferences) { if (string.IsNullOrEmpty(msbuildItem.ItemSpec)) { throw new InvalidDataException($"Invalid DotnetCliToolReference in {ProjectPath}"); } var uniqueName = $"{msbuildItem.ItemSpec}-{Guid.NewGuid().ToString()}"; // Create top level project var properties = new Dictionary <string, string>(); properties.Add("ProjectUniqueName", uniqueName); properties.Add("Type", "ProjectSpec"); properties.Add("ProjectPath", ProjectPath); properties.Add("ProjectName", $"DotnetCliToolReference-{msbuildItem.ItemSpec}"); BuildTasksUtility.AddPropertyIfExists(properties, "Sources", RestoreSources); BuildTasksUtility.AddPropertyIfExists(properties, "FallbackFolders", RestoreFallbackFolders); BuildTasksUtility.AddPropertyIfExists(properties, "PackagesPath", RestorePackagesPath); properties.Add("TargetFrameworks", ToolFramework); properties.Add("ProjectStyle", ProjectStyle.DotnetCliTool.ToString()); BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "Version"); entries.Add(new TaskItem(Guid.NewGuid().ToString(), properties)); // Add reference to package var packageProperties = new Dictionary <string, string>(); packageProperties.Add("ProjectUniqueName", uniqueName); packageProperties.Add("Type", "Dependency"); packageProperties.Add("Id", msbuildItem.ItemSpec); BuildTasksUtility.CopyPropertyIfExists(msbuildItem, packageProperties, "Version", "VersionRange"); packageProperties.Add("TargetFrameworks", ToolFramework); entries.Add(new TaskItem(Guid.NewGuid().ToString(), packageProperties)); // Add restore spec to ensure this is executed during restore var restoreProperties = new Dictionary <string, string>(); restoreProperties.Add("ProjectUniqueName", uniqueName); restoreProperties.Add("Type", "RestoreSpec"); entries.Add(new TaskItem(Guid.NewGuid().ToString(), restoreProperties)); } RestoreGraphItems = entries.ToArray(); return(true); }
public override bool Execute() { var log = new MSBuildLogger(Log); log.LogDebug($"(in) ProjectUniqueName '{ProjectUniqueName}'"); log.LogDebug($"(in) TargetFrameworks '{TargetFrameworks}'"); log.LogDebug($"(in) PackageReferences '{string.Join(";", PackageReferences.Select(p => p.ItemSpec))}'"); var entries = new List <ITaskItem>(); var seenIds = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var msbuildItem in PackageReferences) { var packageId = msbuildItem.ItemSpec; if (string.IsNullOrEmpty(packageId) || !seenIds.Add(packageId)) { // Skip empty or already processed ids continue; } var properties = new Dictionary <string, string>(); properties.Add("ProjectUniqueName", ProjectUniqueName); properties.Add("Type", "Dependency"); properties.Add("Id", packageId); BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "Version", "VersionRange"); BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "VersionOverride"); if (!string.IsNullOrEmpty(TargetFrameworks)) { properties.Add("TargetFrameworks", TargetFrameworks); } BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "IncludeAssets"); BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "ExcludeAssets"); BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "PrivateAssets"); BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "NoWarn"); BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "IsImplicitlyDefined"); BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "GeneratePathProperty"); BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "Aliases"); entries.Add(new TaskItem(Guid.NewGuid().ToString(), properties)); } RestoreGraphItems = entries.ToArray(); return(true); }
public override bool Execute() { var log = new MSBuildLogger(Log); log.LogDebug($"(in) ProjectUniqueName '{ProjectUniqueName}'"); log.LogDebug($"(in) TargetFrameworks '{TargetFrameworks}'"); log.LogDebug($"(in) PackageDownloads '{string.Join(";", PackageDownloads.Select(p => p.ItemSpec))}'"); var entries = new List <ITaskItem>(); var seenIds = new HashSet <Tuple <string, string> >(new CustomEqualityComparer()); foreach (var msbuildItem in PackageDownloads) { var packageId = msbuildItem.ItemSpec; var properties = new Dictionary <string, string>(); properties.Add("ProjectUniqueName", ProjectUniqueName); properties.Add("Type", "DownloadDependency"); properties.Add("Id", packageId); BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "Version", "VersionRange"); properties.TryGetValue("VersionRange", out var versionRange); var key = new Tuple <string, string>(packageId, versionRange); if (string.IsNullOrEmpty(packageId) || !seenIds.Add(key)) { // Skip duplicate id/version combinations continue; } if (!string.IsNullOrEmpty(TargetFrameworks)) { properties.Add("TargetFrameworks", TargetFrameworks); } entries.Add(new TaskItem(Guid.NewGuid().ToString(), properties)); } RestoreGraphItems = entries.ToArray(); return(true); }
public override bool Execute() { var log = new MSBuildLogger(Log); log.LogDebug($"(in) ProjectUniqueName '{ProjectUniqueName}'"); log.LogDebug($"(in) TargetFrameworks '{TargetFrameworks}'"); log.LogDebug($"(in) FrameworkReferences '{string.Join(";", FrameworkReferences.Select(p => p.ItemSpec))}'"); var entries = new List <ITaskItem>(); var seenIds = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var msbuildItem in FrameworkReferences) { var frameworkReference = msbuildItem.ItemSpec; if (string.IsNullOrEmpty(frameworkReference) || !seenIds.Add(frameworkReference)) { // Skip empty or already processed ids continue; } var properties = new Dictionary <string, string>(); properties.Add("ProjectUniqueName", ProjectUniqueName); properties.Add("Type", "FrameworkReference"); properties.Add("Id", frameworkReference); if (!string.IsNullOrEmpty(TargetFrameworks)) { properties.Add("TargetFrameworks", TargetFrameworks); } BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "PrivateAssets"); entries.Add(new TaskItem(Guid.NewGuid().ToString(), properties)); } RestoreGraphItems = entries.ToArray(); return(true); }