/// <summary> /// Determine if a file is v2 or v3 /// </summary> private void GetInputsFromFile(string projectFilePath, PackageRestoreInputs packageRestoreInputs) { // An argument was passed in. It might be a solution file or directory, // project file, or packages.config file var projectFileName = Path.GetFileName(projectFilePath); if (IsPackagesConfig(projectFileName)) { // restoring from packages.config or packages.projectname.config file packageRestoreInputs.PackagesConfigFiles.Add(projectFilePath); } else if (projectFileName.EndsWith("proj", StringComparison.OrdinalIgnoreCase)) { packageRestoreInputs.ProjectFiles.Add(projectFilePath); } else if (projectFileName.EndsWith(".dg", StringComparison.OrdinalIgnoreCase)) { packageRestoreInputs.RestoreV3Context.Inputs.Add(projectFilePath); } else if (projectFileName.EndsWith(".sln", StringComparison.OrdinalIgnoreCase)) { ProcessSolutionFile(projectFilePath, packageRestoreInputs); } else if (ProjectJsonPathUtilities.IsProjectConfig(projectFileName)) { // project.json is no longer allowed throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, LocalizedResourceManager.GetString("Error_ProjectJsonNotAllowed"), projectFileName)); } else { // Not a file we know about. Try to be helpful without response. throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, RestoreRunner.GetInvalidInputErrorMessage(projectFileName), projectFileName)); } }
/// <summary> /// Determine if a file is v2 or v3 /// </summary> private void GetInputsFromFile(string projectFilePath, PackageRestoreInputs packageRestoreInputs) { // An argument was passed in. It might be a solution file or directory, // project file, project.json, or packages.config file var projectFileName = Path.GetFileName(projectFilePath); if (ProjectJsonPathUtilities.IsProjectConfig(projectFileName)) { // project.json or projName.project.json packageRestoreInputs.RestoreV3Context.Inputs.Add(projectFilePath); } else if (IsPackagesConfig(projectFileName)) { // restoring from packages.config or packages.projectname.config file packageRestoreInputs.PackagesConfigFiles.Add(projectFilePath); } else if (projectFileName.EndsWith("proj", StringComparison.OrdinalIgnoreCase)) { // For msbuild files find the project.json or packages.config file, // if neither exist skip it var projectName = Path.GetFileNameWithoutExtension(projectFileName); var dir = Path.GetDirectoryName(projectFilePath); var projectJsonPath = ProjectJsonPathUtilities.GetProjectConfigPath(dir, projectName); var packagesConfigPath = GetPackageReferenceFile(projectFilePath); // Check for project.json if (File.Exists(projectJsonPath)) { if (MsBuildUtility.IsMsBuildBasedProject(projectFilePath)) { // Add the project file path if it allows p2ps packageRestoreInputs.RestoreV3Context.Inputs.Add(projectFilePath); } else { // Unknown project type, add the project.json by itself packageRestoreInputs.RestoreV3Context.Inputs.Add(projectJsonPath); } } else if (File.Exists(packagesConfigPath)) { // Check for packages.config, if it exists add it directly packageRestoreInputs.PackagesConfigFiles.Add(packagesConfigPath); } } else if (projectFileName.EndsWith(".dg", StringComparison.OrdinalIgnoreCase)) { packageRestoreInputs.RestoreV3Context.Inputs.Add(projectFilePath); } else if (projectFileName.EndsWith(".sln", StringComparison.OrdinalIgnoreCase)) { ProcessSolutionFile(projectFilePath, packageRestoreInputs); } else { // Not a file we know about. Try to be helpful without response. throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, RestoreRunner.GetInvalidInputErrorMessage(projectFileName), projectFileName)); } }