nunit won't redirect console output - nunit

I'm using nunit 2.5 and when I try the following
nunit-console.exe "C:\Work\classLib\Data.Tests\bin\Debug\data.tests.dll" /out:output.txt
it still displays it on the console.
I can redirect ALL output by > output.txt of the whole command, but this doesn't work running in the context of NANT.
Any ideas?
EDIT: The NANT command is
<exec program="C:\Program Files\NUnit 2.5\bin\net-2.0\nunit-console.exe
" commandline="C:\Work\classLib\Data.Tests\bin\Debug\Data.Tests.dll
" workingdir="C:\Work\classLib\Data.Tests\bin\Debug" output="output.txt" />
Cheers
Duncan

/out=output.txt appears to be saving only items written out using Console.Writeline
The details of the test run are stored in an xml file, which you can redirect using the /xml switch.

Related

Run a powershell script from TFSBuild.Proj file

I have added a code piece in my MS build file to run a powershell script. But while building it gives me a error error MSB4067: The element "Exec" beneath element "Project" is unrecognized.
Below is the code:
<PropertyGroup>
<PowerShellExe Condition=" '$(PowerShellExe)'=='' ">
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe
</PowerShellExe>
<ScriptLocation Condition=" '$(ScriptLocation)'=='' ">
D:\Synopsis\SynopsysDetect.ps1
</ScriptLocation>
</PropertyGroup>
<Exec Command="%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -ExecutionPolicy Unrestricted -command ^"^& {^&&apos;D:\Synopsis\SynopsysDetect.ps1&apos;} ^"" />
Not sure if the issue is with code or have I placed the code piece at the wrong place. Any help would be appreciated. Thanks.
Moving the above piece of code completely into the "Target" tag fixed the issue.
MSB4067 is "UnrecognizedChildElement". It means that the element containing this line doesn't "know" the exec command. Since the tag </PropertyGroup> is above your line, I have no idea how your structure look like. Please share more of the file blurring confidential parts.
Also see that TFS has a "Run powershell step" that you can use.

NUnit console - when attempting to redirect output /err seems to have no effect

I've got an Nunit project with some tests and they all run as expected. Now I want to incorporate the running of these scripts automatically.
I'm trying to use some of the redirect options so I can separate the test output, but whatever combination I use, all I seem to get is the standard TestResult.xml. I can use /out:AnnotherOut.txt OK, but I'm really interested in capturing the error output using /err:TestErrors.txt.
Command line is:
(NunitConsole App) /nologo /framework:net-4.0 MyTestProject.nunit /include=Integration /err=TestErrors.txt

How to write Command Prompt to a file AND to the screen at the same time

I am trying to write the output of a powershell command to a file. I have completed this:
powershell psake "Dev08, Deploy-things" >> C:\Deployments\DeploymentLog.txt 2>&1
This is dumping all the screen output to a File... GREAT!!
NOW, I also want it to dump to the console screen too. I have used the argument >CON
but it will dump everything to the screen, but not the file.
powershell psake "Dev08, Deploy-things" >> C:\Deployments\DeploymentLog.txt 2>&1 >CON
Maybe >CON is not the way to go.. Here is a test I am using:
dir > c:\test\directory.txt 2>&1
Anyone got an idea on how to do this?????
Instead of having CMD output the file, let your Powershell command do it with the Tee-Object cmdlt.
So for your case, something like:
powershell ^& "'C:\Program Files\7-Zip\7z.exe'" ^| tee B:\test.log
Note that the ^ is required before | so that way it passes it to Powershell and isn't interpreted literally.
Well, as it turns out, I cannot find anything that says you can write to 2 different outputs in Command Prompt. Once you redirect the output to a file, you redirect it. That's it. I cannot find any way to write to the screen as well using commands. SO, the solution that I used was to download "TailXP". Install it on the box and configure it to point to the file i am writing. This will read the file as it's being generated and write it to it's own console screen. It served our purpose and I have it all wrapped up in a .cmd file.

Why is PowerShell's $LastExitCode Variable Always 0 After a Failed Build with MSBuild?

I've noticed that when MSBuild fails, the value of the $LastExitCode variable is always 0. I'm on Windows 7, with MSBuild v4.0 and PowerShell 2.0. This is my MSBuild scritpt:
<?xml version="1.0" encoding="UTF-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="Fail">
<Target Name="Fail">
<Error />
</Target>
</Project>
When I run:
msbuild.exe MyProject.csproj
I can see in the output that MSBuild fails, but when I check $LastExitCode, it has a value of 0. Anyone know what might be going on?
I've tried setting $(ErrorActionPreference) to Stop, but that didn't work. I re-opened a new PowerShell window, that didn't work either.
I ran into a problem recently. It turned out some code in my profile that was updating $lastexitcode- the code was a custom prompt generator. Try running powershell without your profile with "powershell -noprofile" to see if the problem could be code in your profile.
Consider checking the value $?
Its false if $lastexitcode is nonzero... It works for me even when $lastexitcode did not.
$LASTEXITCODE is for win32 executables and $? is for PS commands. What is the value of %errorlevel% when you run the msbuild.exe from cmd?
Please read http://techibee.com/powershell/what-is-lastexitcode-and-in-powershell/1847 if you want to know more about difference between these two special variables.

Exception running powershell script from MSBuild Exec Task

i´m having a problem with MSBuild and Powershell. There is a PS-script that i want to execute within the MSBuild exec-Task.
The Problem: Running the Script direct from CMD works, but running the script within MSBuild I get an error.
Here the MSBuild script:
<Import Project="$(MSBuildExtensionsPath)\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks"/>
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<PropertyGroup>
<PathToSvnClient>C:\Program Files (x86)\CollabNet\Subversion Client</PathToSvnClient>
</PropertyGroup>
<ItemGroup>
<!-- set Folder to Svn Repository for svn info command-->
<SvnFolder Include="$(MSBuildProjectDirectory)\.."/>
</ItemGroup>
<Target Name="SvnInfo">
<!-- get SVN Revision and Repository Path -->
<SvnInfo LocalPath="%(SvnFolder.FullPath)" ToolPath="$(PathToSvnClient)">
<Output TaskParameter="Revision" PropertyName="Revision" />
<Output TaskParameter="RepositoryPath" PropertyName="RepositoryPath" />
</SvnInfo>
</Target>
<Target Name="SetProductVersion" DependsOnTargets="SvnInfo">
<Exec Command="powershell -file "Scripts\SetSth.ps1" -PARAM "$(PathToSth)" -SVNID $(Revision) -SVNFOLDER "$(RepositoryPath)"" LogStandardErrorAsError="true" ContinueOnError="false"/>
</Target>
The Command is executed exactly the same way as on CMD, but i get an exception from the Powershell Script for the SVNFOLDER param.
The Command that is executed looks like this:
powershell -file "Scripts\SetSth.ps1" -PARAM "C:\abc\cde" -SVNID 1234
-SVNFOLDER "https://domain/svn/rep/branches/xy%20(Build%2012)"
So from CMD it works, from within MSBuild not. I have no idea why. I hope you got an idea.
What about this approach playing with double and singles quotes:
<Target Name="SetProductVersion" DependsOnTargets="SvnInfo">
<Exec Command="powershell -command "& {Scripts\SetSth.ps1 -PARAM '$(PathToSth)' -SVNID '$(Revision)' -SVNFOLDER '$(RepositoryPath)'}"" LogStandardErrorAsError="true" ContinueOnError="false"/>
</Target>
Double check your paths.
Remember, powershell invoked in this way runs as Msbuild.exe under whatever user is executing the build. To msbuild.exe, a straight call to cmd.exe is going to start in the working directory where msbuild lives.
Assume -file "Scripts\SetSth.ps1" references C:\users\yourusername\Scripts\SetSth.ps1
So for you, calling cmd.exe and running that may work just fine, b/c your working directory is going to match C:\users\yourusername
For msbuild.exe, its likely unable to find that file, as its starting in something like *C:\Windows\Microsoft.NET\Framework\v4.0*
So it's looking for C:\Windows\Microsoft.NET\Framework\v4.0\Scripts\SetSth.ps1
I would try making that file path fully qualified. If that still doesn't work, have cmd.exe dump its results into a property and have msbuild log it. Then you can review the paths.