Ejemplo n.º 1
0
        private IConfigurationSource ExtractConfigurationSource(string?baseDirectory, IConfigurationSource?appSettings)
        {
            baseDirectory ??= Path.GetDirectoryName(MainModule);

            var configurationSource = new CompositeConfigurationSource();

            configurationSource.Add(new DictionaryConfigurationSource(EnvironmentVariables));

            if (appSettings != null)
            {
                configurationSource.Add(appSettings);
            }
            else if (DotnetRuntime.HasFlag(Runtime.NetFx))
            {
                var appConfigSource = LoadApplicationConfig(MainModule);

                if (appConfigSource != null)
                {
                    configurationSource.Add(appConfigSource);
                }
            }

            if (GlobalSettings.TryLoadJsonConfigurationFile(configurationSource, baseDirectory, out var jsonConfigurationSource))
            {
                configurationSource.Add(jsonConfigurationSource);
            }

            return(configurationSource);
        }
    private DotnetRuntime[] GetRuntimes()
    {
        var configFilePath = Path.ChangeExtension(FilePath, "runtimeconfig.json");
        var runtimes       = DotnetRuntime.GetAllTargets(configFilePath).ToList();

        // Desktop runtimes already include the base runtimes, so we can filter out unnecessary targets
        // https://github.com/Tyrrrz/DotnetRuntimeBootstrapper/issues/30
        if (runtimes.Count > 1)
        {
            foreach (var desktopRuntime in runtimes.Where(r => r.IsWindowsDesktop).ToArray())
            {
                // Only filter out compatible base runtimes!
                // If the app targets .NET 5 desktop and .NET 6 base,
                // we still need to keep the base.
                // Very unlikely that such a situation will happen though.
                runtimes.RemoveAll(r =>
                                   r.IsBase &&
                                   r.Version.Major == desktopRuntime.Version.Major &&
                                   r.Version <= desktopRuntime.Version
                                   );
            }
        }

        return(runtimes.ToArray());
    }
 public bool IsSupersededBy(DotnetRuntime other) =>
 string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase) &&
 Version.Major == other.Version.Major &&
 Version <= other.Version;