tags:

views:

665

answers:

5

I am trying to add a BuildStep to the AfterBuild target in MSBuild and I am using the following

<Target Name="AfterCompile">    
 <ItemGroup>      
  <TestAssemblies Include="$(OutDir)\DataStoreUnitTests.dll" />   
 </ItemGroup>    

 <BuildStep      
  Name="Run unit Tests"
  TeamFoundationServerUrl="$(TeamFoundationServerUrl)"     
  BuildUri="$(BuildUri)"      
  Message="Running unit tests">      
  <Output TaskParameter="Id" PropertyName="StepId" />    
 </BuildStep>    

 <Gallio      
  Assemblies="@(TestAssemblies)"      
  ReportTypes="html"      
  ReportFileNameFormat="buildreport{0}{1}"      
  ReportOutputDirectory="." />    

 <BuildStep      
  TeamFoundationServerUrl="$(TeamFoundationServerUrl)"      
  BuildUri="$(BuildUri)"      
  Id="$(StepId)"      
  Message="Yay! All tests succeded!"      
  Status="Succeeded" />    
  <OnError ExecuteTargets="MarkBuildStepAsFailed" />  
 </Target>  

 <Target Name="MarkBuildStepAsFailed">    
  <BuildStep      
   TeamFoundationServerUrl="$(TeamFoundationServerUrl)"      
   BuildUri="$(BuildUri)"      
   Id="$(StepId)"      
   Message="Tests have failed. See test report in drop folder for details." 
   Status="Failed" />  
</Target>

And when I run it in MSBuild I get the following error:

error MSB4044: The "BuildStep" task was not given a value for the required parameter "BuildUri".

And I cannot see why, does anyone know?

+2  A: 

My thoughts are that $(BuildUri) is evaluating to nothing. Try doing a print statement to debug and target the line number that VS/MSBuild is giving as an error.

<Message Text="$(BuildUri)" />

MSBuild can be run from the command line (I find MSBuild to be easier to work with that way) with the following command:

C:\WINDOWS\Microsoft.NET\Framework\%FrameWork_Version%\MSBuild /verbosity:n
%Solution or Project file%

To set $(BuildUri):

<Target Name="AfterCompile">    
    <PropertyGroup>
        <BuildUri>Build_Uri_Value</BuildUri >
    </PropertyGroup>

    <ItemGroup>
        ...

Information on BuildUri can be found here:

What is the BuildUri and where do i get it from when i'm just trying to get some source?

Gavin Miller
A: 

Indeed, when I add the Message statement, I get back an empty string. Any ideas how I set this to something valid?

Colin

Colin Desmond
Colin, the practice on StackOverflow is to edit your question and add this piece of information, instead of adding it as an answer.
Gavin Miller
A: 

My problem is I have no idea what the BuildUri is or what a valid value would be. Is there any documentation that describes it?

The link provided gives me enough information to crack on, many thanks!!

Colin

Colin Desmond
+3  A: 

Are you running this target as part of a Team Build (on the build server) or as a Desktop build (i.e. locally)?

The BuildUri property is normally populated passed in to the build by the build agent when it is triggering a new team build. In your script the Uri is used to tell TFS what build detail to attach the build step to. If you are running a desktop build then this will be empty unless you pass the property in on the command line.

Martin Woodward
A: 

Martin, thanks for this, it all makes sense now. I was testing the script using a desktop build! I'll try a server build now and see if that makes any difference.

Worked a treat on the build server! Many thanks.

Thanks

Colin

Colin Desmond