private static TargetFrameworkInformation ToTargetFrameworkInformation( IVsTargetFrameworkInfo targetFrameworkInfo) { var tfi = new TargetFrameworkInformation { FrameworkName = NuGetFramework.Parse(targetFrameworkInfo.TargetFrameworkMoniker) }; var ptf = MSBuildStringUtility.Split(GetPropertyValueOrNull(targetFrameworkInfo.Properties, PackageTargetFallback)) .Select(NuGetFramework.Parse) .ToList(); var atf = MSBuildStringUtility.Split(GetPropertyValueOrNull(targetFrameworkInfo.Properties, AssetTargetFallback)) .Select(NuGetFramework.Parse) .ToList(); // Update TFI with fallback properties PackageSpecUtility.ApplyFallbackFramework(tfi, ptf, atf); if (targetFrameworkInfo.PackageReferences != null) { tfi.Dependencies.AddRange( targetFrameworkInfo.PackageReferences .Cast <IVsReferenceItem>() .Select(ToPackageLibraryDependency)); } return(tfi); }
private static void AddPackageTargetFallbacks(PackageSpec spec, IEnumerable <IMSBuildItem> items) { foreach (var item in GetItemByType(items, "TargetFrameworkInformation")) { var frameworkString = item.GetProperty("TargetFramework"); var frameworks = new List <TargetFrameworkInformation>(); if (!string.IsNullOrEmpty(frameworkString)) { frameworks.Add(spec.GetTargetFramework(NuGetFramework.Parse(frameworkString))); } else { frameworks.AddRange(spec.TargetFrameworks); } foreach (var targetFrameworkInfo in frameworks) { var packageTargetFallback = MSBuildStringUtility.Split(item.GetProperty("PackageTargetFallback")) .Select(NuGetFramework.Parse) .ToList(); var assetTargetFallback = MSBuildStringUtility.Split(item.GetProperty(AssetTargetFallbackUtility.AssetTargetFallback)) .Select(NuGetFramework.Parse) .ToList(); // Update the framework appropriately PackageSpecUtility.ApplyFallbackFramework(targetFrameworkInfo, packageTargetFallback, assetTargetFallback); } } }
public void PackageSpecUtility_ApplyFallbackFrameworkWithNoFallbacksVerifyResult() { var frameworkInfo = new TargetFrameworkInformation() { FrameworkName = NuGetFramework.Parse("netcoreapp2.0") }; var atf = new List <NuGetFramework>(); var ptf = new List <NuGetFramework>(); PackageSpecUtility.ApplyFallbackFramework(frameworkInfo, ptf, atf); frameworkInfo.AssetTargetFallback.Should().BeEmpty(); frameworkInfo.Imports.Should().BeEmpty(); frameworkInfo.FrameworkName.Should().NotBeOfType(typeof(FallbackFramework)); frameworkInfo.FrameworkName.Should().NotBeOfType(typeof(AssetTargetFallbackFramework)); }
/// <summary> /// Emulates a JSON deserialization from project.json to PackageSpec in a post-project.json world /// </summary> private async Task <PackageSpec> GetPackageSpecAsync(ISettings settings) { await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync(); var projectReferences = await ProjectServices .ReferencesReader .GetProjectReferencesAsync(Common.NullLogger.Instance, CancellationToken.None); var targetFramework = await _vsProjectAdapter.GetTargetFrameworkAsync(); var packageReferences = (await ProjectServices .ReferencesReader .GetPackageReferencesAsync(targetFramework, CancellationToken.None)) .ToList(); var packageTargetFallback = MSBuildStringUtility.Split(_vsProjectAdapter.PackageTargetFallback) .Select(NuGetFramework.Parse) .ToList(); var assetTargetFallback = MSBuildStringUtility.Split(_vsProjectAdapter.AssetTargetFallback) .Select(NuGetFramework.Parse) .ToList(); var projectTfi = new TargetFrameworkInformation { FrameworkName = targetFramework, Dependencies = packageReferences, }; // Apply fallback settings PackageSpecUtility.ApplyFallbackFramework(projectTfi, packageTargetFallback, assetTargetFallback); // Build up runtime information. var runtimes = await _vsProjectAdapter.GetRuntimeIdentifiersAsync(); var supports = await _vsProjectAdapter.GetRuntimeSupportsAsync(); var runtimeGraph = new RuntimeGraph(runtimes, supports); // In legacy CSProj, we only have one target framework per project var tfis = new TargetFrameworkInformation[] { projectTfi }; return(new PackageSpec(tfis) { Name = _projectName ?? _projectUniqueName, Version = new NuGetVersion(_vsProjectAdapter.Version), Authors = new string[] { }, Owners = new string[] { }, Tags = new string[] { }, ContentFiles = new string[] { }, Dependencies = packageReferences, FilePath = _projectFullPath, RuntimeGraph = runtimeGraph, RestoreMetadata = new ProjectRestoreMetadata { ProjectStyle = ProjectStyle.PackageReference, OutputPath = GetBaseIntermediatePath(), ProjectPath = _projectFullPath, ProjectName = _projectName ?? _projectUniqueName, ProjectUniqueName = _projectFullPath, OriginalTargetFrameworks = tfis .Select(tfi => tfi.FrameworkName.GetShortFolderName()) .ToList(), TargetFrameworks = new List <ProjectRestoreMetadataFrameworkInfo> { new ProjectRestoreMetadataFrameworkInfo(tfis[0].FrameworkName) { ProjectReferences = projectReferences?.ToList() } }, SkipContentFileWrite = true, PackagesPath = GetPackagesPath(settings), Sources = GetSources(settings), FallbackFolders = GetFallbackFolders(settings), ConfigFilePaths = GetConfigFilePaths(settings), ProjectWideWarningProperties = MSBuildRestoreUtility.GetWarningProperties( treatWarningsAsErrors: _vsProjectAdapter.TreatWarningsAsErrors, noWarn: _vsProjectAdapter.NoWarn, warningsAsErrors: _vsProjectAdapter.WarningsAsErrors) } }); }