woensdag, april 27, 2011

VS2010, TFS 2008 multiple build configs and run Unit Tests for only one build config

I want to have a build that has multiple configuration to build. One to run the tests and one to deploy directy to the test envirionment when all tests are passed.
Sounds great, but I ran into a couple of problems:
  • MSBUILD : warning MSB6006: "MSTest.exe" exited with code 1.
  • how to avoid to run the unit tests for the build to deploy
We use TFS2008 and TFS2008 build and the solution is developed with vs2010. At the build server vs2010 is installed. So when you run the unit tests, you need to use the right mstest see these posts:
http://stackoverflow.com/questions/5284174/mstest-fails-when-running-unit-tests-as-part-of-ci-using-tfs-2008
stackoverflow.com/questions/2720057/build-failing-vs2010-solution-on-tfs2008
the solution for me was:
http://blog.aggregatedintelligence.com/2011/03/vs2010-tfs-2008-and-unit-tests.html
and i added this to my tfsbuild.proj
<PropertyGroup> 
    <TestToolsTaskToolPath>
 C:\Program Files (x86)\Microsoft Visual Studio 10.0\
    Common7\IDE\MSTest.exe
</TestToolsTaskToolPath>  
</PropertyGroup>
One problem done one to go.
I searched a while to find the right solution but it was difficult to find but so simple.
I have found these solutions but I knew it must be simpler:
my solution is just add a condition to the itemgroup which contains the test container:
<ItemGroup 
  Condition=" '$(Configuration)' == 'S_TfsBuild' ">    
<TestContainer Include="$(OutDir)\%2aTest%2a.dll"/>
 </ItemGroup>
and my build configuration looks like this:
  <ItemGroup>
     <!--  CONFIGURATIONS     
The list of configurations to build. 
To add/delete configurations, 
edit this value. For example,      
to add a new configuration, add the following lines:
  <ConfigurationToBuild Include="Debug|x86"> 
  <FlavorToBuild>Debug</FlavorToBuild> 
  <PlatformToBuild>x86</PlatformToBuild>
</ConfigurationToBuild>      
The Include attribute value should be unique for each 
ConfigurationToBuild node.   
 -->    
<ConfigurationToBuild Include="Test|Any CPU"> 
      <FlavorToBuild>Test</FlavorToBuild> 
      <PlatformToBuild>Any CPU</PlatformToBuild>
     </ConfigurationToBuild>
      <ConfigurationToBuild Include="S_TfsBuild|Any CPU">
       <FlavorToBuild>S_TfsBuild</FlavorToBuild> 
      <PlatformToBuild>Any CPU</PlatformToBuild> 
    </ConfigurationToBuild>
   </ItemGroup>



 
;