public void InitialBuild(bool fullFramework, string projectPath, string solutionPath) { _logger.LogDebug("Started initial build using {0}", fullFramework ? "msbuild.exe" : "dotnet build"); projectPath = Path.GetDirectoryName(projectPath); ProcessResult result; if (fullFramework) { if (string.IsNullOrEmpty(solutionPath)) { throw new StrykerInputException("Stryker could not build your project as no solution file was presented. Please pass the solution path using --solution-path \"..\\my_solution.sln\""); } solutionPath = Path.GetFullPath(solutionPath); var solutionDir = Path.GetDirectoryName(solutionPath); var msbuildPath = new MsBuildHelper().GetMsBuildPath(_processExecutor); // Build project with MSBuild.exe result = _processExecutor.Start(solutionDir, msbuildPath, $"\"{solutionPath}\""); CheckBuildResult(result, msbuildPath, $"\"{solutionPath}\""); } else { var buildPath = !string.IsNullOrEmpty(solutionPath) ? solutionPath : Path.GetFileName(projectPath); _logger.LogDebug("Initial build using path: {buildPath}", buildPath); // Build with dotnet build result = _processExecutor.Start(projectPath, "dotnet", $"build \"{buildPath}\""); CheckBuildResult(result, "dotnet build", $"\"{Path.GetFileName(projectPath)}\""); } }
public void InitialBuild(bool fullFramework, string projectPath, string solutionPath, string projectName) { _logger.LogInformation("Started initial build using {0}", fullFramework ? "msbuild.exe" : "dotnet build"); ProcessResult result = null; if (fullFramework) { solutionPath = Path.GetFullPath(solutionPath); string solutionDir = Path.GetDirectoryName(solutionPath); var msbuildPath = new MsBuildHelper().GetMsBuildPath(_processExecutor); // Build project with MSBuild.exe result = _processExecutor.Start(solutionDir, msbuildPath, $"\"{solutionPath}\""); } else { // Build with dotnet build result = _processExecutor.Start(projectPath, "dotnet", $"build \"{projectName}\""); } _logger.LogDebug("Initial build output {0}", result.Output); if (result.ExitCode != 0) { // Initial build failed throw new StrykerInputException(result.Output, "Initial build of targeted project failed. Please make targeted project buildable. See above message for build output."); } _logger.LogInformation("Initial build successful"); }
public void InitialBuild(bool fullFramework, string projectPath, string solutionPath) { _logger.LogDebug("Started initial build using {0}", fullFramework ? "msbuild.exe" : "dotnet build"); projectPath = Path.GetDirectoryName(projectPath); ProcessResult result; if (fullFramework) { if (string.IsNullOrEmpty(solutionPath)) { throw new StrykerInputException("Stryker could not build your project as no solution file was presented. Please pass the solution path using --solution-path \"..\\my_solution.sln\""); } solutionPath = Path.GetFullPath(solutionPath); string solutionDir = Path.GetDirectoryName(solutionPath); var msbuildPath = new MsBuildHelper().GetMsBuildPath(_processExecutor); // Build project with MSBuild.exe result = _processExecutor.Start(solutionDir, msbuildPath, $"\"{solutionPath}\""); } else { // Build with dotnet build result = _processExecutor.Start(projectPath, "dotnet", $"build \"{Path.GetFileName(projectPath)}\""); } _logger.LogDebug("Initial build output {0}", result.Output); if (result.ExitCode != 0) { // Initial build failed throw new StrykerInputException(result.Output, "Initial build of targeted project failed. Please make targeted project buildable. See above message for build output."); } _logger.LogDebug("Initial build successful"); }
public void InitialBuild(bool fullFramework, string projectPath, string solutionPath, string projectName) { _logger.LogInformation("Started initial build using {0}", fullFramework ? "msbuild.exe" : "dotnet build"); ProcessResult result = null; if (fullFramework) { solutionPath = Path.GetFullPath(solutionPath); string solutionDir = Path.GetDirectoryName(solutionPath); var msbuildPath = new MsBuildHelper().GetMsBuildPath(_processExecutor); // Build project with MSBuild.exe result = _processExecutor.Start(solutionDir, msbuildPath, $"\"{solutionPath}\""); } else { if (!string.IsNullOrWhiteSpace(solutionPath)) { _logger.LogWarning("Stryker is running on a .net core project but a solution path was provided. The solution path option is only needed on .net framework projects and can be removed. Please update your stryker options."); } // Build with dotnet build result = _processExecutor.Start(projectPath, "dotnet", $"build \"{projectName}\""); } _logger.LogDebug("Initial build output {0}", result.Output); if (result.ExitCode != 0) { // Initial build failed throw new StrykerInputException(result.Output, "Initial build of targeted project failed. Please make targeted project buildable. See above message for build output."); } _logger.LogInformation("Initial build successful"); }
private void CompileGeneratedCode(string projectPath, IEnumerable <string> files, string language) { List <string> referenceAssemblies = MsBuildHelper.GetReferenceAssemblies(projectPath); if (language == "C#") { CompilerHelper.CompileCSharpSourceFromFiles(files, referenceAssemblies, documentationFile: null); } else { CompilerHelper.CompileVisualBasicSourceFromFiles(files, referenceAssemblies, "TheRootNamespace", documentationFile: null); } }
public void RestorePackages(string solutionPath) { _logger.LogInformation("Restoring nuget packages using {0}", "nuget.exe"); if (string.IsNullOrWhiteSpace(solutionPath)) { throw new StrykerInputException("Solution path is required on .net framework projects. Please provide your solution path using --solution-path ..."); } solutionPath = Path.GetFullPath(solutionPath); string solutionDir = Path.GetDirectoryName(solutionPath); // Validate nuget.exe is installed and included in path var nugetWhereExeResult = _processExecutor.Start(solutionDir, "where.exe", "nuget.exe"); if (!nugetWhereExeResult.Output.ToLowerInvariant().Contains("nuget.exe")) { throw new StrykerInputException("Nuget.exe should be installed to restore .net framework nuget packages. Install nuget.exe and make sure it's included in your path."); } // Get the first nuget.exe path from the where.exe output var nugetPath = nugetWhereExeResult.Output.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault().Trim(); // Locate MSBuild.exe var msbuildPath = new MsBuildHelper().GetMsBuildPath(_processExecutor); var msBuildVersionOutput = _processExecutor.Start(solutionDir, msbuildPath, "-version /nologo"); if (msBuildVersionOutput.ExitCode != 0) { _logger.LogError("Unable to detect msbuild version"); } var msBuildVersion = msBuildVersionOutput.Output.Trim(); _logger.LogDebug("Auto detected msbuild version {0} at: {1}", msBuildVersion, msbuildPath); // Restore packages using nuget.exe var nugetRestoreCommand = string.Format("restore \"{0}\" -MsBuildVersion \"{1}\"", solutionPath, msBuildVersion); _logger.LogDebug("Restoring packages using command: {0} {1}", nugetPath, nugetRestoreCommand); try { var nugetRestoreResult = _processExecutor.Start(solutionDir, nugetPath, nugetRestoreCommand, timeoutMs: 120000); if (nugetRestoreResult.ExitCode != 0) { throw new StrykerInputException("Nuget.exe failed to restore packages for your solution. Please review your nuget setup.", nugetRestoreResult.Output); } _logger.LogDebug("Restored packages using nuget.exe, output: {0}", nugetRestoreResult.Output); } catch (OperationCanceledException) { throw new StrykerInputException("Nuget.exe failed to restore packages for your solution. Please review your nuget setup."); } }