Пример #1
0
        public override SdkResult Resolve(SdkReference sdkReference, SdkResolverContext resolverContext, SdkResultFactory factory)
        {
            if (!_enabled)
            {
                return(null);
            }

            InitializeWorkloadResolver(resolverContext);

            if (sdkReference.Name.Equals("Microsoft.NET.SDK.WorkloadAutoImportPropsLocator", StringComparison.OrdinalIgnoreCase))
            {
                List <string> autoImportSdkPaths = new List <string>();
                foreach (var sdkPackInfo in _workloadResolver.GetInstalledWorkloadPacksOfKind(WorkloadPackKind.Sdk))
                {
                    string sdkPackSdkFolder = Path.Combine(sdkPackInfo.Path, "Sdk");
                    string autoImportPath   = Path.Combine(sdkPackSdkFolder, "AutoImport.props");
                    if (File.Exists(autoImportPath))
                    {
                        autoImportSdkPaths.Add(sdkPackSdkFolder);
                    }
                }
                //  Call Distinct() here because with aliased packs, there may be duplicates of the same path
                return(factory.IndicateSuccess(autoImportSdkPaths.Distinct(), sdkReference.Version));
            }
            else if (sdkReference.Name.Equals("Microsoft.NET.SDK.WorkloadManifestTargetsLocator", StringComparison.OrdinalIgnoreCase))
            {
                List <string> workloadManifestPaths = new List <string>();
                foreach (var manifestDirectory in _workloadManifestProvider.GetManifestDirectories())
                {
                    var workloadManifestTargetPath = Path.Combine(manifestDirectory, "WorkloadManifest.targets");
                    if (File.Exists(workloadManifestTargetPath))
                    {
                        workloadManifestPaths.Add(manifestDirectory);
                    }
                }
                return(factory.IndicateSuccess(workloadManifestPaths, sdkReference.Version));
            }
            else
            {
                var packInfo = _workloadResolver.TryGetPackInfo(sdkReference.Name);
                if (packInfo != null)
                {
                    if (Directory.Exists(packInfo.Path))
                    {
                        return(factory.IndicateSuccess(Path.Combine(packInfo.Path, "Sdk"), sdkReference.Version));
                    }
                    else
                    {
                        var itemsToAdd = new Dictionary <string, SdkResultItem>();
                        itemsToAdd.Add("MissingWorkloadPack",
                                       new SdkResultItem(sdkReference.Name,
                                                         metadata: new Dictionary <string, string>()
                        {
                            { "Version", packInfo.Version }
                        }));

                        Dictionary <string, string> propertiesToAdd = new Dictionary <string, string>();
                        return(factory.IndicateSuccess(Enumerable.Empty <string>(),
                                                       sdkReference.Version,
                                                       propertiesToAdd: propertiesToAdd,
                                                       itemsToAdd: itemsToAdd));
                    }
                }
            }
            return(null);
        }