protected override void ExecuteCore() { // Get the list of runtime identifiers that we support and can target ITaskItem frameworkRef = KnownFrameworkReferences.Where(item => String.Compare(item.ItemSpec, "Microsoft.NETCore.App", true) == 0).SingleOrDefault(); string supportedRuntimeIdentifiers = frameworkRef == null ? null : frameworkRef.GetMetadata("RuntimePackRuntimeIdentifiers"); // Get information on the runtime package used for the current target ITaskItem frameworkPack = RuntimePacks.Where(pack => pack.GetMetadata(MetadataKeys.FrameworkName).Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase)) .SingleOrDefault(); _runtimeIdentifier = frameworkPack == null ? null : frameworkPack.GetMetadata(MetadataKeys.RuntimeIdentifier); _packagePath = frameworkPack == null ? null : frameworkPack.GetMetadata(MetadataKeys.PackageDirectory); var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath); var supportedRIDsList = supportedRuntimeIdentifiers == null?Array.Empty <string>() : supportedRuntimeIdentifiers.Split(';'); // Get the best RID for the host machine, which will be used to validate that we can run crossgen for the target platform and architecture string hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid( runtimeGraph, NETCoreSdkRuntimeIdentifier, supportedRIDsList, out bool wasInGraph); if (hostRuntimeIdentifier == null || _runtimeIdentifier == null || _packagePath == null) { Log.LogError(Strings.ReadyToRunNoValidRuntimePackageError); return; } if (!ExtractTargetPlatformAndArchitecture(_runtimeIdentifier, out string targetPlatform, out _targetArchitecture) || !ExtractTargetPlatformAndArchitecture(hostRuntimeIdentifier, out string hostPlatform, out Architecture hostArchitecture) || targetPlatform != hostPlatform) { Log.LogError(Strings.ReadyToRunTargetNotSupportedError); return; } if (!GetCrossgenComponentsPaths() || !File.Exists(_crossgenPath) || !File.Exists(_clrjitPath)) { Log.LogError(Strings.ReadyToRunTargetNotSupportedError); return; } // Create tool task item CrossgenTool = new TaskItem(_crossgenPath); CrossgenTool.SetMetadata("JitPath", _clrjitPath); if (!String.IsNullOrEmpty(_diasymreaderPath)) { CrossgenTool.SetMetadata("DiaSymReader", _diasymreaderPath); } // Process input lists of files ProcessInputFileList(FilesToPublish, _compileList, _symbolsCompileList, _r2rFiles); }
protected override void ExecuteCore() { LoadFilesToSkip(); LockFile lockFile = new LockFileCache(BuildEngine4).GetLockFile(AssetsFilePath); CompilationOptions compilationOptions = CompilationOptionsConverter.ConvertFrom(CompilerOptions); SingleProjectInfo mainProject = SingleProjectInfo.Create( ProjectPath, AssemblyName, AssemblyExtension, AssemblyVersion, AssemblySatelliteAssemblies); IEnumerable <ReferenceInfo> frameworkReferences = ReferenceInfo.CreateFrameworkReferenceInfos(ReferencePaths); IEnumerable <ReferenceInfo> directReferences = ReferenceInfo.CreateDirectReferenceInfos(ReferencePaths, ReferenceSatellitePaths); Dictionary <string, SingleProjectInfo> referenceProjects = SingleProjectInfo.CreateProjectReferenceInfos( ReferencePaths, ReferenceSatellitePaths); IEnumerable <string> privateAssets = PackageReferenceConverter.GetPackageIds(PrivateAssetsPackageReferences); ProjectContext projectContext = lockFile.CreateProjectContext( NuGetUtils.ParseFrameworkName(TargetFramework), RuntimeIdentifier, PlatformLibraryName, IsSelfContained); DependencyContext dependencyContext = new DependencyContextBuilder(mainProject, projectContext) .WithFrameworkReferences(frameworkReferences) .WithDirectReferences(directReferences) .WithReferenceProjectInfos(referenceProjects) .WithPrivateAssets(privateAssets) .WithCompilationOptions(compilationOptions) .WithReferenceAssembliesPath(FrameworkReferenceResolver.GetDefaultReferenceAssembliesPath()) .WithPackagesThatWhereFiltered(GetFilteredPackages()) .Build(); if (compileFilesToSkip.Any() || runtimeFilesToSkip.Any()) { dependencyContext = TrimFilesToSkip(dependencyContext); } var writer = new DependencyContextWriter(); using (var fileStream = File.Create(DepsFilePath)) { writer.Write(dependencyContext, fileStream); } _filesWritten.Add(new TaskItem(DepsFilePath)); }
protected override void ExecuteCore() { _runtimePack = GetNETCoreAppRuntimePack(); _crossgen2Pack = Crossgen2Packs?.FirstOrDefault(); _targetRuntimeIdentifier = _runtimePack?.GetMetadata(MetadataKeys.RuntimeIdentifier); // Get the list of runtime identifiers that we support and can target ITaskItem targetingPack = GetNETCoreAppTargetingPack(); string supportedRuntimeIdentifiers = targetingPack?.GetMetadata(MetadataKeys.RuntimePackRuntimeIdentifiers); var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath); var supportedRIDsList = supportedRuntimeIdentifiers == null?Array.Empty <string>() : supportedRuntimeIdentifiers.Split(';'); // Get the best RID for the host machine, which will be used to validate that we can run crossgen for the target platform and architecture _hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid( runtimeGraph, NETCoreSdkRuntimeIdentifier, supportedRIDsList, out bool wasInGraph); if (_hostRuntimeIdentifier == null || _targetRuntimeIdentifier == null) { Log.LogError(Strings.ReadyToRunNoValidRuntimePackageError); return; } if (ReadyToRunUseCrossgen2) { if (!ValidateCrossgen2Support()) { return; } // NOTE: Crossgen2 does not yet currently support emitting native symbols, and until this feature // is implemented, we will use crossgen for it. This should go away in the future when crossgen2 supports the feature. if (EmitSymbols && !ValidateCrossgenSupport()) { return; } } else { if (!ValidateCrossgenSupport()) { return; } } // Future: check DiaSymReaderPath in the _crossgen2Tool info when crossgen2 starts supporting emitting native symbols bool hasValidDiaSymReaderLib = String.IsNullOrEmpty(_crossgenTool.DiaSymReaderPath) ? false : File.Exists(_crossgenTool.DiaSymReaderPath); // Process input lists of files ProcessInputFileList(Assemblies, _compileList, _symbolsCompileList, _r2rFiles, _r2rReferences, hasValidDiaSymReaderLib); }
private NuGetFramework ParseFramework(string name) { var framework = NuGetUtils.ParseFrameworkName(name); if (framework == null) { Log.LogError(Strings.InvalidFrameworkName, framework); } return(framework); }
protected override void ExecuteCore() { var lockFileCache = new LockFileCache(BuildEngine4); LockFile lockFile = lockFileCache.GetLockFile(AssetsFilePath); IEnumerable <string> excludeFromPublishPackageIds = PackageReferenceConverter.GetPackageIds(ExcludeFromPublishPackageReferences); IPackageResolver packageResolver = NuGetPackageResolver.CreateResolver(lockFile, ProjectPath); HashSet <PackageIdentity> packagestoBeFiltered = null; if (TargetManifestFiles != null && TargetManifestFiles.Length > 0) { packagestoBeFiltered = new HashSet <PackageIdentity>(); foreach (var manifestFile in TargetManifestFiles) { Log.LogMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, Strings.ParsingFiles, manifestFile)); var packagesSpecified = StoreArtifactParser.Parse(manifestFile); foreach (var pkg in packagesSpecified) { Log.LogMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, Strings.PackageInfoLog, pkg.Id, pkg.Version)); } packagestoBeFiltered.UnionWith(packagesSpecified); } } ProjectContext projectContext = lockFile.CreateProjectContext( NuGetUtils.ParseFrameworkName(TargetFramework), RuntimeIdentifier, PlatformLibraryName, IsSelfContained); projectContext.PackagesToBeFiltered = packagestoBeFiltered; var assemblyResolver = new PublishAssembliesResolver(packageResolver) .WithExcludeFromPublish(excludeFromPublishPackageIds) .WithPreserveStoreLayout(PreserveStoreLayout); IEnumerable <ResolvedFile> resolvedAssemblies = assemblyResolver.Resolve(projectContext); foreach (ResolvedFile resolvedAssembly in resolvedAssemblies) { TaskItem item = new TaskItem(resolvedAssembly.SourcePath); item.SetMetadata("DestinationSubPath", resolvedAssembly.DestinationSubPath); item.SetMetadata("AssetType", resolvedAssembly.Asset.ToString().ToLower()); _assembliesToPublish.Add(item); } foreach (var resolvedPkg in assemblyResolver.GetResolvedPackages()) { TaskItem item = new TaskItem(resolvedPkg.Id); item.SetMetadata("Version", resolvedPkg.Version.ToString()); _packagesResolved.Add(item); } }
private NuGetFramework ParseFramework(string name) { var framework = NuGetUtils.ParseFrameworkName(name); if (framework == null) { // TODO: localize: https://github.com/dotnet/sdk/issues/33 Log.LogError($"Invalid framework name: '{framework}'."); } return(framework); }
protected override void ExecuteCore() { NuGetFramework targetFramework = NuGetUtils.ParseFrameworkName(TargetFrameworkMoniker); LockFile lockFile = new LockFileCache(this).GetLockFile(ProjectAssetsFile); _packageResolver = NuGetPackageResolver.CreateResolver(lockFile, ProjectPath); var embeddedApphostPaths = new List <ITaskItem>(); foreach (var runtimeIdentifier in ShimRuntimeIdentifiers.Select(r => r.ItemSpec)) { var resolvedApphostAssetPath = GetApphostAsset(targetFramework, lockFile, runtimeIdentifier); var packagedShimOutputDirectoryAndRid = Path.Combine( PackagedShimOutputDirectory, runtimeIdentifier); var appHostDestinationFilePath = Path.Combine( packagedShimOutputDirectoryAndRid, ToolCommandName + Path.GetExtension(resolvedApphostAssetPath)); Directory.CreateDirectory(packagedShimOutputDirectoryAndRid); // This is the embedded string. We should normalize it on forward slash, so the file won't be different according to // build machine. var appBinaryFilePath = string.Join("/", new[] { ".store", PackageId.ToLowerInvariant(), PackageVersion, PackageId.ToLowerInvariant(), PackageVersion, "tools", targetFramework.GetShortFolderName(), "any", ToolEntryPoint }); AppHost.Create( resolvedApphostAssetPath, appHostDestinationFilePath, appBinaryFilePath, overwriteExisting: true ); var item = new TaskItem(appHostDestinationFilePath); item.SetMetadata("ShimRuntimeIdentifier", runtimeIdentifier); embeddedApphostPaths.Add(item); } EmbeddedApphostPaths = embeddedApphostPaths.ToArray(); }
protected override void ExecuteCore() { var lockFileCache = new LockFileCache(this); LockFile lockFile = lockFileCache.GetLockFile(AssetsFilePath); IEnumerable <string> excludeFromPublishPackageIds = PackageReferenceConverter.GetPackageIds(ExcludeFromPublishPackageReferences); IPackageResolver packageResolver = NuGetPackageResolver.CreateResolver(lockFile, ProjectPath); HashSet <PackageIdentity> packagestoBeFiltered = null; if (RuntimeStorePackages != null && RuntimeStorePackages.Length > 0) { packagestoBeFiltered = new HashSet <PackageIdentity>(); foreach (var package in RuntimeStorePackages) { packagestoBeFiltered.Add(ItemUtilities.GetPackageIdentity(package)); } } ProjectContext projectContext = lockFile.CreateProjectContext( NuGetUtils.ParseFrameworkName(TargetFramework), RuntimeIdentifier, PlatformLibraryName, RuntimeFrameworks, IsSelfContained); projectContext.PackagesToBeFiltered = packagestoBeFiltered; var assemblyResolver = new PublishAssembliesResolver(packageResolver) .WithExcludeFromPublish(excludeFromPublishPackageIds) .WithPreserveStoreLayout(PreserveStoreLayout); IEnumerable <ResolvedFile> resolvedAssemblies = assemblyResolver.Resolve(projectContext); foreach (ResolvedFile resolvedAssembly in resolvedAssemblies) { TaskItem item = new TaskItem(resolvedAssembly.SourcePath); item.SetMetadata("DestinationSubPath", resolvedAssembly.DestinationSubPath); item.SetMetadata("AssetType", resolvedAssembly.Asset.ToString().ToLower()); item.SetMetadata(MetadataKeys.PackageName, resolvedAssembly.Package.Id.ToString()); item.SetMetadata(MetadataKeys.PackageVersion, resolvedAssembly.Package.Version.ToString().ToLower()); if (resolvedAssembly.Asset == AssetType.Resources) { // For resources, the DestinationSubDirectory is set to the locale. Set the Culture // metadata on the generated item to this value so that the satellite assemblies can // be filtered by culture. item.SetMetadata(MetadataKeys.Culture, resolvedAssembly.DestinationSubDirectory); } _assembliesToPublish.Add(item); } }
protected override void ExecuteCore() { ITaskItem runtimePack = GetNETCoreAppRuntimePack(); _runtimeIdentifier = runtimePack?.GetMetadata(MetadataKeys.RuntimeIdentifier); _packagePath = runtimePack?.GetMetadata(MetadataKeys.PackageDirectory); // Get the list of runtime identifiers that we support and can target ITaskItem targetingPack = GetNETCoreAppTargetingPack(); string supportedRuntimeIdentifiers = targetingPack?.GetMetadata(MetadataKeys.RuntimePackRuntimeIdentifiers); var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath); var supportedRIDsList = supportedRuntimeIdentifiers == null?Array.Empty <string>() : supportedRuntimeIdentifiers.Split(';'); // Get the best RID for the host machine, which will be used to validate that we can run crossgen for the target platform and architecture string hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid( runtimeGraph, NETCoreSdkRuntimeIdentifier, supportedRIDsList, out bool wasInGraph); if (hostRuntimeIdentifier == null || _runtimeIdentifier == null || _packagePath == null) { Log.LogError(Strings.ReadyToRunNoValidRuntimePackageError); return; } if (!ExtractTargetPlatformAndArchitecture(_runtimeIdentifier, out string targetPlatform, out _targetArchitecture) || !ExtractTargetPlatformAndArchitecture(hostRuntimeIdentifier, out string hostPlatform, out Architecture hostArchitecture) || targetPlatform != hostPlatform) { Log.LogError(Strings.ReadyToRunTargetNotSupportedError); return; } if (!GetCrossgenComponentsPaths() || !File.Exists(_crossgenPath) || !File.Exists(_clrjitPath)) { Log.LogError(Strings.ReadyToRunTargetNotSupportedError); return; } // Create tool task item CrossgenTool = new TaskItem(_crossgenPath); CrossgenTool.SetMetadata("JitPath", _clrjitPath); if (!String.IsNullOrEmpty(_diasymreaderPath)) { CrossgenTool.SetMetadata("DiaSymReader", _diasymreaderPath); } // Process input lists of files ProcessInputFileList(Assemblies, _compileList, _symbolsCompileList, _r2rFiles, _r2rReferences); }
public static LockFileTarget GetTargetAndReturnNullIfNotFound(this LockFile lockFile, string frameworkAlias, string runtimeIdentifier) { LockFileTarget lockFileTarget = lockFile.GetTarget(frameworkAlias, runtimeIdentifier); if (lockFileTarget == null && lockFile.PackageSpec.TargetFrameworks.All(tfi => string.IsNullOrEmpty(tfi.TargetAlias))) { var nuGetFramework = NuGetUtils.ParseFrameworkName(frameworkAlias); lockFileTarget = lockFile.GetTarget(nuGetFramework, runtimeIdentifier); } return(lockFileTarget); }
private string ResolveFilePath(string relativePath, string resolvedPackagePath) { if (NuGetUtils.IsPlaceholderFile(relativePath)) { return(null); } relativePath = relativePath.Replace('/', Path.DirectorySeparatorChar); relativePath = relativePath.Replace('\\', Path.DirectorySeparatorChar); return(resolvedPackagePath != null ? Path.Combine(resolvedPackagePath, relativePath) : string.Empty); }
private string GetBestRuntimeIdentifier(string targetRuntimeIdentifier, string availableRuntimeIdentifiers, out bool wasInGraph) { if (targetRuntimeIdentifier == null || availableRuntimeIdentifiers == null) { wasInGraph = false; return(null); } return(NuGetUtils.GetBestMatchingRid( new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath), targetRuntimeIdentifier, availableRuntimeIdentifiers.Split(';'), out wasInGraph)); }
protected override void ExecuteCore() { var lockFileCache = new LockFileCache(this); LockFile lockFile = lockFileCache.GetLockFile(AssetsFilePath); HashSet <PackageIdentity> packagestoBeFiltered = null; if (RuntimeStorePackages != null && RuntimeStorePackages.Length > 0) { packagestoBeFiltered = new HashSet <PackageIdentity>(); foreach (var package in RuntimeStorePackages) { packagestoBeFiltered.Add(ItemUtilities.GetPackageIdentity(package)); } } ProjectContext projectContext = lockFile.CreateProjectContext( NuGetUtils.ParseFrameworkName(TargetFramework), RuntimeIdentifier, PlatformLibraryName, RuntimeFrameworks, IsSelfContained); projectContext.PackagesToBeFiltered = packagestoBeFiltered; var assetsFileResolver = new AssetsFileResolver(NuGetPackageResolver.CreateResolver(lockFile)) .WithExcludedPackages(PackageReferenceConverter.GetPackageIds(ExcludedPackageReferences)) .WithPreserveStoreLayout(PreserveStoreLayout); foreach (var resolvedFile in assetsFileResolver.Resolve(projectContext)) { TaskItem item = new TaskItem(resolvedFile.SourcePath); item.SetMetadata(MetadataKeys.DestinationSubPath, resolvedFile.DestinationSubPath); item.SetMetadata(MetadataKeys.DestinationSubDirectory, resolvedFile.DestinationSubDirectory); item.SetMetadata(MetadataKeys.AssetType, resolvedFile.Asset.ToString().ToLowerInvariant()); item.SetMetadata(MetadataKeys.PackageName, resolvedFile.Package.Id.ToString()); item.SetMetadata(MetadataKeys.PackageVersion, resolvedFile.Package.Version.ToString().ToLowerInvariant()); if (resolvedFile.Asset == AssetType.Resources) { // For resources, the DestinationSubDirectory is set to the locale. Set the Culture // metadata on the generated item to this value so that the satellite assemblies can // be filtered by culture. item.SetMetadata(MetadataKeys.Culture, resolvedFile.DestinationSubDirectory.TrimEnd(Path.DirectorySeparatorChar)); } _resolvedAssets.Add(item); } }
protected override void ExecuteCore() { LockFile lockFile = new LockFileCache(BuildEngine4).GetLockFile(AssetsFilePath); ProjectContext projectContext = lockFile.CreateProjectContext( NuGetUtils.ParseFrameworkName(TargetFramework), RuntimeIdentifier, PlatformLibraryName); WriteRuntimeConfig(projectContext); if (!string.IsNullOrEmpty(RuntimeConfigDevPath)) { WriteDevRuntimeConfig(projectContext); } }
protected override void ExecuteCore() { var embeddedApphostPaths = new List <ITaskItem>(); foreach (var runtimeIdentifier in ShimRuntimeIdentifiers.Select(r => r.ItemSpec)) { var resolvedApphostAssetPath = GetApphostAsset(ApphostsForShimRuntimeIdentifiers, runtimeIdentifier); var packagedShimOutputDirectoryAndRid = Path.Combine( PackagedShimOutputDirectory, runtimeIdentifier); var appHostDestinationFilePath = Path.Combine( packagedShimOutputDirectoryAndRid, ToolCommandName + ExecutableExtension.ForRuntimeIdentifier(runtimeIdentifier)); Directory.CreateDirectory(packagedShimOutputDirectoryAndRid); // per https://github.com/dotnet/cli/issues/9870 nuget layout (as in {packageid}/{packageversion}/tools/)is normalized version var normalizedPackageVersion = NuGetVersion.Parse(PackageVersion).ToNormalizedString(); // This is the embedded string. We should normalize it on forward slash, so the file won't be different according to // build machine. var appBinaryFilePath = string.Join("/", new[] { ".store", PackageId.ToLowerInvariant(), normalizedPackageVersion, PackageId.ToLowerInvariant(), normalizedPackageVersion, "tools", NuGetUtils.ParseFrameworkName(TargetFrameworkMoniker).GetShortFolderName(), "any", ToolEntryPoint }); AppHost.Create( resolvedApphostAssetPath, appHostDestinationFilePath, appBinaryFilePath ); var item = new TaskItem(appHostDestinationFilePath); item.SetMetadata(MetadataKeys.ShimRuntimeIdentifier, runtimeIdentifier); embeddedApphostPaths.Add(item); } EmbeddedApphostPaths = embeddedApphostPaths.ToArray(); }
protected override void ExecuteCore() { _runtimePack = GetNETCoreAppRuntimePack(); _crossgen2Pack = Crossgen2Packs?.FirstOrDefault(); _targetRuntimeIdentifier = _runtimePack?.GetMetadata(MetadataKeys.RuntimeIdentifier); // Get the list of runtime identifiers that we support and can target ITaskItem targetingPack = GetNETCoreAppTargetingPack(); string supportedRuntimeIdentifiers = targetingPack?.GetMetadata(MetadataKeys.RuntimePackRuntimeIdentifiers); var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath); var supportedRIDsList = supportedRuntimeIdentifiers == null?Array.Empty <string>() : supportedRuntimeIdentifiers.Split(';'); // Get the best RID for the host machine, which will be used to validate that we can run crossgen for the target platform and architecture _hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid( runtimeGraph, NETCoreSdkRuntimeIdentifier, supportedRIDsList, out _); if (_hostRuntimeIdentifier == null || _targetRuntimeIdentifier == null) { Log.LogError(Strings.ReadyToRunNoValidRuntimePackageError); return; } if (ReadyToRunUseCrossgen2) { if (!ValidateCrossgen2Support()) { return; } // NOTE: Crossgen2 does not yet currently support emitting native symbols, and until this feature // is implemented, we will use crossgen for it. This should go away in the future when crossgen2 supports the feature. if (EmitSymbols && !ValidateCrossgenSupport()) { return; } } else { if (!ValidateCrossgenSupport()) { return; } } }
protected override void ExecuteCore() { _runtimePack = GetNETCoreAppRuntimePack(); _crossgen2Pack = Crossgen2Packs?.FirstOrDefault(); _targetRuntimeIdentifier = _runtimePack?.GetMetadata(MetadataKeys.RuntimeIdentifier); // Get the list of runtime identifiers that we support and can target ITaskItem targetingPack = GetNETCoreAppTargetingPack(); string supportedRuntimeIdentifiers = targetingPack?.GetMetadata(MetadataKeys.RuntimePackRuntimeIdentifiers); var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath); var supportedRIDsList = supportedRuntimeIdentifiers == null?Array.Empty <string>() : supportedRuntimeIdentifiers.Split(';'); // Get the best RID for the host machine, which will be used to validate that we can run crossgen for the target platform and architecture _hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid( runtimeGraph, NETCoreSdkRuntimeIdentifier, supportedRIDsList, out _); if (_hostRuntimeIdentifier == null || _targetRuntimeIdentifier == null) { Log.LogError(Strings.ReadyToRunNoValidRuntimePackageError); return; } if (ReadyToRunUseCrossgen2) { if (!ValidateCrossgen2Support()) { return; } // In .NET 5 Crossgen2 did not support emitting native symbols, so we use Crossgen to emit them if (_crossgen2IsVersion5 && EmitSymbols && !ValidateCrossgenSupport()) { return; } } else { if (!ValidateCrossgenSupport()) { return; } } }
private bool AddCrossgen2Package(Version normalizedTargetFrameworkVersion, List <ITaskItem> packagesToDownload) { var knownCrossgen2Pack = KnownCrossgen2Packs.Where(crossgen2Pack => { var packTargetFramework = NuGetFramework.Parse(crossgen2Pack.GetMetadata("TargetFramework")); return(packTargetFramework.Framework.Equals(TargetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) && NormalizeVersion(packTargetFramework.Version) == normalizedTargetFrameworkVersion); }).SingleOrDefault(); if (knownCrossgen2Pack == null) { return(false); } var crossgen2PackPattern = knownCrossgen2Pack.GetMetadata("Crossgen2PackNamePattern"); var crossgen2PackVersion = knownCrossgen2Pack.GetMetadata("Crossgen2PackVersion"); var crossgen2PackSupportedRuntimeIdentifiers = knownCrossgen2Pack.GetMetadata("Crossgen2RuntimeIdentifiers").Split(';'); // Get the best RID for the host machine, which will be used to validate that we can run crossgen for the target platform and architecture var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath); var hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, NETCoreSdkRuntimeIdentifier, crossgen2PackSupportedRuntimeIdentifiers, out bool wasInGraph); if (hostRuntimeIdentifier == null) { return(false); } var crossgen2PackName = crossgen2PackPattern.Replace("**RID**", hostRuntimeIdentifier); if (!string.IsNullOrEmpty(RuntimeFrameworkVersion)) { crossgen2PackVersion = RuntimeFrameworkVersion; } TaskItem packageToDownload = new TaskItem(crossgen2PackName); packageToDownload.SetMetadata(MetadataKeys.Version, crossgen2PackVersion); packagesToDownload.Add(packageToDownload); Crossgen2Packs = new ITaskItem[1]; Crossgen2Packs[0] = new TaskItem(crossgen2PackName); Crossgen2Packs[0].SetMetadata(MetadataKeys.NuGetPackageId, crossgen2PackName); Crossgen2Packs[0].SetMetadata(MetadataKeys.NuGetPackageVersion, crossgen2PackVersion); return(true); }
private void GetFileDependencies(LockFileTargetLibrary package, string targetName) { string packageId = $"{package.Name}/{package.Version.ToNormalizedString()}"; string frameworkAlias = _targetNameToAliasMap[targetName]; // for each type of file group foreach (var fileGroup in (FileGroup[])Enum.GetValues(typeof(FileGroup))) { var filePathList = fileGroup.GetFilePathAndProperties(package); foreach (var entry in filePathList) { string filePath = entry.Item1; IDictionary <string, string> properties = entry.Item2; if (NuGetUtils.IsPlaceholderFile(filePath) || !EmitLegacyAssetsFileItems) { continue; } var fileKey = $"{packageId}/{filePath}"; var item = new TaskItem(fileKey); item.SetMetadata(MetadataKeys.FileGroup, fileGroup.ToString()); item.SetMetadata(MetadataKeys.ParentTarget, frameworkAlias); // Foreign Key item.SetMetadata(MetadataKeys.ParentPackage, packageId); // Foreign Key if (fileGroup == FileGroup.FrameworkAssembly) { // NOTE: the path provided for framework assemblies is the name of the framework reference item.SetMetadata("FrameworkAssembly", filePath); item.SetMetadata(MetadataKeys.NuGetPackageId, package.Name); item.SetMetadata(MetadataKeys.NuGetPackageVersion, package.Version.ToNormalizedString()); } foreach (var property in properties) { item.SetMetadata(property.Key, property.Value); } _fileDependencies.Add(item); // map each file key to a Type metadata value SaveFileKeyType(fileKey, fileGroup); } } }
protected override void ExecuteCore() { var lockFileCache = new LockFileCache(this); LockFile lockFile = lockFileCache.GetLockFile(AssetsFilePath); ProjectContext projectContext = lockFile.CreateProjectContext( NuGetUtils.ParseFrameworkName(TargetFramework), RuntimeIdentifier, PlatformLibraryName, runtimeFrameworks: null, IsSelfContained); var packageClosure = new HashSet <PackageIdentity>(); foreach (var packageItem in PackagesToPrune) { var pkgName = packageItem.ItemSpec; if (!string.IsNullOrEmpty(pkgName)) { packageClosure.UnionWith(projectContext.GetTransitiveList(pkgName)); } } var packagesToPublish = new HashSet <PackageIdentity>(); foreach (var resolvedFile in ResolvedFiles) { var resolvedPkg = ItemUtilities.GetPackageIdentity(resolvedFile); if (resolvedPkg != null && !packageClosure.Contains(resolvedPkg)) { _assembliesToPublish.Add(resolvedFile); packagesToPublish.Add(resolvedPkg); } } AssembliesToPublish = _assembliesToPublish.ToArray(); foreach (var resolvedPkg in packagesToPublish) { TaskItem item = new TaskItem(resolvedPkg.Id); item.SetMetadata("Version", resolvedPkg.Version.ToString()); _packagesResolved.Add(item); } PublishedPackages = _packagesResolved.ToArray(); }
private bool IsAnalyzer(string file) { bool isAnalyzer = false; if (file.StartsWith("analyzers", StringComparison.Ordinal) && Path.GetExtension(file).Equals(".dll", StringComparison.OrdinalIgnoreCase)) { var projectLanguage = NuGetUtils.GetLockFileLanguageName(ProjectLanguage); if (projectLanguage == "cs" || projectLanguage == "vb") { string excludeLanguage = projectLanguage == "vb" ? "cs" : "vb"; var fileParts = file.Split('/'); isAnalyzer = fileParts.Any(x => x.Equals(projectLanguage, StringComparison.OrdinalIgnoreCase)) || !fileParts.Any(x => x.Equals(excludeLanguage, StringComparison.OrdinalIgnoreCase)); } } return(isAnalyzer); }
protected override void ExecuteCore() { bool writeDevRuntimeConfig = !string.IsNullOrEmpty(RuntimeConfigDevPath); if (AdditionalProbingPaths?.Any() == true && !writeDevRuntimeConfig) { Log.LogWarning(Strings.SkippingAdditionalProbingPaths); } LockFile lockFile = new LockFileCache(this).GetLockFile(AssetsFilePath); ProjectContext projectContext = lockFile.CreateProjectContext( NuGetUtils.ParseFrameworkName(TargetFrameworkMoniker), RuntimeIdentifier, PlatformLibraryName, IsSelfContained); WriteRuntimeConfig(projectContext); if (writeDevRuntimeConfig) { WriteDevRuntimeConfig(projectContext); } }
private void GetFileDependencies(LockFileTargetLibrary package, string targetName) { string packageId = $"{package.Name}/{package.Version.ToNormalizedString()}"; TaskItem item; // for each type of file group foreach (var fileGroup in (FileGroup[])Enum.GetValues(typeof(FileGroup))) { var filePathList = fileGroup.GetFilePathAndProperties(package); foreach (var entry in filePathList) { string filePath = entry.Item1; IDictionary <string, string> properties = entry.Item2; if (NuGetUtils.IsPlaceholderFile(filePath)) { continue; } var fileKey = $"{packageId}/{filePath}"; item = new TaskItem(fileKey); item.SetMetadata(MetadataKeys.FileGroup, fileGroup.ToString()); item.SetMetadata(MetadataKeys.ParentTarget, targetName); // Foreign Key item.SetMetadata(MetadataKeys.ParentPackage, packageId); // Foreign Key foreach (var property in properties) { item.SetMetadata(property.Key, property.Value); } _fileDependencies.Add(item); // map each file key to a Type metadata value SaveFileKeyType(fileKey, fileGroup); } } }
protected override void ExecuteCore() { LockFile lockFile = new LockFileCache(BuildEngine4).GetLockFile(AssetsFilePath); NuGetPathContext nugetPathContext = NuGetPathContext.Create(Path.GetDirectoryName(ProjectPath)); IEnumerable <string> privateAssetsPackageIds = PackageReferenceConverter.GetPackageIds(PrivateAssetsPackageReferences); ProjectContext projectContext = lockFile.CreateProjectContext( NuGetUtils.ParseFrameworkName(TargetFramework), RuntimeIdentifier, PlatformLibraryName); IEnumerable <ResolvedFile> resolvedAssemblies = new PublishAssembliesResolver(new NuGetPackageResolver(nugetPathContext)) .WithPrivateAssets(privateAssetsPackageIds) .Resolve(projectContext); foreach (ResolvedFile resolvedAssembly in resolvedAssemblies) { TaskItem item = new TaskItem(resolvedAssembly.SourcePath); item.SetMetadata("DestinationSubPath", resolvedAssembly.DestinationSubPath); _assembliesToPublish.Add(item); } }
protected override void ExecuteCore() { bool writeDevRuntimeConfig = !string.IsNullOrEmpty(RuntimeConfigDevPath); if (!WriteAdditionalProbingPathsToMainConfig) { if (AdditionalProbingPaths?.Any() == true && !writeDevRuntimeConfig) { 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; } } LockFile lockFile = new LockFileCache(this).GetLockFile(AssetsFilePath); ProjectContext projectContext = lockFile.CreateProjectContext( NuGetUtils.ParseFrameworkName(TargetFrameworkMoniker), RuntimeIdentifier, PlatformLibraryName, RuntimeFrameworks, IsSelfContained); WriteRuntimeConfig(projectContext); if (writeDevRuntimeConfig) { WriteDevRuntimeConfig(projectContext); } }
private void LoadFilesToSkip() { foreach (var fileToSkip in FilesToSkip) { string packageId, packageSubPath; NuGetUtils.GetPackageParts(fileToSkip.ItemSpec, out packageId, out packageSubPath); if (String.IsNullOrEmpty(packageId) || String.IsNullOrEmpty(packageSubPath)) { continue; } var itemType = fileToSkip.GetMetadata(nameof(ConflictResolution.ConflictItemType)); var packagesWithFilesToSkip = (itemType == nameof(ConflictResolution.ConflictItemType.Reference)) ? compileFilesToSkip : runtimeFilesToSkip; HashSet <string> filesToSkipForPackage; if (!packagesWithFilesToSkip.TryGetValue(packageId, out filesToSkipForPackage)) { packagesWithFilesToSkip[packageId] = filesToSkipForPackage = new HashSet <string>(StringComparer.OrdinalIgnoreCase); } filesToSkipForPackage.Add(packageSubPath); } }
private void ProcessRuntimeIdentifier( string runtimeIdentifier, KnownRuntimePack selectedRuntimePack, string runtimePackVersion, List <string> additionalFrameworkReferencesForRuntimePack, HashSet <string> unrecognizedRuntimeIdentifiers, List <ITaskItem> unavailableRuntimePacks, List <ITaskItem> runtimePacks, List <ITaskItem> packagesToDownload, string isTrimmable, bool addToPackageDownload) { var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath); var knownFrameworkReferenceRuntimePackRuntimeIdentifiers = selectedRuntimePack.RuntimePackRuntimeIdentifiers.Split(';'); string runtimePackRuntimeIdentifier = NuGetUtils.GetBestMatchingRid( runtimeGraph, runtimeIdentifier, knownFrameworkReferenceRuntimePackRuntimeIdentifiers, out bool wasInGraph); if (runtimePackRuntimeIdentifier == null) { if (wasInGraph) { // Report this as an error later, if necessary. This is because we try to download // all available runtime packs in case there is a transitive reference to a shared // framework we don't directly reference. But we don't want to immediately error out // here if a runtime pack that we might not need to reference isn't available for the // targeted RID (e.g. Microsoft.WindowsDesktop.App for a linux RID). var unavailableRuntimePack = new TaskItem(selectedRuntimePack.Name); unavailableRuntimePack.SetMetadata(MetadataKeys.RuntimeIdentifier, runtimeIdentifier); unavailableRuntimePacks.Add(unavailableRuntimePack); } else if (!unrecognizedRuntimeIdentifiers.Contains(runtimeIdentifier)) { // NETSDK1083: The specified RuntimeIdentifier '{0}' is not recognized. Log.LogError(Strings.RuntimeIdentifierNotRecognized, runtimeIdentifier); unrecognizedRuntimeIdentifiers.Add(runtimeIdentifier); } } else if (addToPackageDownload) { foreach (var runtimePackNamePattern in selectedRuntimePack.RuntimePackNamePatterns.Split(';')) { string runtimePackName = runtimePackNamePattern.Replace("**RID**", runtimePackRuntimeIdentifier); if (runtimePacks != null) { TaskItem runtimePackItem = new TaskItem(runtimePackName); runtimePackItem.SetMetadata(MetadataKeys.NuGetPackageId, runtimePackName); runtimePackItem.SetMetadata(MetadataKeys.NuGetPackageVersion, runtimePackVersion); runtimePackItem.SetMetadata(MetadataKeys.FrameworkName, selectedRuntimePack.Name); runtimePackItem.SetMetadata(MetadataKeys.RuntimeIdentifier, runtimePackRuntimeIdentifier); runtimePackItem.SetMetadata(MetadataKeys.IsTrimmable, isTrimmable); if (selectedRuntimePack.RuntimePackAlwaysCopyLocal) { runtimePackItem.SetMetadata(MetadataKeys.RuntimePackAlwaysCopyLocal, "true"); } if (additionalFrameworkReferencesForRuntimePack != null) { runtimePackItem.SetMetadata(MetadataKeys.AdditionalFrameworkReferences, string.Join(";", additionalFrameworkReferencesForRuntimePack)); } runtimePacks.Add(runtimePackItem); } TaskItem packageToDownload = new TaskItem(runtimePackName); packageToDownload.SetMetadata(MetadataKeys.Version, runtimePackVersion); packagesToDownload.Add(packageToDownload); } } }
private ITaskItem GetHostItem(string runtimeIdentifier, List <ITaskItem> knownAppHostPacksForTargetFramework, List <ITaskItem> packagesToDownload, string hostNameWithoutExtension, string itemName, bool isExecutable, bool errorIfNotFound) { var selectedAppHostPack = knownAppHostPacksForTargetFramework.Single(); string appHostRuntimeIdentifiers = selectedAppHostPack.GetMetadata("AppHostRuntimeIdentifiers"); string appHostPackPattern = selectedAppHostPack.GetMetadata("AppHostPackNamePattern"); string appHostPackVersion = selectedAppHostPack.GetMetadata("AppHostPackVersion"); if (!string.IsNullOrEmpty(RuntimeFrameworkVersion)) { appHostPackVersion = RuntimeFrameworkVersion; } string bestAppHostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid( new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath), runtimeIdentifier, appHostRuntimeIdentifiers.Split(';'), out bool wasInGraph); if (bestAppHostRuntimeIdentifier == null) { if (wasInGraph) { // NETSDK1084: There was no app host for available for the specified RuntimeIdentifier '{0}'. if (errorIfNotFound) { Log.LogError(Strings.NoAppHostAvailable, runtimeIdentifier); } else { Log.LogMessage(Strings.NoAppHostAvailable, runtimeIdentifier); } } else { // NETSDK1083: The specified RuntimeIdentifier '{0}' is not recognized. if (errorIfNotFound) { Log.LogError(Strings.RuntimeIdentifierNotRecognized, runtimeIdentifier); } else { Log.LogMessage(Strings.RuntimeIdentifierNotRecognized, runtimeIdentifier); } } return(null); } else { string hostPackName = appHostPackPattern.Replace("**RID**", bestAppHostRuntimeIdentifier); string hostRelativePathInPackage = Path.Combine("runtimes", bestAppHostRuntimeIdentifier, "native", hostNameWithoutExtension + (isExecutable ? ExecutableExtension.ForRuntimeIdentifier(bestAppHostRuntimeIdentifier) : ".dll")); TaskItem appHostItem = new TaskItem(itemName); string appHostPackPath = null; if (!string.IsNullOrEmpty(TargetingPackRoot)) { appHostPackPath = Path.Combine(TargetingPackRoot, hostPackName, appHostPackVersion); } if (appHostPackPath != null && Directory.Exists(appHostPackPath)) { // Use AppHost from packs folder appHostItem.SetMetadata(MetadataKeys.PackageDirectory, appHostPackPath); appHostItem.SetMetadata(MetadataKeys.Path, Path.Combine(appHostPackPath, hostRelativePathInPackage)); } else { // C++/CLI does not support package download && dedup error if (!NuGetRestoreSupported && !packagesToDownload.Any(p => p.ItemSpec == hostPackName)) { Log.LogError( Strings.TargetingApphostPackMissingCannotRestore, "Apphost", $"{NetCoreTargetingPackRoot}\\{hostPackName}", selectedAppHostPack.GetMetadata("TargetFramework") ?? "", hostPackName, appHostPackVersion ); } // Download apphost pack TaskItem packageToDownload = new TaskItem(hostPackName); packageToDownload.SetMetadata(MetadataKeys.Version, appHostPackVersion); packagesToDownload.Add(packageToDownload); appHostItem.SetMetadata(MetadataKeys.NuGetPackageId, hostPackName); appHostItem.SetMetadata(MetadataKeys.NuGetPackageVersion, appHostPackVersion); } appHostItem.SetMetadata(MetadataKeys.PathInPackage, hostRelativePathInPackage); appHostItem.SetMetadata(MetadataKeys.RuntimeIdentifier, runtimeIdentifier); return(appHostItem); } }
// get library and file definitions private void GetPackageAndFileDefinitions() { TaskItem item; foreach (var package in LockFile.Libraries) { string packageId = $"{package.Name}/{package.Version.ToNormalizedString()}"; item = new TaskItem(packageId); item.SetMetadata(MetadataKeys.Name, package.Name); item.SetMetadata(MetadataKeys.Type, package.Type); item.SetMetadata(MetadataKeys.Version, package.Version.ToNormalizedString()); item.SetMetadata(MetadataKeys.Path, package.Path ?? string.Empty); string resolvedPackagePath = ResolvePackagePath(package); item.SetMetadata(MetadataKeys.ResolvedPath, resolvedPackagePath ?? string.Empty); _packageDefinitions.Add(item); foreach (var file in package.Files) { if (NuGetUtils.IsPlaceholderFile(file)) { continue; } var fileKey = $"{packageId}/{file}"; var fileItem = new TaskItem(fileKey); fileItem.SetMetadata(MetadataKeys.Path, file); string resolvedPath = ResolveFilePath(file, resolvedPackagePath); fileItem.SetMetadata(MetadataKeys.ResolvedPath, resolvedPath ?? string.Empty); if (IsAnalyzer(file)) { fileItem.SetMetadata(MetadataKeys.Analyzer, "true"); fileItem.SetMetadata(MetadataKeys.Type, "AnalyzerAssembly"); // get targets that contain this package var parentTargets = LockFile.Targets .Where(t => t.Libraries.Any(lib => lib.Name == package.Name)); foreach (var target in parentTargets) { var fileDepsItem = new TaskItem(fileKey); fileDepsItem.SetMetadata(MetadataKeys.ParentTarget, target.Name); // Foreign Key fileDepsItem.SetMetadata(MetadataKeys.ParentPackage, packageId); // Foreign Key _fileDependencies.Add(fileDepsItem); } } else { // get a type for the file if one is available string fileType; if (!_fileTypes.TryGetValue(fileKey, out fileType)) { fileType = "unknown"; } fileItem.SetMetadata(MetadataKeys.Type, fileType); } _fileDefinitions.Add(fileItem); } } }
// get library and file definitions private void GetPackageAndFileDefinitions() { foreach (var package in LockFile.Libraries) { var packageName = package.Name; var packageVersion = package.Version.ToNormalizedString(); string packageId = $"{packageName}/{packageVersion}"; var item = new TaskItem(packageId); item.SetMetadata(MetadataKeys.Name, packageName); item.SetMetadata(MetadataKeys.Type, package.Type); item.SetMetadata(MetadataKeys.Version, packageVersion); item.SetMetadata(MetadataKeys.Path, package.Path ?? string.Empty); string resolvedPackagePath = ResolvePackagePath(package); item.SetMetadata(MetadataKeys.ResolvedPath, resolvedPackagePath ?? string.Empty); item.SetMetadata(MetadataKeys.DiagnosticLevel, GetPackageDiagnosticLevel(package)); _packageDefinitions.Add(item); if (!EmitLegacyAssetsFileItems) { continue; } foreach (var file in package.Files) { if (NuGetUtils.IsPlaceholderFile(file)) { continue; } var fileKey = $"{packageId}/{file}"; var fileItem = new TaskItem(fileKey); fileItem.SetMetadata(MetadataKeys.Path, file); fileItem.SetMetadata(MetadataKeys.NuGetPackageId, packageName); fileItem.SetMetadata(MetadataKeys.NuGetPackageVersion, packageVersion); string resolvedPath = ResolveFilePath(file, resolvedPackagePath); fileItem.SetMetadata(MetadataKeys.ResolvedPath, resolvedPath ?? string.Empty); if (NuGetUtils.IsApplicableAnalyzer(file, ProjectLanguage)) { fileItem.SetMetadata(MetadataKeys.Analyzer, "true"); fileItem.SetMetadata(MetadataKeys.Type, "AnalyzerAssembly"); // get targets that contain this package var parentTargets = LockFile.Targets .Where(t => t.Libraries.Any(lib => lib.Name == package.Name)); foreach (var target in parentTargets) { string frameworkAlias = _targetNameToAliasMap[target.Name]; var fileDepsItem = new TaskItem(fileKey); fileDepsItem.SetMetadata(MetadataKeys.ParentTarget, frameworkAlias); // Foreign Key fileDepsItem.SetMetadata(MetadataKeys.ParentPackage, packageId); // Foreign Key _fileDependencies.Add(fileDepsItem); } } else { // get a type for the file if one is available if (!_fileTypes.TryGetValue(fileKey, out string fileType)) { fileType = "unknown"; } fileItem.SetMetadata(MetadataKeys.Type, fileType); } _fileDefinitions.Add(fileItem); } } string GetPackageDiagnosticLevel(LockFileLibrary package) { string target = TargetFramework ?? ""; var messages = LockFile.LogMessages.Where(log => log.LibraryId == package.Name && log.TargetGraphs .Select(tg => { var parsedTargetGraph = NuGetFramework.Parse(tg); var alias = _lockFile.PackageSpec.TargetFrameworks.FirstOrDefault(tf => tf.FrameworkName == parsedTargetGraph)?.TargetAlias; return(alias ?? tg); }).Contains(target)); if (!messages.Any()) { return(string.Empty); } return(messages.Max(log => log.Level).ToString()); } }