1

What I'm trying to achieve: I want to use a web application to run all the tests on my local windows PC.

I am using the following command:

c:/code/myRepo && dotnet test

I have tried the following command through run:

cmd.exe /C "c:/code/myRepo && dotnet test"

which runs successfully and all my tests pass.

I now want to run this from my .net Core application as so:

public static string RunCommand( string cmd)
{
    var escapedArgs = cmd.Replace("\"", "\\\"");

    var process = new Process()
    {
        StartInfo = new ProcessStartInfo
        {
            FileName = "cmd.exe",
            Arguments = $"/C \"{escapedArgs}\"",
            RedirectStandardOutput = true,
            UseShellExecute = false,
            CreateNoWindow = false,
        }
    };
    process.Start();
    string result = process.StandardOutput.ReadToEnd();
    process.WaitForExit();
    return result;
}

When I run the tests from here the tests run, but they all fail.

Question: there is something different between these 2 environments but I have no idea what, how /what can I check what might be different. I've tried the command:

set

and can't see anything obviously affecting the environment

6
  • You don't need cmd.exe to execute a command line application. Just run the application. cmd.exe /C starts another console with whatever arguments you passed to it. What you're trying to do will start one console that starts another console that finally runs dotnet with the arguments you provided. Just start dotnet instead Commented Apr 12, 2019 at 11:47
  • As this probably duplicate question shows, all you need to do is call dotnet as the application and pass the option or path to the dll. Just make sure it's run on the correct working directory. You could even use Process.Start("dotnet","test") if your program is in the correct working directory Commented Apr 12, 2019 at 11:49
  • thanks @PanagiotisKanavos. The program i am running is in a different scope to the tests. My application is programmatically running the tests from many other solutions that are not linked Commented Apr 12, 2019 at 12:44
  • That sounds like an XY problem - how to test multiple projects. As for the current question, you still don't need cmd. Either add the path to the project file as the last of the arguments, or set the WorkingDirectory in ProcessStartInfo to the folder where the project file is Commented Apr 12, 2019 at 12:47
  • As for the actual problem, you could use a build script eg written in FAKE or CAKE to find and run all tests. You could even use a Powershell or CMD script to just find all *.csproj files under a root folder and pass them as arguments to dotnet run. Commented Apr 12, 2019 at 12:51

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.