private ProjectContext GetProjectContextFromDirectory(string directory, NuGetFramework framework)
        {
            if (directory == null || framework == null)
            {
                return(null);
            }

            var projectRootPath = directory;

            if (!File.Exists(Path.Combine(projectRootPath, Project.FileName)))
            {
                return(null);
            }

            return(ProjectContext.Create(
                       projectRootPath,
                       framework,
                       RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers()));
        }
Esempio n. 2
0
        public static IEnumerable <string> InferCurrentRuntimeIdentifiers(DotnetVersionFile versionFile)
        {
            IEnumerable <string> fallbackIdentifiers = null;

            // If the machine's RID isn't supported by the shared framework (i.e. the CLI
            // is being used on a newer version of an OS), add the RID that the CLI was built
            // with as a fallback.  The RID the CLI was built with will have the correct
            // runtime.* NuGet packages available.
            // For example, when a user is using osx.10.12, but we only support osx.10.10 and
            // osx.10.11, the project.json "runtimes" section cannot contain osx.10.12, since
            // that RID isn't contained in the runtime graph - users will get a restore error.
            FrameworkDependencyFile fxDepsFile = new FrameworkDependencyFile();

            if (!fxDepsFile.SupportsCurrentRuntime())
            {
                string buildRid = versionFile.BuildRid;
                if (!string.IsNullOrEmpty(buildRid))
                {
                    fallbackIdentifiers = new string[] { buildRid };
                }
            }

            return(RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers(fallbackIdentifiers));
        }