Powershell error in Executing NUnit test - nunit

This might sound silly but I have been trying to execute a NUnit test using powershell script, had several attempts but no hope. is there different format or do I need to add a plugin?
Any help would be appriciated...
Command = "c:\Program Files\NUnit 2.4.8\bin\nunit-console.exe" /config=Release "C:\projects\IntegrationTests\IntegrationTests.nunit" 2>&1
Output as below:
PS C:\tests> "c:\Program Files\NUnit2.4.8\bin\nunit-console.exe" /config=Release
"C:\projects\IntegrationTests\IntegrationTests.nunit" 2>&1
You must provide a value expression on the right-hand side of the '/' operator.
At line:1 char:55 + "c:\Program Files\NUnit 2.4.8\bin\nunit-console.exe" / <<<<
config=Release "C:\projects\IntegrationTests\IntegrationTests.nunit" 2>&1
Thanks in Advance

You didn't put the part
/config=Release
inside your quoted command text.
Your command should probably look like
"c:\Program Files\NUnit 2.4.8\bin\nunit-console.exe /config=Release C:\projects\IntegrationTests\IntegrationTests.nunit" 2>&1
... i didn't check nunit-console.exe command line options, but i suppose you already tested if the nunit command works.

Sorry for the mess in the top dialog, proper code version below
& 'c:\Program Files\NUnit 2.4.\bin\nunitconsole.exe' /config=Release C:\Projects\IntegrationTests\IntegrationTests.nunit 2>&1

Related

Parameterising values causes error in powershell/msbuild command

I have a powershell script that in turn calls msbuild.exe and runs it with a solution value and a parameters argument. If i run this script by writing the line manually it runs as expected and builds the solution, however, due to the fact that this script is designed to build multiple solutions, the parameters, solution file path, and msbuild path are all passed as variables.
The line that i need to run looks like this:
& 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe' FooBar.sln "/t:rebuild" /p:PlatformTarget=AnyCPU /p:Configuration=Release /p:DeployOnBuild=true /p:CustomizablePublishDir=true /p:OutDir=F:\agent\_work\1\s\Deploy.Temp\Foo.Bar.Binaries\\ | Out-Host
And the way it is split into variables is as follows:
$1 = 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe'
$2 = 'FooBar.sln'
$3 = "/t:rebuild /p:PlatformTarget=AnyCPU /p:Configuration=Release /p:DeployOnBuild=true /p:CustomizablePublishDir=true /p:OutDir=F:\agent\_work\1\s\Deploy.Temp\Foo.Bar.Binaries\\ | Out-Host"
& $1 $2 $3
For context, to get these values we use an XML with many nodes with 3 properties on each.
The error i get when i run the paramaterised script is as follows:
Unhandled Exception: System.ArgumentException: The name "Foo_Bar:PlatformTarget=AnyCPU /p:Configuration=Release /p:DeployOnBuild=true /p:CustomizablePublishDir=true /p:OutDir=F:\agent\_work\1\s\Deploy.Temp\Foo.bar.Binaries\\ | Out-Host" contains
an invalid character ".".
Obviously this is due to how powershell is handling the strings but I can't figure out how to make it work.
| Out-Host should not be passed as part of an argument to an application - but that's not the issue here.
It seems to be a combination of combining all command line switches in a single string and having . anywhere in said argument - if I split the string into individual parts or replace your OutDir argument with a path that doesn't contain any ., msbuild proceeds to attempt to build the projects:
$msbuild = 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe'
$solution = 'FooBar.sln'
$arguments = "/t:rebuild /p:PlatformTarget=AnyCPU /p:Configuration=Release /p:DeployOnBuild=true /p:CustomizablePublishDir=true /p:OutDir=F:\agent\_work\1\s\Deploy.Temp\Foo.Bar.Binaries"
&$msbuild $solution $arguments.Split(' ') |Out-Host

unable to store output in a variable also not able to export result to any file using powershell

I have written following commands:
$env:Path += "C:\Program Files (x86)\Java\jre6\bin"
& "C:\Program Files (x86)\Java\jre6\bin\java" -version
I am trying to store output of second line in a variable but unable to do so. Also tried to export output in some file, that also did not work. Please assist.
java.exe might be writing the version output to stderr.
You can merge the error stream (2) into the standard output stream (1) with a stream redirection operator (>&) like so:
& "C:\program files(x86)\java\jre6\bin\java" -version 2>&1
PowerShell will try to be helpful and wrap the error output in an ErrorRecord. Since we just need the plaintext output, grab the Message value from the Exception wrapped by it:
$jversion = (& "C:\program files(x86)\java\jre6\bin\java" -version 2>&1).Exception.Message
$jversion will now contain one or more strings as output by java.exe
See the about_Redirection help file for more information

Run TextTransform.exe with args from Powershell

I want to run TextTransform.exe with the parameter args on my template while in PowerShell v3. Here are my variables and the options I tried. Note that it works with no '-a' parameters, but I need the args to run the template correctly.
$textTransformPath = "C:\Program Files (x86)\Common Files\Microsoft Shared\TextTemplating\14.0\TextTransform.exe"
$templateath = "$ProjectPath\TheTemplate.tt"
$textTransformParams = "-a !!TheParam!$TheValue"
#& "$textTransformPath" "$templatePath" <-- this runs, but no args!
# these don't work:
& "$textTransformPath" "$templatePath" $textTransformParams
& "$textTransformPath" "$templatePath" "$textTransformParams"
I don't know why this is so difficult, it seems like it should be really easy. If I type out this in the standard command line it works, which verifies the problem is with my PS syntax.
It never fails...one last search after almost giving up and found the answer:
Using $(SolutionDir) when running template via TextTransform.exe
The combo I apparently didn't try previously was:
& "$textTransformPath" "$templatePath" -a !!TheParam!$TheValue
Hope this helps someone else.

How do I change directory and run a file in that directory in powershell?

For example, i want to run cygwin.bat which is located in the c:/cygwin/ directory...
I tried the following but got an error:
cd c:/cygwin ./cygwin.bat
cd c:/cygwin and ./cygwin.bat are two different statements. You can execute them from the interactive console like so:
PS C:\> cd c:/cygwin
PS C:\cygwin> ./cygwin.bat
Or, if you really want to do it on the same line, then use a ; between them to indicate separate statements.
cd c:/cygwin ; ./cygwin.bat
best way is the way its always been
c:\cygwin\cygwin.bat
it's all you need to type
Try iex
$command = "cd c:/cywin"
iex $command

making archive with perl, when path is with spaces

How can I use path with spaces in a perl script, running Archive commend?
Saying this is the command with the path I need:
C:\\"Program Files"\\7-Zip\\7z.exe a d:\\views\\"My views" d:\\"Public view"
Someone has an idea?
If you use the system command with multiple arguments, each of them is passed unmodified to the invoked program:
system 'C:\Program Files\7-Zip\7z.exe', 'a',
'd:\views\My views', 'd:\Public view';
Although it isn't a Perl question, you can use this syntax
"C:\Program Files\7-Zip\7z.exe" a target.zip "c:\path with spaces\example.pdf"
And if you need to call from a perl script
$cmd = q!"C:\Program Files\7-Zip\7z.exe" a target.zip "c:\path with spaces\example.pdf"!;
system $cmd;