Esempio n. 1
0
        /// <summary>
        /// Read project inputs using MSBuild
        /// </summary>
        private async Task DetermineInputsFromMSBuildAsync(PackageRestoreInputs packageRestoreInputs)
        {
            // Find P2P graph for v3 inputs.
            // Ignore xproj files as top level inputs
            var projectsWithPotentialP2PReferences = packageRestoreInputs
                                                     .ProjectFiles
                                                     .Where(path => !path.EndsWith(".xproj", StringComparison.OrdinalIgnoreCase))
                                                     .ToArray();

            if (projectsWithPotentialP2PReferences.Length > 0)
            {
                DependencyGraphSpec dgFileOutput = null;

                try
                {
                    dgFileOutput = await GetDependencyGraphSpecAsync(projectsWithPotentialP2PReferences,
                                                                     GetSolutionDirectory(packageRestoreInputs),
                                                                     packageRestoreInputs.NameOfSolutionFile,
                                                                     ConfigFile);
                }
                catch (Exception ex)
                {
                    // At this point reading the project has failed, to keep backwards
                    // compatibility this should warn instead of error if
                    // packages.config files exist, but no project.json files.
                    // This will skip NETCore projects which is a problem, but there is
                    // not a good way to know if they exist, or if this is an old type of
                    // project that the targets file cannot handle.

                    // Log exception for debug
                    Console.LogDebug(ex.ToString());

                    // Check for packages.config but no project.json files
                    if (projectsWithPotentialP2PReferences.Where(HasPackagesConfigFile).Any() &&
                        !projectsWithPotentialP2PReferences.Where(HasProjectJsonFile).Any())
                    {
                        // warn to let the user know that NETCore will be skipped
                        Console.LogWarning(LocalizedResourceManager.GetString("Warning_ReadingProjectsFailed"));

                        // Add packages.config
                        packageRestoreInputs.PackagesConfigFiles
                        .AddRange(projectsWithPotentialP2PReferences
                                  .Select(GetPackagesConfigFile)
                                  .Where(path => path != null));
                    }
                    else
                    {
                        // If there are project.json files or no packages.config files
                        // continue to fail
                        throw;
                    }
                }

                // Process the DG file and add both v2 and v3 inputs
                if (dgFileOutput != null)
                {
                    AddInputsFromDependencyGraphSpec(packageRestoreInputs, dgFileOutput);
                }
            }
        }