public DependencyGraphSpec GenerateDependencyGraph(string projectPath) { var dgOutput = _fileSystem.Path.Combine(_fileSystem.Path.GetTempPath(), _fileSystem.Path.GetTempFileName()); string[] arguments = { "msbuild", $"\"{projectPath}\"", "/t:Restore,GenerateRestoreGraphFile", $"/p:RestoreGraphOutputPath=\"{dgOutput}\"" }; var runStatus = _dotNetRunner.Run(_fileSystem.Path.GetDirectoryName(projectPath), arguments); if (runStatus.IsSuccess) { /* * TempDirectory is a hacky workaround for DependencyGraphSpec(JObject) * being deprecated. Unfortunately it looks like the only alternative * is to load the file locally. Which is ok normally, but complicates * testing. */ using (var tempDirectory = new TempDirectory()) { var dependencyGraphFilename = System.IO.Path.Combine(tempDirectory.DirectoryPath, "DependencyGraph.json"); var dependencyGraphText = _fileSystem.File.ReadAllText(dgOutput); System.IO.File.WriteAllText(dependencyGraphFilename, dependencyGraphText); return(DependencyGraphSpec.Load(dependencyGraphFilename)); } } throw new CommandValidationException($"Unable to process the project `{projectPath}. Are you sure this is a valid .NET Core or .NET Standard project type?" + $"{Environment.NewLine}{Environment.NewLine}Here is the full error message returned from the Microsoft Build Engine:{Environment.NewLine}{Environment.NewLine}{runStatus.Output} - {runStatus.Errors} - exit code: {runStatus.ExitCode}"); }
private DependencyGraphSpec GetDependencies(string projectPath) { var tmpFile = new TemporaryFile(projectPath); var tmpFilePath = tmpFile.Path; string[] arguments = { "msbuild", $"\"{projectPath}\"", "/t:GenerateRestoreGraphFile", $"/p:RestoreGraphOutputPath=\"{tmpFilePath}\"" }; // Blocking run var runStatus = _dotNetRunner.Run(Path.GetDirectoryName(projectPath), arguments); if (!runStatus.IsSuccess) { throw new Exception( $"Unable to process the project `{projectPath}. Are you sure this is a valid .csproj/.sln?" + "\r\n\r\nHere is the full error message returned from the Microsoft Build Engine:\r\n\r\n" + runStatus.Output); } var dependencyGraphText = File.ReadAllText(tmpFilePath); tmpFile.Delete(); return(new DependencyGraphSpec(JsonConvert.DeserializeObject <JObject>(dependencyGraphText))); }
public RunStatus AddPackage(string projectPath, string packageName, string frameworkName, NuGetVersion version) { string projectName = _fileSystem.Path.GetFileName(projectPath); string[] arguments = new[] { "add", $"\"{projectName}\"", "package", packageName, "-v", version.ToString(), "-f", $"\"{frameworkName}\"" }; return(_dotNetRunner.Run(_fileSystem.Path.GetDirectoryName(projectPath), arguments)); }
public DependencyGraphSpec GenerateDependencyGraph(string projectPath) { if (string.Equals(_fileSystem.Path.GetExtension(projectPath), ".sln", StringComparison.OrdinalIgnoreCase)) { return(GenerateSolutionDependencyGraph(projectPath)); } string dgOutput = _fileSystem.Path.Combine(_fileSystem.Path.GetTempPath(), _fileSystem.Path.GetTempFileName()); string[] arguments = { "msbuild", $"\"{projectPath}\"", "/t:GenerateRestoreGraphFile", $"/p:RestoreGraphOutputPath=\"{dgOutput}\"" }; var runStatus = _dotNetRunner.Run(_fileSystem.Path.GetDirectoryName(projectPath), arguments); if (runStatus.IsSuccess) { string dependencyGraphText = _fileSystem.File.ReadAllText(dgOutput); return(new DependencyGraphSpec(JsonConvert.DeserializeObject <JObject>(dependencyGraphText))); } else { throw new CommandValidationException($"Unable to process the project `{projectPath}. Are you sure this is a valid .NET Core or .NET Standard project type?" + $"\r\n\r\nHere is the full error message returned from the Microsoft Build Engine:\r\n\r\n" + runStatus.Output); } }
public RunStatus AddPackage(string projectPath, string packageName, string frameworkName, NuGetVersion version, bool noRestore) { string projectName = _fileSystem.Path.GetFileName(projectPath); List <string> arguments = new List <string> { "add", $"\"{projectName}\"", "package", packageName, "-v", version.ToString(), "-f", $"\"{frameworkName}\"" }; if (noRestore) { arguments.Add("--no-restore"); } return(_dotNetRunner.Run(_fileSystem.Path.GetDirectoryName(projectPath), arguments.ToArray())); }
public DependencyGraphSpec GenerateDependencyGraph(string projectPath) { string dgOutput = _fileSystem.Path.Combine(_fileSystem.Path.GetTempPath(), _fileSystem.Path.GetTempFileName()); string[] arguments = new[] { "msbuild", projectPath, "/t:GenerateRestoreGraphFile", $"/p:RestoreGraphOutputPath={dgOutput}" }; var runStatus = _dotNetRunner.Run(_fileSystem.Path.GetDirectoryName(projectPath), arguments); if (runStatus.IsSuccess) { string dependencyGraphText = _fileSystem.File.ReadAllText(dgOutput); return(new DependencyGraphSpec(JsonConvert.DeserializeObject <JObject>(dependencyGraphText))); } return(null); }
public DependencyGraphSpec GenerateDependencyGraph(string projectPath) { var dgOutput = _fileSystem.Path.Combine(_fileSystem.Path.GetTempPath(), _fileSystem.Path.GetTempFileName()); string[] arguments = { "msbuild", $"\"{projectPath}\"", "/t:Restore,GenerateRestoreGraphFile", $"/p:RestoreGraphOutputPath=\"{dgOutput}\"" }; var runStatus = _dotNetRunner.Run(_fileSystem.Path.GetDirectoryName(projectPath), arguments); if (runStatus.IsSuccess) { var dependencyGraphText = _fileSystem.File.ReadAllText(dgOutput); return(new DependencyGraphSpec(JsonConvert.DeserializeObject <JObject>(dependencyGraphText))); } throw new CommandValidationException($"Unable to process the project `{projectPath}. Are you sure this is a valid .NET Core or .NET Standard project type?" + $"{Environment.NewLine}{Environment.NewLine}Here is the full error message returned from the Microsoft Build Engine:{Environment.NewLine}{Environment.NewLine}{runStatus.Output}"); }
public RunStatus Restore(string projectPath) { string[] arguments = new[] { "restore", $"\"{projectPath}\"" }; return(_dotNetRunner.Run(_fileSystem.Path.GetDirectoryName(projectPath), arguments)); }