Exemplo n.º 1
0
        private bool TryResolveFramework(
            IEnumerable <NuGetFramework> availableFrameworks,
            out NuGetFramework resolvedFramework)
        {
            NuGetFramework framework;

            if (FrameworkOption.HasValue())
            {
                var frameworkOptionValue = FrameworkOption.Value();
                framework = NuGetFramework.Parse(frameworkOptionValue);

                if (!availableFrameworks.Contains(framework))
                {
                    ReportError(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            Resources.ProjectDoesNotSupportProvidedFramework,
                            ProjectArgument.Value,
                            frameworkOptionValue));

                    resolvedFramework = null;
                    return(false);
                }
            }
            else
            {
                // Prioritize non-desktop frameworks since they have the option of not dispatching to resolve TagHelpers.
                framework = availableFrameworks.FirstOrDefault(f => !f.IsDesktop()) ?? availableFrameworks.First();
            }

            resolvedFramework = framework;
            return(true);
        }
        private bool TryResolveFramework(
            IEnumerable <NuGetFramework> availableFrameworks,
            out NuGetFramework resolvedFramework)
        {
            NuGetFramework framework;

            if (FrameworkOption.HasValue())
            {
                var frameworkOptionValue = FrameworkOption.Value();
                framework = NuGetFramework.Parse(frameworkOptionValue);

                if (!availableFrameworks.Contains(framework))
                {
                    ReportError(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            Resources.ProjectDoesNotSupportProvidedFramework,
                            ProjectArgument.Value,
                            frameworkOptionValue));

                    resolvedFramework = null;
                    return(false);
                }
            }
            else
            {
                framework = availableFrameworks.First();
            }

            resolvedFramework = framework;
            return(true);
        }
Exemplo n.º 3
0
        private void ParseArguments()
        {
            ProjectPath   = GetProjectPath();
            Configuration = ConfigurationOption.Value() ?? DotNet.Cli.Utils.Constants.DefaultConfiguration;

            if (!FrameworkOption.HasValue())
            {
                throw new Exception($"Option {FrameworkOption.Template} does not have a value.");
            }
            TargetFramework = NuGetFramework.Parse(FrameworkOption.Value());

            if (!OutputPathOption.HasValue())
            {
                throw new Exception($"Option {OutputPathOption.Template} does not have a value.");
            }
            OutputPath = OutputPathOption.Value();
        }
Exemplo n.º 4
0
        private ProjectContext GetRuntimeContext()
        {
            var workspace = new BuildWorkspace(ProjectReaderSettings.ReadFromEnvironment());

            var projectContext = workspace.GetProjectContext(ProjectPath, TargetFramework);

            if (projectContext == null)
            {
                Debug.Assert(FrameworkOption.HasValue());
                throw new InvalidOperationException($"Project '{ProjectPath}' does not support framework: {FrameworkOption.Value()}");
            }

            var runtimeContext = workspace.GetRuntimeContext(
                projectContext,
                RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());

            return(runtimeContext);
        }
        private bool ParseArguments()
        {
            ProjectPath   = GetProjectPath(Options.ProjectArgument.Value);
            Configuration = ConfigurationOption.Value() ?? DotNet.Cli.Utils.Constants.DefaultConfiguration;

            if (FrameworkOption.HasValue())
            {
                TargetFramework = NuGetFramework.Parse(FrameworkOption.Value());
            }

            if (!OutputPathOption.HasValue())
            {
                Application.Error.WriteLine($"Option {OutputPathOption.Template} does not have a value.");
                return(false);
            }
            OutputPath = OutputPathOption.Value();

            return(true);
        }
        private ProjectContext GetRuntimeContext()
        {
            var            workspace       = new BuildWorkspace(ProjectReaderSettings.ReadFromEnvironment());
            var            projectContexts = ProjectContext.CreateContextForEachFramework(ProjectPath).ToArray();
            ProjectContext projectContext;

            if (TargetFramework != null)
            {
                projectContext = projectContexts.FirstOrDefault(context => context.TargetFramework.Equals(TargetFramework));
                if (projectContext == null)
                {
                    throw new InvalidOperationException($"Project '{ProjectPath}' does not support framework: {FrameworkOption.Value()}");
                }
            }
            else if (projectContexts.Length == 1)
            {
                projectContext = projectContexts[0];
            }
            else
            {
                throw new InvalidOperationException($"Project '{ProjectPath}' targets multiple frameworks. Specify one using '{FrameworkOption.Template}.");
            }

            return(workspace.GetRuntimeContext(
                       projectContext,
                       RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers()));
        }