How do I prevent ANT from closing batch file? - selenium

I have a .bat file to start selenium grid and I want it to stay open. I read the documentation on the ANT page but tried couple things but cant figure it out. This is what i have so far. It says it executed it but i cant tell.
<project>
<target name="runBatch">
<exec executable="cmd" fork="true" spawn="true">
<arg value="startGRID.bat"/>
</exec>
</target>
</project>
This is what startGRID.bat looks like when i run from command prompt.

so i got it to start but now i need it to start in another prompt.
<project>
<target name="startGRID">
<exec dir="." executable="cmd">
<arg value="/c"/>
<arg value="java -jar selenium-server-standalone-2.43.1.jar -role hub"/>
</exec>
</target>
</project>

Related

how to run msbuild script through cruise control

I am getting execption when i am running cruise control by iis or cctray and below is ccnet.config.i wanted to run my scrip through cruise control .please let me know how to relove this issue
<project name="Visteon">
<webURL>http://localhost/ccnet/</webURL>
<triggers>
<intervalTrigger seconds="110" buildCondition="ForceBuild" />
</triggers>
<tasks>
<msbuild>
<executable>C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
</executable>
<workingDirectory>E:\workingfolder_123</workingDirectory>
<buildArgs>E:\CCnet.xml /p:Configuration=release</buildArgs>
<timeout>1800</timeout>
<!-- 30 minutes -->
<logger>C:\Program Files\CruiseControl.NET\server\
ThoughtWorks.CruiseControl.MSBuild.dll</logger>
</msbuild>
</tasks>
</project>
</cruisecontrol>
my scripts is like this
<Target Name="GetSource">
<Message Text="Checking out trunk into $(SourceDirectory)" />
<SvnCheckout RepositoryPath="$(SvnCheckoutPath)"
LocalPath="$(CheckOutPath)"
UserName="aa"
Password="aa">
<Output TaskParameter="Revision" PropertyName="Revision" />
</SvnCheckout>
</Target>
<Target Name="Build" DependsOnTargets="GetSource;Clean;" />
<Target Name="Clean">
<!-- Clean, then rebuild entire solution -->
<MSBuild Projects="$(CheckOutPath)\SUPPLIER_SOFTWARE.sln" Targets="Clean;Rebuild" />
</Target>
Try using the CruiseControl Template below
<project name="MyCodeFolder Project" queue="MyQueue" queuePriority="1">
<tasks>
<msbuild>
<executable>C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable>
<workingDirectory>D:\Projects\MyCodeFolder</workingDirectory>
<projectFile>CCnet.xml</projectFile>
<buildArgs>/noconsolelogger /nologo /p:Configuration=Release</buildArgs>
<targets>
</targets>
<timeout>4800</timeout>
</msbuild>
</tasks>
As for the build script you will need the root to have Project node and set default target name main as the entry point. Please see below:
<Project DefaultTargets="Main">
<Target Name="Main">
//Do Something
</Target>
</Project>
You are missing project file tag e.g.
<projectFile>your_msbuild_script-here</projectFile>
http://build.sharpdevelop.net/ccnet/doc/CCNET/MsBuild%20Task.html
I'm also not sure what exactly E:\CCnet.xml is. If this is your msbuild file, put it
inside <projectFile/> and try again.
I hope that helps.

MSbuild 4.0 fail to compile .Net 3.5 project

I am using Msbuild 4.0.
In our project few solution are having .net 3.5 projects.
When i compile it through Visual studio it works. If i build the same using Msbuild it fails.
Following is the compilation issue:
error : Compilation failed. Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Exception from HRESULT: 0x80131515
Even i tried with changing
toolsversion to 3.5
through additionalproperties of item. [ I am using Msbuild task to build my solution]
Our Msbuild task looks like below.
<Target Name="BuildDotNETSolutions" Condition="'$(Group)' != ''" DependsOnTargets="Init;GetNextVersionNumber">
<!-- Complie solutions -->
<!-- Version property is useful for changing the Wix Msi version-->
<MSBuild Projects="#(Solution)" BuildInParallel="true"
Properties="Configuration=$(Configuration);PostbuildEvent=;Version=$(BuildNextVersionNumber)"
Condition="'%(Solution.Group)' == '$(Group)' And '%(Solution.Type)' == 'DotNET' And '%(Solution.IsRebuild)'=='$(IsRebuild)'">
<Output
TaskParameter="TargetOutputs"
ItemName="BuildOutputs" />
</MSBuild>
We are passing solutions through properties file like below
<Solution Include="$(Implementation)\MultiEvent.csproj;">
<Group>Event</Group>
<AdditionalProperties>
ReferencePath=$(Implementation)\References;
ToolsVersion=3.5;
</AdditionalProperties>
<IsRebuild>True</IsRebuild>
<Type>DotNET</Type>
</Solution>
I don't know if you happen to have any script-runner that runs MSBuild. Personnally, I'm using NAnt and everything is working fine. I've read (somewhere) that MSBuild sometimes do stupid things and by adding the property "TrackFileAccess" and set it to "false" helps a lot. In my case, it fixed the problem.
If it can be of any help, I've included my NAnt build task. I hope it can be useful to you.
<!--*******************************************************************************
Runs MSBuild to build the project solution
Arguments:
${MSBuild.exe}: Path to MSBuild.exe
${project.solution}: the solution name to build
${buildconfiguration}: The build configuration to trigger the build
${build.dir} : The directory where to put builded files
********************************************************************************-->
<target name="run.msbuild" description="Rebuilds a given solution file">
<echo message="Rebuilding Solution ${project.solution}" />
<echo>${MSBuild.exe}</echo>
<exec program="${MSBuild.exe}">
<arg value="${project.solution}"/>
<arg line="/property:SignAssembly=${project.sign},AssemblyOriginatorKeyFile=${project::get-base-directory()}\${project.signature.file}" />
<arg line="/property:OutDir=${build.dir}" />
<arg line="/property:TrackFileAccess=false" />
<arg line="/property:DebugType=${debug.type}" />
<arg line="/property:Platform="Any CPU"" />
<arg line="/nologo" />
<arg line="/verbosity:minimal" />
<arg line="/property:Configuration=${buildconfiguration}"/>
</exec>
in the case of a Development build, I set the following params :
<property name="buildconfiguration" value="Debug"/>
<property name="debug.type" value="full" />

How get exec task output with msbuild

I'm trying to get simple output by exec task with msbuild:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Test">
<Exec Command="echo test output">
<Output TaskParameter="Outputs" ItemName="Test1" />
</Exec>
<Exec Command="echo test output">
<Output TaskParameter="Outputs" PropertyName="Test2" />
</Exec>
<Message Text="----------------------------------------"/>
<Message Text="#(Test1)"/>
<Message Text="----------------------------------------"/>
<Message Text="$(Test2)"/>
<Message Text="----------------------------------------"/>
</Target>
</Project>
But get next output:
echo test output
test output
echo test output
test output
----------------------------------------
----------------------------------------
----------------------------------------
How can I get output by my script?
Good news everyone! You can now capture output from <Exec> as of .NET 4.5.
Like this:
<Exec ... ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
</Exec>
Simply:
Add ConsoleToMsBuild="true" to your <Exec> tag
Capture the output using the ConsoleOutput parameter in an <Output> tag
Finally!
Documentation here
If you want to capture output to an array-like structure and not to a plain string where the output lines are separated by a semicolon, use ItemName instead of PropertyName:
<Exec ... ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" ItemName="OutputOfExec" />
</Exec>
I've gotten to the point where I'm so frustrated with the limitations of MSBuild, and the stuff that's supposed to work but doesn't (at least not in every context), that pretty much anytime I need to do anything with MSBuild, I create a custom build task in C#.
If none of the other suggestions are working, then you could certainly do it that way.
You can pipe the output to a file so to speak, and read it back.
echo test output > somefile.txt

<msbuild> task or msbuild.exe with NAnt?

It looks like there are (at least) two options for getting nant to use csproj files: using the task of NAntContrib or using msbuild.exe directly (e.g., codecampserver). Am I reading this right, and if so, what is the advantage of using msbuild.exe over the NAntContrib task?
The NAntContrib assumes .NET Framework V2.0. If you want to use .NET 3.5, you'll need to call MsBuild.exe directly. As you upgrade to new versions of .NET, you need only modify the MSBuildPath property.
Here's an example:
<property name="MSBuildPath" value="C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe"/>
<target name="build">
<exec program="${MSBuildPath}">
<arg line='"${SolutionFile}"' />
<arg line="/property:Configuration=${SolutionConfiguration}" />
<arg value="/target:Rebuild" />
<arg value="/verbosity:normal" />
<arg value="/nologo" />
<arg line='/logger:"C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll"'/>
</exec>
</target>
The value MSBuildPath for different versions of .NET are
2.0, 3.0 C:\Windows\Microsoft.NET\Framework64\v2.0.50727\MSBuild.exe
3.5 C:\Windows\Microsoft.NET\Framework64\v3.5\MSBuild.exe
4, 4.5.x, 4.6.x, 4.7.x C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe
For a 32-bit build, change Framework64 to Framework
Update
Following up on some of the comments, the value attribute is used for parameters that have no white space characters where as line is used for parameters that contain white spaces. Otherwise, the NAnt would use the space as an end of input.
Here is a simple target
<target>
<loadtasks assembly="${nant::get-base-directory()}/../../nantcontrib-0.85/bin/NAnt.Contrib.Tasks.dll" />
<msbuild project="${filepath.root}/yourproject.csproj" verbose="true">
<arg value="/p:Platform=${build.platform}" />
<arg value="/t:Rebuild" />
<arg value="/p:OutputPath=${build.dir}/bin/" />
</msbuild>
</target>

Finding TeamCity Agent's working path for use in MSBuild script

I want to copy the output files from my build to a staging server, but I can't figure out how to find the path used by TeamCity to store the build output in from in MSBuild. Any help?
Thanks!
The $(teamcity_build_workingDir) property did it.
The best way is to upload the files to teamcity. Choose step1 (General Settings) and enter artifacts path. It should be something like /SourceOfProject/bin/releaese/*.dll.
I zip files before I upload them, because you only want to download 1 file that contains the complete build.
My build always has 2 steps in a nant - file.
Step1 - call msbuild
Step2 - use 7zip to create zip
<?xml version="1.0"?>
<project name="MyProjectBuild"
default="build" basedir="."
xmlns="http://nant.sf.net/release/0.85/nant.xsd">
<description>Build Script</description>
<target name="build" >
<exec program="C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe" >
<arg value="MyProject\MyProject.csproj" />
<arg value="/t:Build" />
<arg value="/p:Configuration=Release" />
</exec>
<exec program="7z" >
<arg value="a" />
<arg value="MyProject\bin\release\buildresult.zip" />
<arg value="MyProject\bin\release\*.dll" />
</exec>
</target>
</project>
Anyway my working path is:
C:\Programme\TeamCity\buildAgent\work