Ejemplo n.º 1
0
        private void ProcessRuntimeIdentifier(string runtimeIdentifier, KnownFrameworkReference knownFrameworkReference,
                                              string runtimeFrameworkVersion, HashSet <string> unrecognizedRuntimeIdentifiers,
                                              List <ITaskItem> unavailableRuntimePacks, List <ITaskItem> runtimePacks, List <ITaskItem> packagesToDownload, string isTrimmable)
        {
            var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath);
            var knownFrameworkReferenceRuntimePackRuntimeIdentifiers = knownFrameworkReference.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(knownFrameworkReference.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
            {
                foreach (var runtimePackNamePattern in knownFrameworkReference.RuntimePackNamePatterns.Split(';'))
                {
                    string runtimePackName = runtimePackNamePattern.Replace("**RID**", runtimePackRuntimeIdentifier);

                    if (runtimePacks != null)
                    {
                        TaskItem runtimePackItem = new TaskItem(runtimePackName);
                        runtimePackItem.SetMetadata(MetadataKeys.PackageName, runtimePackName);
                        runtimePackItem.SetMetadata(MetadataKeys.PackageVersion, runtimeFrameworkVersion);
                        runtimePackItem.SetMetadata(MetadataKeys.FrameworkName, knownFrameworkReference.Name);
                        runtimePackItem.SetMetadata(MetadataKeys.RuntimeIdentifier, runtimePackRuntimeIdentifier);
                        runtimePackItem.SetMetadata(MetadataKeys.IsTrimmable, isTrimmable);
                        runtimePackItem.SetMetadata(MetadataKeys.AvailableRuntimeIdentifiers, knownFrameworkReference.RuntimePackRuntimeIdentifiers);

                        runtimePacks.Add(runtimePackItem);
                    }

                    TaskItem packageToDownload = new TaskItem(runtimePackName);
                    packageToDownload.SetMetadata(MetadataKeys.Version, runtimeFrameworkVersion);

                    packagesToDownload.Add(packageToDownload);
                }
            }
        }
Ejemplo n.º 2
0
        private bool AddAotOrR2RRuntimePackage(AotPackageType packageType, Version normalizedTargetFrameworkVersion, List <ITaskItem> packagesToDownload)
        {
            var knownPacks = packageType == AotPackageType.Crossgen2 ? KnownCrossgen2Packs : KnownILCompilerPacks;
            var knownPack  = knownPacks.Where(pack =>
            {
                var packTargetFramework = NuGetFramework.Parse(pack.GetMetadata("TargetFramework"));
                return(packTargetFramework.Framework.Equals(TargetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) &&
                       NormalizeVersion(packTargetFramework.Version) == normalizedTargetFrameworkVersion);
            }).SingleOrDefault();

            if (knownPack == null)
            {
                return(false);
            }

            var packageName = packageType == AotPackageType.Crossgen2 ? "Crossgen2" : "ILCompiler";

            var packPattern = knownPack.GetMetadata(packageName + "PackNamePattern");
            var packVersion = knownPack.GetMetadata(packageName + "PackVersion");
            var packSupportedRuntimeIdentifiers = knownPack.GetMetadata(packageName + "RuntimeIdentifiers").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, packSupportedRuntimeIdentifiers, out bool wasInGraph);

            if (hostRuntimeIdentifier == null)
            {
                return(false);
            }

            var runtimePackName = packPattern.Replace("**RID**", hostRuntimeIdentifier);

            if (!string.IsNullOrEmpty(RuntimeFrameworkVersion))
            {
                packVersion = RuntimeFrameworkVersion;
            }

            // We need to download the runtime pack
            TaskItem runtimePackToDownload = new TaskItem(runtimePackName);

            runtimePackToDownload.SetMetadata(MetadataKeys.Version, packVersion);
            packagesToDownload.Add(runtimePackToDownload);

            var newItem = new TaskItem(runtimePackName);

            newItem.SetMetadata(MetadataKeys.NuGetPackageId, runtimePackName);
            newItem.SetMetadata(MetadataKeys.NuGetPackageVersion, packVersion);

            if (packageType == AotPackageType.Crossgen2)
            {
                Crossgen2Packs = new[] { newItem };
            }
            else
            {
                ILCompilerPacks = new[] { newItem };
            }

            return(true);
        }
        private string GetBestRuntimeIdentifier(string targetRuntimeIdentifier, string availableRuntimeIdentifiers, out bool wasInGraph)
        {
            var runtimeGraph          = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath);
            var bestRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph,
                                                                      AppHostRuntimeIdentifier,
                                                                      availableRuntimeIdentifiers.Split(';'),
                                                                      out wasInGraph);

            return(bestRuntimeIdentifier);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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));
        }
Ejemplo n.º 8
0
        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;
                }
            }
        }
Ejemplo n.º 9
0
        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;
                }
            }
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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);
            }
        }
Ejemplo n.º 12
0
        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 addRuntimePackAndDownloadIfNecessary)
        {
            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 (addRuntimePackAndDownloadIfNecessary)
            {
                foreach (var runtimePackNamePattern in selectedRuntimePack.RuntimePackNamePatterns.Split(';'))
                {
                    string runtimePackName = runtimePackNamePattern.Replace("**RID**", runtimePackRuntimeIdentifier);

                    //  Look up runtimePackVersion from workload manifests if necessary
                    string resolvedRuntimePackVersion = GetResolvedPackVersion(runtimePackName, runtimePackVersion);

                    string runtimePackPath = GetPackPath(runtimePackName, resolvedRuntimePackVersion);

                    if (runtimePacks != null)
                    {
                        TaskItem runtimePackItem = new TaskItem(runtimePackName);
                        runtimePackItem.SetMetadata(MetadataKeys.NuGetPackageId, runtimePackName);
                        runtimePackItem.SetMetadata(MetadataKeys.NuGetPackageVersion, resolvedRuntimePackVersion);
                        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));
                        }

                        if (runtimePackPath != null)
                        {
                            runtimePackItem.SetMetadata(MetadataKeys.PackageDirectory, runtimePackPath);
                        }

                        runtimePacks.Add(runtimePackItem);
                    }

                    if (runtimePackPath == null)
                    {
                        TaskItem packageToDownload = new TaskItem(runtimePackName);
                        packageToDownload.SetMetadata(MetadataKeys.Version, resolvedRuntimePackVersion);

                        packagesToDownload.Add(packageToDownload);
                    }
                }
            }
        }
Ejemplo n.º 13
0
        private ITaskItem GetAppHostItem(string runtimeIdentifier, List <ITaskItem> knownAppHostPacksForTargetFramework,
                                         List <ITaskItem> packagesToDownload)
        {
            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}'.
                    Log.LogError(Strings.NoAppHostAvailable, runtimeIdentifier);
                }
                else
                {
                    //  NETSDK1083: The specified RuntimeIdentifier '{0}' is not recognized.
                    Log.LogError(Strings.RuntimeIdentifierNotRecognized, runtimeIdentifier);
                }
                return(null);
            }
            else
            {
                string appHostPackName = appHostPackPattern.Replace("**RID**", bestAppHostRuntimeIdentifier);

                string appHostRelativePathInPackage = Path.Combine("runtimes", bestAppHostRuntimeIdentifier, "native",
                                                                   DotNetAppHostExecutableNameWithoutExtension + ExecutableExtension.ForRuntimeIdentifier(bestAppHostRuntimeIdentifier));


                TaskItem appHostItem     = new TaskItem("AppHost");
                string   appHostPackPath = null;
                if (!string.IsNullOrEmpty(TargetingPackRoot))
                {
                    appHostPackPath = Path.Combine(TargetingPackRoot, appHostPackName, appHostPackVersion);
                }
                if (appHostPackPath != null && Directory.Exists(appHostPackPath))
                {
                    //  Use AppHost from packs folder
                    appHostItem.SetMetadata(MetadataKeys.PackageDirectory, appHostPackPath);
                    appHostItem.SetMetadata(MetadataKeys.Path, Path.Combine(appHostPackPath, appHostRelativePathInPackage));
                }
                else
                {
                    //  Download apphost pack
                    TaskItem packageToDownload = new TaskItem(appHostPackName);
                    packageToDownload.SetMetadata(MetadataKeys.Version, appHostPackVersion);

                    packagesToDownload.Add(packageToDownload);

                    appHostItem.SetMetadata(MetadataKeys.RuntimeIdentifier, runtimeIdentifier);
                    appHostItem.SetMetadata(MetadataKeys.PackageName, appHostPackName);
                    appHostItem.SetMetadata(MetadataKeys.PackageVersion, appHostPackVersion);
                    appHostItem.SetMetadata(MetadataKeys.RelativePath, appHostRelativePathInPackage);
                }

                return(appHostItem);
            }
        }
Ejemplo n.º 14
0
        protected override void ExecuteCore()
        {
            //  Perf optimization: If there are no FrameworkReference items, then don't do anything
            //  (This means that if you don't have any direct framework references, you won't get any transitive ones either
            if (FrameworkReferences == null || FrameworkReferences.Length == 0)
            {
                return;
            }

            var knownFrameworkReferencesForTargetFramework = KnownFrameworkReferences.Select(item => new KnownFrameworkReference(item))
                                                             .Where(kfr => kfr.TargetFramework.Framework.Equals(TargetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) &&
                                                                    NormalizeVersion(kfr.TargetFramework.Version) == NormalizeVersion(new Version(TargetFrameworkVersion)))
                                                             .ToList();

            var frameworkReferenceMap = FrameworkReferences.ToDictionary(fr => fr.ItemSpec);

            List <ITaskItem> packagesToDownload      = new List <ITaskItem>();
            List <ITaskItem> runtimeFrameworks       = new List <ITaskItem>();
            List <ITaskItem> targetingPacks          = new List <ITaskItem>();
            List <ITaskItem> runtimePacks            = new List <ITaskItem>();
            List <ITaskItem> unavailableRuntimePacks = new List <ITaskItem>();

            bool reportedUnrecognizedRuntimeIdentifier = false;

            foreach (var knownFrameworkReference in knownFrameworkReferencesForTargetFramework)
            {
                frameworkReferenceMap.TryGetValue(knownFrameworkReference.Name, out ITaskItem frameworkReference);

                //  Get the path of the targeting pack in the targeting pack root (e.g. dotnet/ref)
                TaskItem targetingPack = new TaskItem(knownFrameworkReference.Name);
                targetingPack.SetMetadata(MetadataKeys.PackageName, knownFrameworkReference.TargetingPackName);

                string targetingPackVersion = null;
                if (frameworkReference != null)
                {
                    //  Allow targeting pack version to be overridden via metadata on FrameworkReference
                    targetingPackVersion = frameworkReference.GetMetadata("TargetingPackVersion");
                }
                if (string.IsNullOrEmpty(targetingPackVersion))
                {
                    targetingPackVersion = knownFrameworkReference.TargetingPackVersion;
                }
                targetingPack.SetMetadata(MetadataKeys.PackageVersion, targetingPackVersion);

                string targetingPackPath = null;
                if (!string.IsNullOrEmpty(TargetingPackRoot))
                {
                    targetingPackPath = Path.Combine(TargetingPackRoot, knownFrameworkReference.TargetingPackName, knownFrameworkReference.TargetingPackVersion);
                }
                if (targetingPackPath != null && Directory.Exists(targetingPackPath))
                {
                    // Use targeting pack from packs folder
                    targetingPack.SetMetadata(MetadataKeys.PackageDirectory, targetingPackPath);
                    targetingPack.SetMetadata(MetadataKeys.Path, targetingPackPath);
                }
                else
                {
                    if (EnableTargetingPackDownload)
                    {
                        //  Download targeting pack
                        TaskItem packageToDownload = new TaskItem(knownFrameworkReference.TargetingPackName);
                        packageToDownload.SetMetadata(MetadataKeys.Version, targetingPackVersion);

                        packagesToDownload.Add(packageToDownload);
                    }
                }

                targetingPacks.Add(targetingPack);

                var runtimeFrameworkVersion = GetRuntimeFrameworkVersion(frameworkReference, knownFrameworkReference);

                if (SelfContained &&
                    !string.IsNullOrEmpty(RuntimeIdentifier) &&
                    !string.IsNullOrEmpty(knownFrameworkReference.RuntimePackNamePatterns))
                {
                    foreach (var runtimePackNamePattern in knownFrameworkReference.RuntimePackNamePatterns.Split(';'))
                    {
                        string runtimePackRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(
                            new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath),
                            RuntimeIdentifier,
                            knownFrameworkReference.RuntimePackRuntimeIdentifiers.Split(';'),
                            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(knownFrameworkReference.Name);
                                unavailableRuntimePack.SetMetadata(MetadataKeys.RuntimeIdentifier, RuntimeIdentifier);
                                unavailableRuntimePacks.Add(unavailableRuntimePack);
                            }
                            else if (!reportedUnrecognizedRuntimeIdentifier)
                            {
                                //  NETSDK1083: The specified RuntimeIdentifier '{0}' is not recognized.
                                Log.LogError(Strings.RuntimeIdentifierNotRecognized, RuntimeIdentifier);
                                reportedUnrecognizedRuntimeIdentifier = true;
                            }
                        }
                        else
                        {
                            string runtimePackName = runtimePackNamePattern.Replace("**RID**", runtimePackRuntimeIdentifier);

                            TaskItem runtimePackItem = new TaskItem(runtimePackName);
                            runtimePackItem.SetMetadata(MetadataKeys.PackageName, runtimePackName);
                            runtimePackItem.SetMetadata(MetadataKeys.PackageVersion, runtimeFrameworkVersion);
                            runtimePackItem.SetMetadata(MetadataKeys.FrameworkName, knownFrameworkReference.Name);
                            runtimePackItem.SetMetadata(MetadataKeys.RuntimeIdentifier, runtimePackRuntimeIdentifier);

                            runtimePacks.Add(runtimePackItem);

                            TaskItem packageToDownload = new TaskItem(runtimePackName);
                            packageToDownload.SetMetadata(MetadataKeys.Version, runtimeFrameworkVersion);

                            packagesToDownload.Add(packageToDownload);
                        }
                    }
                }

                TaskItem runtimeFramework = new TaskItem(knownFrameworkReference.RuntimeFrameworkName);

                runtimeFramework.SetMetadata(MetadataKeys.Version, runtimeFrameworkVersion);
                runtimeFramework.SetMetadata(MetadataKeys.FrameworkName, knownFrameworkReference.Name);

                runtimeFrameworks.Add(runtimeFramework);
            }

            if (packagesToDownload.Any())
            {
                PackagesToDownload = packagesToDownload.ToArray();
            }

            if (runtimeFrameworks.Any())
            {
                RuntimeFrameworks = runtimeFrameworks.ToArray();
            }

            if (targetingPacks.Any())
            {
                TargetingPacks = targetingPacks.ToArray();
            }

            if (runtimePacks.Any())
            {
                RuntimePacks = runtimePacks.ToArray();
            }

            if (unavailableRuntimePacks.Any())
            {
                UnavailableRuntimePacks = unavailableRuntimePacks.ToArray();
            }
        }