protected override void ExecuteCore() { if (!WriteAdditionalProbingPathsToMainConfig) { // If we want to generate the runtimeconfig.dev.json file // and we have additional probing paths to add to it // BUT the runtimeconfigdevpath is empty, log a warning. if (GenerateRuntimeConfigDevFile && AdditionalProbingPaths?.Any() == true && string.IsNullOrEmpty(RuntimeConfigDevPath)) { Log.LogWarning(Strings.SkippingAdditionalProbingPaths); } } if (!string.IsNullOrEmpty(RollForward)) { if (!RollForwardValues.Any(v => string.Equals(RollForward, v, StringComparison.OrdinalIgnoreCase))) { Log.LogError(Strings.InvalidRollForwardValue, RollForward, string.Join(", ", RollForwardValues)); return; } } if (AssetsFilePath == null) { var isFrameworkDependent = LockFileExtensions.IsFrameworkDependent( RuntimeFrameworks, IsSelfContained, RuntimeIdentifier, string.IsNullOrWhiteSpace(PlatformLibraryName)); if (isFrameworkDependent != true) { throw new ArgumentException( $"{nameof(DependencyContextBuilder)} Does not support non FrameworkDependent without asset file. " + $"runtimeFrameworks: {string.Join(",", RuntimeFrameworks.Select(r => r.ItemSpec))} " + $"isSelfContained: {IsSelfContained} " + $"runtimeIdentifier: {RuntimeIdentifier} " + $"platformLibraryName: {PlatformLibraryName}"); } if (PlatformLibraryName != null) { throw new ArgumentException( "Does not support non null PlatformLibraryName(TFM < 3) without asset file."); } WriteRuntimeConfig( RuntimeFrameworks.Select(r => new ProjectContext.RuntimeFramework(r)).ToArray(), null, isFrameworkDependent: true, new List <LockFileItem>()); } else { LockFile lockFile = new LockFileCache(this).GetLockFile(AssetsFilePath); ProjectContext projectContext = lockFile.CreateProjectContext( TargetFramework, RuntimeIdentifier, PlatformLibraryName, RuntimeFrameworks, IsSelfContained); WriteRuntimeConfig(projectContext.RuntimeFrameworks, projectContext.PlatformLibrary, projectContext.IsFrameworkDependent, projectContext.LockFile.PackageFolders); if (GenerateRuntimeConfigDevFile && !string.IsNullOrEmpty(RuntimeConfigDevPath)) { WriteDevRuntimeConfig(projectContext.LockFile.PackageFolders); } } }
public IEnumerable <ResolvedFile> Resolve(ProjectContext projectContext, bool resolveRuntimeTargets = true) { List <ResolvedFile> results = new List <ResolvedFile>(); foreach (LockFileTargetLibrary targetLibrary in projectContext.GetRuntimeLibraries(_excludedPackageIds)) { if (!targetLibrary.IsPackage()) { continue; } var targetLibraryPackage = new PackageIdentity(targetLibrary.Name, targetLibrary.Version); string pkgRoot; string libraryPath = _packageResolver.GetPackageDirectory(targetLibrary.Name, targetLibrary.Version, out pkgRoot); results.AddRange(GetResolvedFiles(targetLibrary.RuntimeAssemblies, targetLibraryPackage, libraryPath, pkgRoot, AssetType.Runtime)); results.AddRange(GetResolvedFiles(targetLibrary.NativeLibraries, targetLibraryPackage, libraryPath, pkgRoot, AssetType.Native)); if (resolveRuntimeTargets) { foreach (LockFileRuntimeTarget runtimeTarget in targetLibrary.RuntimeTargets.FilterPlaceholderFiles()) { if (string.Equals(runtimeTarget.AssetType, "native", StringComparison.OrdinalIgnoreCase) || string.Equals(runtimeTarget.AssetType, "runtime", StringComparison.OrdinalIgnoreCase)) { string sourcePath = Path.Combine(libraryPath, runtimeTarget.Path); AssetType _assetType = AssetType.None; Enum.TryParse <AssetType>(runtimeTarget.AssetType, true, out _assetType); results.Add( new ResolvedFile( sourcePath: sourcePath, destinationSubDirectory: GetDestinationSubDirectory(sourcePath, pkgRoot, GetRuntimeTargetDestinationSubDirectory(runtimeTarget)), package: targetLibraryPackage, assetType: _assetType)); } } } foreach (LockFileItem resourceAssembly in targetLibrary.ResourceAssemblies.FilterPlaceholderFiles()) { string locale; string sourcePath = Path.Combine(libraryPath, resourceAssembly.Path); if (!resourceAssembly.Properties.TryGetValue("locale", out locale)) { locale = null; } results.Add( new ResolvedFile( sourcePath: sourcePath, destinationSubDirectory: GetDestinationSubDirectory(sourcePath, pkgRoot, locale), package: targetLibraryPackage, assetType: AssetType.Resources)); } } return(results); }
public DependencyContextBuilder(SingleProjectInfo mainProjectInfo, bool includeRuntimeFileVersions, RuntimeGraph runtimeGraph, ProjectContext projectContext) { _mainProjectInfo = mainProjectInfo; _includeRuntimeFileVersions = includeRuntimeFileVersions; _runtimeGraph = runtimeGraph; var libraryLookup = new LockFileLookup(projectContext.LockFile); _dependencyLibraries = projectContext.LockFileTarget.Libraries .Select(lockFileTargetLibrary => { var dependencyLibrary = new DependencyLibrary(lockFileTargetLibrary.Name, lockFileTargetLibrary.Version, lockFileTargetLibrary.Type); LockFileLibrary library; if (libraryLookup.TryGetLibrary(lockFileTargetLibrary, out library)) { dependencyLibrary.Sha512 = library.Sha512; dependencyLibrary.Path = library.Path; dependencyLibrary.MSBuildProject = library.MSBuildProject; } return(dependencyLibrary); }).ToDictionary(d => d.Name, StringComparer.OrdinalIgnoreCase); _libraryDependencies = new Dictionary <string, List <LibraryDependency> >(StringComparer.OrdinalIgnoreCase); foreach (var library in projectContext.LockFileTarget.Libraries) { _libraryDependencies[library.Name] = library.Dependencies .Select(d => new LibraryDependency() { Name = d.Id, MinVersion = d.VersionRange.MinVersion }).ToList(); } _mainProjectDependencies = projectContext.GetTopLevelDependencies().ToList(); _packagesToBeFiltered = projectContext.PackagesToBeFiltered; _isFrameworkDependent = projectContext.IsFrameworkDependent; _platformLibrary = projectContext.PlatformLibrary?.Name; _dotnetFrameworkName = projectContext.LockFileTarget.TargetFramework.DotNetFrameworkName; _runtimeIdentifier = projectContext.LockFileTarget.RuntimeIdentifier; _isPortable = projectContext.IsPortable; _usedLibraryNames = new HashSet <string>(_dependencyLibraries.Keys, StringComparer.OrdinalIgnoreCase); }
private void AddFrameworks(RuntimeOptions runtimeOptions, ProjectContext projectContext) { if (projectContext.IsFrameworkDependent) { runtimeOptions.Tfm = TargetFramework; runtimeOptions.RollForward = RollForward; if (projectContext.RuntimeFrameworks == null || projectContext.RuntimeFrameworks.Length == 0) { // If there are no RuntimeFrameworks (which would be set in the ProcessFrameworkReferences task based // on FrameworkReference items), then use package resolved from MicrosoftNETPlatformLibrary for // the runtimeconfig RuntimeConfigFramework framework = new RuntimeConfigFramework(); framework.Name = projectContext.PlatformLibrary.Name; framework.Version = projectContext.PlatformLibrary.Version.ToNormalizedString(); runtimeOptions.Framework = framework; } else { HashSet <string> usedFrameworkNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var platformLibrary in projectContext.RuntimeFrameworks) { if (projectContext.RuntimeFrameworks.Length > 1 && platformLibrary.Name.Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase)) { // If there are multiple runtime frameworks, then exclude Microsoft.NETCore.App, // as a workaround for https://github.com/dotnet/core-setup/issues/4947 continue; } // Don't add multiple entries for the same shared framework. // This is necessary if there are FrameworkReferences to different profiles // that map to the same shared framework. if (!usedFrameworkNames.Add(platformLibrary.Name)) { continue; } RuntimeConfigFramework framework = new RuntimeConfigFramework(); framework.Name = platformLibrary.Name; framework.Version = platformLibrary.Version; // If there is only one runtime framework, then it goes in the framework property of the json // If there are multiples, then we leave the framework property unset and put the list in // the frameworks property. if (runtimeOptions.Framework == null && runtimeOptions.Frameworks == null) { runtimeOptions.Framework = framework; } else { if (runtimeOptions.Frameworks == null) { runtimeOptions.Frameworks = new List <RuntimeConfigFramework>(); runtimeOptions.Frameworks.Add(runtimeOptions.Framework); runtimeOptions.Framework = null; } runtimeOptions.Frameworks.Add(framework); } } } } }