VSTest.Console.Exe does not execute tests - visual-studio-2012

vstest.console.exe does not execute my tests.
var testProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = #"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe",
Arguments = _testDllPath,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
I receive the following output when executing the commandline:
Microsoft (R) Test Execution Command Line Tool Version 11.0.60315.1Copyright (c) Microsoft Corporation. All rights reserved.
NOTE: Tests do get executed when I run MSTest:
var testProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = #"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe",
Arguments = string.Format(#"/testcontainer:""{0}"" /resultsfile:""{1}""", _testDllPath, _resultsDirectoryPath),
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
However, running mstest on the commandlline results in one of my tests failing even though I cannot reproduce the test failure in VS2012 TestExplorer.

I needed to surround my test dll path with quotes:
var testProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = #"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe",
Arguments = _testDllPath.Replace(_testDllPath, '"' + _testDllPath + '"'),
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};

Related

Azure Linux App Service with .Net Core Stack. Unable to use NodeJS

I am hosting a .NET Core Application on MS Azure (on a Linux Service Plan) and I want to run some NodeJS code in the .NET Core Application. I did this a while ago on a Windows Service Plan, there it was working. Now I am trying with a Linux Plan and it is not working.
First I was trying to use "Jering.Javascript.NodeJS" and then also "INodeServices" from Microsoft (which is obsolete). But "node" was not found. I also tried to start directly a Process (Code below), but also not working. "node" is not found.
var proc = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = "node",
Arguments = " -v",
RedirectStandardOutput = true
}
};
result += "RUN: " + proc.StartInfo.FileName;
proc.Start();
var reader = proc.StandardOutput;
NodeJS is installed on the server and also the command works there but it seems that the .NET Core app is hosted as docker and does not have any access outside to run NodeJS. Image
I found a useful information here.
The problem is that Node is not present in the container so it is
necessary to have a script to install and start it before starting the
app itself.
Reproduceļ¼š
Here is my script:
//using System.Diagnostics;
ProcessStartInfo startinfo = new ProcessStartInfo();
startinfo.FileName = "bash";
//startinfo.FileName = "/etc/opt/nodejs/14.15.0/bin/node"; //it's no use even node package located here.
Process process = new Process();
process.StartInfo = startinfo;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
//install and start nodejs
process.StandardInput.WriteLine("apt-get install curl");
process.StandardInput.WriteLine("curl -sL https://deb.nodesource.com/setup_12.x | bash");
process.StandardInput.WriteLine("apt-get install -y nodejs");
//Run "node -v"
process.StandardInput.WriteLine("node -v");
string line = string.Empty;
while (!process.StandardOutput.EndOfStream)
{
line = process.StandardOutput.ReadLine();
_logger.LogInformation(line);
}
process.WaitForExit();
return string.Empty;
It works on my .net Core app based on Linux.
I think I found a better solution ;)
In an app service you can mount a storage. In my case I mounted a storage, which contains the nodeJS lib.
Azure Portal Screenshot
Now i can execute the following code:
string result = "";
var proc = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = "/externallibs/node/bin/node",
Arguments = " -v",
RedirectStandardOutput = true
}
};
result += "RUN: " + proc.StartInfo.FileName;
proc.Start();
var reader = proc.StandardOutput;
return result + reader.ReadToEnd();
You can create on azure portal an environment var named POST_BUILD_COMMAND with a command to fix your environment path.
Linux Service Plans runs on Oryx which is documented here
POST_BUILD_COMMAND=PATH=/usr/bin/node:$PATH

Trying to make SQL Profiler with TraceServer() C#

When debug program in line:
reader.InitializeAsReader(ci, #"D:\trace2\trace3.trc");
Exception: FileNotFoundException: Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\pfclnt.dll' or one of its dependencies. The system cannot find the file specified.
I try to add references from sql 2012 but still get the error
TraceServer reader = new TraceServer();
ConnectionInfoBase ci = new SqlConnectionInfo();
(ci as SqlConnectionInfo).ServerName = "localhost";
((SqlConnectionInfo)ci).UseIntegratedSecurity = true;
reader.InitializeAsReader(ci, #"D:\trace2\trace3.trc");
int eventNumber = 0;
while (reader.Read())
{
Console.Write("{0}\n", reader.GetValue(0).ToString());
eventNumber++;
if (eventNumber == 10) break;
}

how to run Visual Studio 'Command window' commands in c# code.

when i try to run the command 'Help.F1Help' from 'Command Window' (Visual Studio -> view-> other windows-> command Window) i can able to see the help file opening.
but when i try in c# with the below code nothing working. Any help would be appreciated
Code:-
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
//startInfo.UseShellExecute = true;
startInfo.Verb = "runas";
startInfo.FileName = "cmd.exe";
//startInfo.Arguments = "/C Help.LaunchinHelpViewer";
startInfo.Arguments = "/C Help.F1Help";
process.StartInfo = startInfo;
process.Start();

Cake NuGetPack Configuration

I'm trying to create a NuGet package using a Cake script:
var configuration = Argument("configuration", "Release");
var binDir = Directory("./bin") ;
var nugetPackageDir = Directory("./artifacts");
var nugetFilePaths = GetFiles("./**/*.csproj").Concat(GetFiles("./**/*.nuspec"));
var nuGetPackSettings = new NuGetPackSettings
{
BasePath = binDir + Directory(configuration),
OutputDirectory = nugetPackageDir
};
Task("NuGetPack")
.Does(() => NuGetPack(nugetFilePaths, nuGetPackSettings));
I get the following error:
========================================
NuGetPack
========================================
Executing task: NuGetPack
Attempting to build package from 'SomeProject.csproj'.
MSBuild auto-detection: using msbuild version '12.0' from 'C:\Program Files (x86)\MSBuild\12.0\bin'.
Unable to find 'C:\DEV\SomeProject\bin\Debug\SomeProject.dll'. Make sure the project has been built.
An error occured when executing task 'NuGetPack'.
Error: NuGet: Process returned an error (exit code 1).
It searches the assembly in the Debug folder instead of the Release folder.
How to set NuGetPack build configuration to Release in Cake?
You need to add the following command line argument -Prop Configuration=Release to the nuget pack command:
var nuGetPackSettings = new NuGetPackSettings
{
BasePath = binDir + Directory(configuration),
OutputDirectory = nugetPackageDir,
ArgumentCustomization = args => args.Append("-Prop Configuration=" + configuration)
};
It can be set using the Properties property:
var nuGetPackSettings = new NuGetPackSettings
{
BasePath = binDir + Directory(configuration),
OutputDirectory = nugetPackageDir,
Properties = new Dictionary<string, string>
{
{ "Configuration", configuration }
}
};

How to call C .exe file from C#?

I have an .exe file which was written in C. It is a command line application. I want give command line and also get correspond output in this application through a C# application.
How do I invoke the command and get the output from C#?
You could use the Process.Start method:
class Program
{
static void Main()
{
var psi = new ProcessStartInfo
{
FileName = #"c:\work\test.exe",
Arguments = #"param1 param2",
UseShellExecute = false,
RedirectStandardOutput = true,
};
var process = Process.Start(psi);
if (process.WaitForExit((int)TimeSpan.FromSeconds(10).TotalMilliseconds))
{
var result = process.StandardOutput.ReadToEnd();
Console.WriteLine(result);
}
}
}
You need to use the Process.Start method.
You supply it with the name of your process and any command line arguments and it will run the executable.
You can capture any output which you can then process in your C# application.

Resources