i am getting an error from a bat file saying directory or filename not right but i can not see why as the directory or file points correctly

Hi,


I am running below .bat file via team city but it is throwing an error as below could you see why would i get that and how i can fix this? thanks

SCRIPT;

"C:\Source\SS.SpreadsMarketManagement\SPIN.MarketManagement.IntegrationTests\SPIN.MarketManagement.IntegrationTests\NUnit-2.6.4\bin\nunit-console.exe" /labels /out=TestResult.txt /xml=TestResult.xml /framework=net-4.0 bin\Debug\SPIN.MarketManagement.IntegrationTests.dll
 
"C:\Source\SS.SpreadsMarketManagement\SPIN.MarketManagement.IntegrationTests\packages\SpecFlow.1.9.0\tools\specflow.exe" nunitexecutionreport SPIN.MarketManagement.IntegrationTests.csproj
 
IF NOT EXIST TestResult.xml GOTO FAIL
IF NOT EXIST TestResult.html GOTO FAIL
EXIT
 
:FAIL
echo ##teamcity[buildStatus status='FAILURE']
EXIT /B 1

Open in new window


ERROR as below log shows;

Step 3/6: Run Specflow (Command Line)
[17:19:59][Step 3/6] Starting: C:\BuildAgent\work\d36e2f25629d2214\SPIN.MarketManagement.IntegrationTests\SPIN.MarketManagement.IntegrationTests\RunSpecFlow.bat
[17:19:59][Step 3/6] in directory: C:\BuildAgent\work\d36e2f25629d2214\SPIN.MarketManagement.IntegrationTests
[17:19:59][Step 3/6] 
[17:19:59][Step 3/6] C:\BuildAgent\work\d36e2f25629d2214\SPIN.MarketManagement.IntegrationTests>"C:\Source\SS.SpreadsMarketManagement\SPIN.MarketManagement.IntegrationTests\SPIN.MarketManagement.IntegrationTests\NUnit-2.6.4\bin\nunit-console.exe" /labels /out=TestResult.txt /xml=TestResult.xml /framework=net-4.0 bin\Debug\SPIN.MarketManagement.IntegrationTests.dll 
[17:19:59][Step 3/6] 
[17:19:59][Step 3/6] C:\BuildAgent\work\d36e2f25629d2214\SPIN.MarketManagement.IntegrationTests>"C:\Source\SS.SpreadsMarketManagement\SPIN.MarketManagement.IntegrationTests\packages\SpecFlow.1.9.0\tools\specflow.exe" nunitexecutionreport SPIN.MarketManagement.IntegrationTests.csproj 
[17:19:59][Step 3/6] The filename, directory name, or volume label syntax is incorrect.
[17:19:59][Step 3/6] The system cannot find the path specified.
[17:19:59][Step 3/6] 
[17:19:59][Step 3/6] C:\BuildAgent\work\d36e2f25629d2214\SPIN.MarketManagement.IntegrationTests>IF NOT EXIST TestResult.xml GOTO FAIL 
[17:19:59][Step 3/6] 
[17:19:59][Step 3/6] C:\BuildAgent\work\d36e2f25629d2214\SPIN.MarketManagement.IntegrationTests>echo 
[17:19:59][Step 3/6] ##teamcity[buildStatus status='FAILURE']
[17:19:59][Step 3/6]  
[17:19:59][Step 3/6] ##teamcity[buildStatus status='FAILURE']
[17:19:59][Step 3/6] 
[17:19:59][Step 3/6] C:\BuildAgent\work\d36e2f25629d2214\SPIN.MarketManagement.IntegrationTests>EXIT /B 1 
[17:19:59][Step 3/6] Process exited with code 1
[17:19:59][Step 3/6] Step Run Specflow (Command Line) failed

Open in new window

nicedoneAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pcelbaCommented:
Your script contains UTF-8 BOM at the beginning and it seems team city does not handle it properly. I would recommend to remove it. (Just save the BAT file in ASCII format.)

The biggest problem is the first line which seems to be too long for a BAT file. You should make it shorter, e.g.
C:
CD "\Source\SS.SpreadsMarketManagement\SPIN.MarketManagement.IntegrationTests\SPIN.MarketManagement.IntegrationTests\NUnit-2.6.4\bin"
nunit-console.exe /labels /out=TestResult.txt /xml=TestResult.xml /framework=net-4.0 bin\Debug\SPIN.MarketManagement.IntegrationTests.dll

Open in new window

Also, I cannot recognize whether the last parameter contains spaces. If yes then you should enclose it to double quotes.
If the /framework=net-4.0 is just a command line switch
and the rest  bin\Debug\SPIN.MarketManagement.IntegrationTests.dll  is additional parameter then you don't need additional double quotes. If everything belongs to the /framework switch then you will need dbl quotes.
nicedoneAuthor Commented:
Hi, Thanks for your comments but as you can see below i still run into problem as below, i have shortened the paths as you suggested, also i copied contents to notepad and then saved it to make it ASCII.

Step 3/6: Run Specflow (Command Line)
[10:19:43][Step 3/6] Starting: C:\BuildAgent\work\d36e2f25629d2214\SPIN.MarketManagement.IntegrationTests\SPIN.MarketManagement.IntegrationTests\SpecFlowRunner.bat
[10:19:43][Step 3/6] in directory: C:\BuildAgent\work\d36e2f25629d2214
[10:19:43][Step 3/6] 
[10:19:43][Step 3/6] C:\BuildAgent\work\d36e2f25629d2214>"C:\Source\NUnit-2.6.4\bin\nunit-console.exe" /out=TestResult.txt /xml=TestResult.xml /framework=net-4.0 SPIN.MarketManagement.IntegrationTests\bin\Debug\SPIN.MarketManagement.IntegrationTests.dll 
[10:19:43][Step 3/6] 
[10:19:43][Step 3/6] C:\BuildAgent\work\d36e2f25629d2214>"C:\Source\SpecFlow.1.9.0\tools\specflow.exe" nunitexecutionreport SPIN.MarketManagement.IntegrationTests.csproj 
[10:19:43][Step 3/6] 
[10:19:43][Step 3/6] C:\BuildAgent\work\d36e2f25629d2214>IF NOT EXIST TestResult.xml GOTO FAIL 
[10:19:43][Step 3/6] 
[10:19:43][Step 3/6] The system cannot find the path specified.
[10:19:43][Step 3/6] The system cannot find the path specified.
[10:19:43][Step 3/6] C:\BuildAgent\work\d36e2f25629d2214>echo 
[10:19:43][Step 3/6] ##teamcity[buildStatus status='FAILURE']
[10:19:43][Step 3/6]  
[10:19:43][Step 3/6] ##teamcity[buildStatus status='FAILURE']
[10:19:43][Step 3/6] 
[10:19:43][Step 3/6] C:\BuildAgent\work\d36e2f25629d2214>EXIT /B 1 
[10:19:43][Step 3/6] Process exited with code 1
[10:19:43][Step 3/6] Step Run Specflow (Command Line) failed

Open in new window



when i run command below from command prompt i am able to run the tests and produces the file  so i do not get what teamcity complaining about can not find the path? Also /framework=net-4.0 is just a command line switch
and the rest SPIN.MarketManagement.IntegrationTests\bin\Debug\SPIN.MarketManagement.IntegrationTests.dll  is additional parameter

C:\Source\NUnit-2.6.4\bin\nunit-console.exe
/labels /out=TestResult.txt /xml=TestResult.xml /framework=net-4.0 SPIN.MarketManagement.IntegrationTests\bin\Debug\SPIN
.MarketManagement.IntegrationTests.dll

Open in new window


So i really dont know what i can furhter do to fix this

i tried to use the tutorial from :

http://www.hamishgraham.net/post/TeamCity-SpecFlow-Integration.aspx

but unfortunately it does not work so far , what would you recommend as the command works from cmd, but not in teamcity somehow
pcelbaCommented:
"The system cannot find the path specified." means TeamCity cannot see the C:\Source\NUnit-2.6.4\bin\ path.

Does the user under which the TeamCity is running has all necessary access rights to the folder?

You could just create another batch or execute command  DIR C:\Source\NUnit-2.6.4\bin\ > diroutput.txt
and check the result.
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

nicedoneAuthor Commented:
I have changed the working directory and running the command

NUnit-2.6.4\bin\nunit-console.exe /labels /out=TestResult.txt /xml=TestResult.xml /framework=net-4.0 bin\Debug\SPIN.MarketManagement.IntegrationTests.dll

Open in new window


but i still get the same error from teamcity but cmd works fine.

what do you mean you could create another batch? can you guide me on that you mean create another bat file? but what difference will that make?

and also I ran DIR C:\Source\NUnit-2.6.4\bin\ > diroutput.txt  in cmd prompt, and it produced a file what do you mean should i create another batch file with the

DIR C:\Source\NUnit-2.6.4\bin\ > diroutput.txt  contents and see if it will produce the file is that what you mean?

sorry i am really newbie to teamcity and bat files as well so will need alittle more guidance
pcelbaCommented:
Batch = script, ie. file containing commands.

And you need to find WHY TeamCity cannot find the path used in your commands.

So first of all you have to check whether the path is visible for TeamCity and DIR command should help.

Instead of the
NUnit-2.6.4\bin\nunit-console.exe ... in your script simply write the DIR command:

DIR C:\Source\NUnit-2.6.4\bin\ > diroutput.txt

The  ">  diroutput.txt"  means the command output redirection into a file which you can view in Notepad later.
If you don't use output redirection then you cloud see the DIR command output in the TeamCity log.

Also does the TeamCity run on the same computer where the EXE resides and where the path exists?
nicedoneAuthor Commented:
here is the output, it is still failing to find the path interestingly as below so what would that mean?

Step 3/6: Run Specflow (Command Line)
[12:02:50][Step 3/6] Starting: C:\BuildAgent\work\d36e2f25629d2214\SPIN.MarketManagement.IntegrationTests\SPIN.MarketManagement.IntegrationTests\SpecFlowRunner.bat
[12:02:50][Step 3/6] in directory: C:\BuildAgent\work\d36e2f25629d2214\SPIN.MarketManagement.IntegrationTests\SPIN.MarketManagement.IntegrationTests
[12:02:50][Step 3/6] 
[12:02:50][Step 3/6] C:\BuildAgent\work\d36e2f25629d2214\SPIN.MarketManagement.IntegrationTests\SPIN.MarketManagement.IntegrationTests>DIR C:\Source\NUnit-2.6.4\bin\   1>diroutput.txt 
[12:02:50][Step 3/6] The system cannot find the path specified.
[12:02:50][Step 3/6] Process exited with code 1
[12:02:50][Step 3/6] Step Run Specflow (Command Line) failed

Open in new window

nicedoneAuthor Commented:
And that is the error I am getting, and if this is because of the rights ,it should have thrown rights error authentication error instead of the path error instead, is not it?
pcelbaCommented:
Try it without output redirection please.

Did you install TeamCity on your local computer or do you use some server?
pcelbaCommented:
If the access rights do not allow to see some folder then you cannot distinguish between missing file and file invisible due to the access rights.

So under what user runs the TeamCity on your PC?
nicedoneAuthor Commented:
it runs under my active directory name , which has system administrator role basically
nicedoneAuthor Commented:
i can see some people used paths like from teamviewer edit screen as below;

what does % % do in the paths ,should i add something like that what do yuo think?


Specs.Consumption\bin\%system.Configuration%\Specs.Consumption.dll
pcelbaCommented:
%% encloses predefined part of the path given by some OS variable.

E.g. %Windir%  means C:\Windows obviously.
nicedoneAuthor Commented:
so do yuo have any idea why i might not run the even the simplest script?
nicedoneAuthor Commented:
if i run it as not a batch file but

Commandline-->Custom script as below it runs but does not produce the file

C:\Windows\System32\cmd.exe /labels /out=TestResult.txt /xml=TestResult.xml /framework=net-4.0 bin\Debug\SPIN.MarketManagement.IntegrationTests.dll


if i use as below i get the path error as usual

NUnit-2.6.4\bin\nunit-console.exe /labels /out=TestResult.txt /xml=TestResult.xml /framework=net-4.0 bin\Debug\SPIN.MarketMan
agement.IntegrationTests.dll


but again if the cmd.exe completed without errors why does not it produce the files ,very weird
pcelbaCommented:
Do you have the path mentioned in the command on your PC?
C:\BuildAgent\work\d36e2f25629d2214\SPIN.MarketManagement.IntegrationTests\SPIN.MarketManagement.IntegrationTests

The DIR command cannot fail with the "The system cannot find the path specified." error because it just reports "The system cannot find the FILE specified.".

So the problem is in TeamCity and the error appears when TeamCity attempts to issue CD command.
pcelbaCommented:
"C:\Windows\System32\cmd.exe /labels /out=TestResult.txt /xml=TestResult.xml /framework=net-4.0 bin\Debug\SPIN.MarketManagement.IntegrationTests.dll"

This does not seem to be a correct command.  


"NUnit-2.6.4\bin\nunit-console.exe /labels /out=TestResult.txt /xml=TestResult.xml /framework=net-4.0 bin\Debug\SPIN.MarketManagement.IntegrationTests.dll"

This command contains some relative paths. Do they exist in your current path?
nicedoneAuthor Commented:
i have corrected the path issue , path was changed in the server so i corrected that

but now see the log below it looks as if it ran smoothly but at last it gives an error, and i can check on the server that the files are not created as well...what do you say?

Step 4/7: Run Specflow (Command Line)
[16:49:53][Step 4/7] Starting: C:\BuildAgent\work\d36e2f25629d2214\SPIN.MarketManagement.IntegrationTests\SPIN.MarketManagement.IntegrationTests\SpecFlowRunner.bat
[16:49:53][Step 4/7] in directory: C:\BuildAgent\work\d36e2f25629d2214\SPIN.MarketManagement.IntegrationTests\SPIN.MarketManagement.IntegrationTests
[16:49:53][Step 4/7] 
[16:49:53][Step 4/7] C:\BuildAgent\work\d36e2f25629d2214\SPIN.MarketManagement.IntegrationTests\SPIN.MarketManagement.IntegrationTests>C:\BuildAgent\work\d36e2f25629d2214\SPIN.MarketManagement.IntegrationTests\packages\NUnit.Runners.2.6.4\tools\nunit-console.exe /labels /out=TestResult.txt /xml=TestResult.xml /framework=net-4.0 bin\Debug\SPIN.MarketManagement.IntegrationTests.dll 
[16:49:53][Step 4/7] 
[16:49:53][Step 4/7] C:\BuildAgent\work\d36e2f25629d2214\SPIN.MarketManagement.IntegrationTests\SPIN.MarketManagement.IntegrationTests>C:\BuildAgent\work\d36e2f25629d2214\SPIN.MarketManagement.IntegrationTests\packages\SpecFlow.1.9.0\tools\specflow.exe nunitexecutionreport SPIN.MarketManagement.IntegrationTests.csproj 
[16:49:53][Step 4/7] Process exited with code -2146232576
[16:49:54][Step 4/7] Step Run Specflow (Command Line) failed

Open in new window

pcelbaCommented:
This means the specflow.exe returned exit code -2146232576 but TeamCity can continue when the exit code = 0.
So please check what means this exit code in the specflow.exe documentation.
nicedoneAuthor Commented:
Ok cheers ,I will check what that code means and let you know
nicedoneAuthor Commented:
Ok, i have changed the script to implement reporting in the following tutorial:

https://github.com/jole78/TeamCity.SpecFlow.Reporting/wiki/The-TSR-Module

teamcity runs the script but gets the "NUnit Output is missing" error which is down in the script ,could you shed light to why would it get that error and how i can fix it pls?

powershell script:
#-- Public Module Functions --#

function Invoke-TeamCitySpecFlowReport {
<#
.SYNOPSIS
Produces a report that can be shown in TeamCity.
.PARAMETER Categories
NUnit categories to execute
#>
param(
	[String[]]$Categories = @()
)
	
	try {
		Write-LogMessage $tsr.Messages.Begin		
	
		Remove-FileCache
		
		Invoke-NUnit $Categories
		Invoke-SpecFlow
		
		Publish-Artifacts		
		Add-FileCache
		
		Write-LogMessage $tsr.Messages.End
	
	} catch {
		throw $_.Exception
	}
}

function Set-Properties {
<#
.SYNOPSIS
Updates one or more properties with new values.
.PARAMETER Properties
The properties to set via @{ Key=Value; Key2=Value2 }.
#>
	param(
		[HashTable]$Properties = @{}
	)

	foreach ($key in $Properties.keys) {
		
		$value = $Properties.$key		
		$tsr[$key] = $value
		
		Write-LogMessage ("[TeamCity.SpecFlow.Reporting]: property [{0}] was updated with value [{1}]" -f $key, $value)
    }
}

#-- Private Module Functions --#

function Write-LogMessage{
	[CmdletBinding()]
	param(
		[Parameter(Position=0, ValueFromPipeline=$true)]
		[String]$Message
	)
	
	# TODO: we should streamline the use of write-verbose and write-debug instead
	if($tsr.Verbose) {
		Write-Host $Message
	}
}

function Write-TeamCityServiceMessage {
	param(
		[String]$MessageName,
		[String]$Value
	)
	# ##teamcity[<messageName> 'value']
	# ##teamcity[<messageName> name1='value1' name2='value2']
	
	$message = "##teamcity[{0} '{1}']" -f $MessageName, $Value
	Write-Host $message
}

function Invoke-SpecFlow {
	[CmdletBinding()]
	param()
	
	Write-LogMessage "=== Invoking specflow.exe ==="
	
	if($tsr.PathToSpecFlowExe) {
		$exe = $tsr.PathToSpecFlowExe
	} else {
		$exe = $(Get-SpecFlowPackage).Exe
	}	

	if(Test-Path $exe -PathType:Leaf) {
		try {	
			$ProjectInformation = Get-Project -ea:Stop
		
			$arguments = @()
			
			#https://github.com/techtalk/SpecFlow/wiki/Reporting
			$arguments += $tsr.SpecFlowReportType
			$arguments += $ProjectInformation.PathToProjectFile
			
			#$args += '/out:{0}' -f 'TestResult.html'
			
			$source = Get-FirstOrDefault '.\specflow.exe.config'
			if($source) {
				$destination = Split-Path -Parent $exe
				
				if((Test-Path (Join-Path $destination 'specflow.exe.config')) -eq $false) {
					Write-LogMessage $("copying file 'specflow.exe.config' to [{0}]" -f $destination)
					$specflow_exe_config = Copy-Item -Path $source.FullName -Destination $destination -PassThru
				}
			}
			
			Invoke-Executable $exe $arguments -ea:Stop
			
			if($specflow_exe_config) {
				Delete-File $specflow_exe_config.FullName
			}
			
			# TODO: the name of the file needs to be configurable
			$html_report = Get-FirstOrDefault '.\TestResult.html'
			if($html_report) {
				$tsr.GeneratedFiles.HtmlReport = $html_report
			} else {
				Write-Error "SpecFlow 'HtmlReport' output is missing"
			}
			
			
		} catch {
			throw "An error occurred while executing specflow.exe: " + $_
		} 
	} else {
		throw "failed to find 'specflow.exe' at location '$exe'"
	}
}

function Invoke-NUnit {
	[CmdletBinding()]
	param (
		[String[]] $Categories = @()
	)
	Write-LogMessage "=== Invoking nunit.console.exe ==="
	
	if($tsr.PathToNUnitConsoleExe) {
		$exe = $tsr.PathToNUnitConsoleExe
	} else {
		$exe = $(Get-NUnitPackage).Exe
	}
	
	if(Test-Path $exe -PathType:Leaf) {
		try {
			$arguments = @()
			
			$ProjectInformation = Get-Project -ea:Stop
			
			if($ProjectInformation.PathToAssembly) {
				$arguments += $ProjectInformation.PathToAssembly
			} else {
				$arguments += $ProjectInformation.PathToProjectFile
			}
			$arguments += "/labels"
			$arguments += "/out=TestResult.txt"
			$arguments += "/xml=TestResult.xml"
			if($Categories) {
				$arguments += "/include:$($Categories -join '|')"
			}
			
			Invoke-Executable $exe $arguments -ea:Stop
			
			$output = Get-FirstOrDefault .\TestResult.txt
			$result = Get-FirstOrDefault .\TestResult.xml
			if($output) {
				$tsr.GeneratedFiles.NUnitOutput = $output
			} else {
				Write-Error "NUnit output is missing"				
			}
			
			if($result) {
				$tsr.GeneratedFiles.NUnitReport = $result
			} else {
				Write-Error "NUnit report is missing"
			}	
			
		} catch {
			throw "error when executing nunit-console.exe: " + $_
		}
	} else {
		throw "failed to find 'nunit-console.exe' at location '$exe'"
	}	
}

function Invoke-Executable {
	[CmdletBinding()]
	param(
		[Parameter(Position=0)]
		[String]$Executable,
		[Parameter(Position=1)]
		[String[]]$Parameters
	)
	
	Write-Verbose $("Invoking '{0}'" -f $Executable)
	$Parameters | % {Write-Verbose $_} -Begin {Write-Verbose $("using arguments:")}
	
	& $Executable $Parameters | Out-String | Write-LogMessage
}

function Get-Project {
	[CmdletBinding()]
	param()
	
	$project_file = Get-FirstOrDefault '.\*.*proj'
	if($project_file -eq $null){
		Write-Error "Failed to find the project file"
		return
	}
	
	$out = @{PathToProjectFile = $project_file.FullName}
	
	$assembly_name = '{0}.dll' -f $project_file.BaseName	
	$assembly_path = 'bin' | Join-Path -ChildPath $tsr.Configuration | Join-Path -ChildPath $assembly_name
	
	$assembly_file = Get-FirstOrDefault $(Join-Path . $assembly_path)
	if($assembly_file) {
		$out.PathToAssembly = $assembly_file.FullName
	}	

	return $out;
}

function Get-NUnitPackage {
	
	$tools = Join-Path $(Get-Package "NUnit.Runners").Path 'tools'	
	$nunit_console_exe = Get-Item $(Join-Path $tools 'nunit-console.exe')

	return @{
		Exe = $nunit_console_exe.FullName
	}
}

function Get-SpecFlowPackage {
	
	$tools = Join-Path $(Get-Package "SpecFlow").Path 'tools'	
	$specflow_exe = Get-Item $(Join-Path $tools 'specflow.exe')

	return @{
		Exe = $specflow_exe.FullName		
	}
}

function Get-PackagesFolder {
	[CmdletBinding()]
	param()
	
	if( (Split-Path $tsr.PathToPackagesFolder -Leaf) -eq 'Packages' ){
		$PackagesFolderPath = $tsr.PathToPackagesFolder
	} else {
		$PackagesFolderPath = Join-Path $tsr.PathToPackagesFolder 'Packages'
	}	
	
	$result = Get-FirstOrDefault $PackagesFolderPath
	if($result -eq $null) {
		$msg = "Failed to find the 'packages' folder at location: '{0}'." -f $PackagesFolderPath
		Write-Error $msg
		return
	}
	
	return $result
}

function Get-Package {
	[CmdletBinding()]
	param(
		[string]$Name
	)
	
	$PackagesFolder = Get-PackagesFolder
	$results = Get-ChildItem $PackagesFolder | Where-Object {
		$_ -match "^($Name){1}(\.)?(\d+\.{0,1})*$"
	}
	
	if($results -eq $null) {
		Write-Error $("failed to find package '{0}' at location: '{1}'" -f $Name, $PackagesFolder.FullName)
		return
	}
	
	$results | ForEach-Object {
		Write-Debug $_.Name
	} -Begin {Write-Debug $("found {0} packages:" -f $results.Count)}
	
	#TODO: handle package versions (this only gets the latest one)
	$package = $results | Sort-Object -Property Name -Descending | Select-Object -First 1
	$version = $package.Name -split "$Name."
	
	$result = @{
		Version = if($version.Length -gt 1) {$version[1]} else {"n/a"}
		Path = $package.FullName
	}
	
	Write-Debug $("package: {0}; version: {1}" -f $result.Path, $result.Version)
	
	return $result

}

function Remove-FileCache{	
	
	if($tsr.CleanEnvironment) {
		
		$x = Get-Content .\files.generated -WarningAction:SilentlyContinue -ErrorAction:SilentlyContinue
		if($x) {
			$x -split ';' | % { Delete-File $_ }
		}
	}
}

function Add-FileCache {
	$($tsr.GeneratedFiles.GetEnumerator() |  % { 
		$_.Value.FullName}) -join ';' | 
		Set-Content .\files.generated | Out-Null
}

function Get-FirstOrDefault {
	param(
		[String]$Path
	)
	
	return Get-Item -Path $Path -ErrorAction:SilentlyContinue | Select-Object -First 1	
}

function Publish-Artifacts {
	
	if($tsr.GeneratedFiles.HtmlReport -and $tsr.PublishArtifacts) {
		Write-TeamCityServiceMessage 'publishArtifacts' $tsr.GeneratedFiles.HtmlReport.FullName		
	}
}

function Delete-File {
	[CmdletBinding()]
	param(
		[String]$Path
	)
	
	if($Path) {
		if(Test-Path $Path -PathType:Leaf) {
			Write-LogMessage $("deleting file [{0}]" -f $Path)
			Remove-Item $Path -ErrorAction:SilentlyContinue | Out-Null
		}
	}
}

function Set-PSConsole {
	try {
		$max = $host.UI.RawUI.MaxPhysicalWindowSize
		if($max) {
		$host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.Size(9999,9999)
		$host.UI.RawUI.WindowSize = New-Object System.Management.Automation.Host.Size($max.Width,$max.Height)
	}
	} catch {}

}

# default values
# override by Set-Properties @{Key=Value} outside of this script
$tsr = @{
	Configuration = 'Release'
	SpecFlowReportType = 'nunitexecutionreport'
	PublishArtifacts = $true
	CleanEnvironment = $true
	PathToPackagesFolder = '..\'
	Verbose = $true
	Messages = @{
		Begin = "##teamcity[blockOpened name='TeamCity.SpecFlow.Reporting']"
		End = "##teamcity[blockClosed name='TeamCity.SpecFlow.Reporting']"
	}
	GeneratedFiles = @{}
	Indentation = 0
	
}

if ($env:TEAMCITY_VERSION) {
	Set-PSConsole
}
Export-ModuleMember -Function Invoke-TeamCitySpecFlowReport, Set-Properties

Open in new window

pcelbaCommented:
This error means "No TestResult.txt file found in the current folder".

You may either change the path where PowerShell looks for the file (.\TestResult.txt) or generate the output in a different folder.

First of all check whether the output file exists or not.

You could also add more info to the log and study the log output. (See Write-LogMessage commands in the script.)
nicedoneAuthor Commented:
Hi, i just connected to the server to check if file even exists at all, but it does not exist no where, so that script is not able to create a file at the first place.But what i do not understand is that why would not it create the file ? i did everything as in the tutorial ?
nicedoneAuthor Commented:
because the error occurs in "Invoke-NUnit $Categories" call and i call this script in teamcity via

Import-Module .\TeamCity.Specflow.Reporting.psm1
Invoke-TeamCitySpecFlowReport

Can it be that $Categories are empty? could you check https://github.com/jole78/TeamCity.SpecFlow.Reporting/wiki/The-TSR-Module , what i am missing really? may be the tutorial is totally wrong,
pcelbaCommented:
Invoke-TeamCitySpecFlowReport  can contain one parameter:  $Categories which represents a string array containing parameters passed to the nunit-console.exe in the /include command line switch.

You may look to the Invoke-NUnit function in the script where you can see the string array parsing int o the /include command line switch.

So do you need the /include parameter? I would guess No.

The solution for you is more info in the log. Look at the  Invoke-NUnit function again and add more Write-LogMessage  calls which should contain all info necessary for debugging. You may use string expressions to store values of used variables to the log etc.

If you add following line
Write-LogMessage $exe
to the script then you may see the full path to the EXE file in the log.
Write-LogMessage "Current path: " + (Get-location)  should write the current path to the log.

You should also be able to execute the script directly from PowerShell on the server and see the results.
nicedoneAuthor Commented:
Ok, i have changed the methodology again to follow :https://jamesheppinstall.wordpress.com/tag/specflow/

and guess what finally i can generate the reports TestResult.xml and TestResult.txt

but when i run from the agent's cmd below command

specflow.exe nunitexecutionreport  xxx.csproj /testOutput:TestResult.txt /out:TestResult.html

I get the error ;

The element <ParameterGroup> beneath element <UsingTask> is
  unrecognized. I looked this up on google and there is a logical explanation which looks like the problem i am facing which states that;

"This can occur when your project is configured to use a recent version of NuGet but the MSBuild version being used by TeamCity is old and doesn't support some new NuGet features.

Change the MSBuild version and tools to at least 4.0"

Problem is i do not know how i can upgrade MSBuild version to at least 4.0 , how can i do that and where  should i do this in my VS build file and if so how or should i connect to the server to do this but how?
 or since i have the output files to be able to run specflow.exe should i take another way around?
pcelbaCommented:
The MSBUILD v4 is available e.g. here: http://www.microsoft.com/en-us/download/details.aspx?id=8279

You may also look for newer versions which were delivered together with newer Visual Studio versions or as a standalone downloads. (Search for MSBUILD download on the net.)

Install the MSBUILD into the server where TeamCity resides. It will also be necessary to tell TeamCity what MSBUILD to use in some configuration probably.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows OS

From novice to tech pro — start learning today.