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)}\"");
            }
        }
Beispiel #2
0
        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");
        }
Beispiel #3
0
        private TestRunResult LaunchTestProcess(int?timeoutMs, IDictionary <string, string> envVars)
        {
            var result = _processExecutor.Start(
                _projectFile,
                "dotnet",
                @"vstest " + string.Join(" ", _testBinariesPaths),
                envVars,
                timeoutMs ?? 0);

            return(new TestRunResult(result.ExitCode == 0, result.Output));
        }
Beispiel #4
0
        private TestRunResult LaunchTestProcess(int?timeoutMs, IDictionary <string, string> envVars)
        {
            var result = _processExecutor.Start(
                _projectFile,
                "dotnet",
                "test --no-build --no-restore",
                envVars,
                timeoutMs ?? 0);

            return(new TestRunResult
            {
                Success = result.ExitCode == 0,
                ResultMessage = result.Output
            });
        }
Beispiel #5
0
        public string GetMsBuildPath(IProcessExecutor _processExecutor)
        {
            if (File.Exists(@"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe"))
            {
                return(@"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe");
            }
            // See if any MSBuild.exe can be found in visual studio installation folder
            foreach (string drive in Directory.GetLogicalDrives())
            {
                var visualStudioPath = Path.Combine(drive, "Program Files (x86)", "Microsoft Visual Studio");
                if (_fileSystem.Directory.Exists(visualStudioPath))
                {
                    _logger.LogDebug("Using vswhere.exe to locate msbuild");

                    var vsWherePath    = Path.Combine(visualStudioPath, "Installer", "vswhere.exe");
                    var vsWhereCommand = "-latest -requires Microsoft.Component.MSBuild -products * -find MSBuild\\**\\Bin\\MSBuild.exe";
                    var vsWhereResult  = _processExecutor.Start(visualStudioPath, vsWherePath, vsWhereCommand);

                    if (vsWhereResult.ExitCode == 0)
                    {
                        var msBuildPath = vsWhereResult.Output.Trim();
                        if (_fileSystem.File.Exists(msBuildPath))
                        {
                            _logger.LogDebug($"Msbuild executable path found at {msBuildPath}");

                            return(msBuildPath);
                        }
                    }
                }
            }

            // Else, find in default locations
            _logger.LogDebug("Unable to find msbuild using vswhere, using fallback locations");

            foreach (string possiblePath in fallbackLocations)
            {
                if (_fileSystem.File.Exists(possiblePath))
                {
                    return(possiblePath);
                }
            }
            throw new FileNotFoundException("MsBuild.exe could not be located. If you have MsBuild.exe available but still see this error please create an issue.");
        }