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
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 runsdotnet
with the arguments you provided. Just startdotnet
insteaddotnet
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 useProcess.Start("dotnet","test")
if your program is in the correct working directorycmd
. Either add the path to the project file as the last of the arguments, or set theWorkingDirectory
inProcessStartInfo
to the folder where the project file is*.csproj
files under a root folder and pass them as arguments todotnet run
.