none
Example of MSBuild with MSTest

    Question

  • Does anyone have an example of using MSBuild to build a website (or any other project), run tests (MSTest), then either deploying files or not (depending compile/MSTest results)?

    I'm trying to get a core solution, from which I can add emails, reports, etc.

    Thanks!
    Erick

    Monday, May 24, 2010 9:17 PM

Answers

  • Hello, Eric

    This is possible, this could be done in MSBuild.

    1.    For how to run the MSTest, We use Exec task to run MSTest comandline. See this link http://scottlaw.knot.org/blog/?p=400. For Exec task, there is an ExitCode output parameter. We could check this parameter to see whether our test is success of not. We could run the MSTest in AfterBuild target.

    I know little about MSTest, so that I could not provide more help to you.

    2.    We could use MSBuild Task to deploy our websites according to the MSTest. See this link http://codingcockerel.co.uk/2008/05/18/how-to-publish-a-web-site-with-msbuild/

    So the finally the code may like.

      <Target Name="AfterBuild">

        <PropertyGroup>

          <!--TestSuccessOrNot is the property specify whether the Test is sucess or not -->

          <TestSuccessOrNot>1</TestSuccessOrNot>

        </PropertyGroup>

        <!--Run MSTest.exe-->

        <Exec Command="$(VS90COMNTOOLS)..\IDE\mstest.exe /testcontainer:TestDLL.dll" >

          <Output TaskParameter="ExitCode" PropertyName="TestSuccessOrNot"/>

        </Exec>

        <!--Condition checks whether the MSTest was executed successfully, if so, deploy your web site-->

        <MSBuild Condition ="'$(TestSuccessOrNot)'=='0'" Projects="BuildDemoSite.csproj"

             Targets="ResolveReferences;_CopyWebApplication"

             Properties="WebProjectOutputDir=$(OutputFolder); 

               OutDir=$(WebProjectOutputDir)\" />

      </Target>

    Thanks
    Chao

    Wednesday, May 26, 2010 9:09 AM
    Moderator

All replies

  • Hello, Eric

    This is possible, this could be done in MSBuild.

    1.    For how to run the MSTest, We use Exec task to run MSTest comandline. See this link http://scottlaw.knot.org/blog/?p=400. For Exec task, there is an ExitCode output parameter. We could check this parameter to see whether our test is success of not. We could run the MSTest in AfterBuild target.

    I know little about MSTest, so that I could not provide more help to you.

    2.    We could use MSBuild Task to deploy our websites according to the MSTest. See this link http://codingcockerel.co.uk/2008/05/18/how-to-publish-a-web-site-with-msbuild/

    So the finally the code may like.

      <Target Name="AfterBuild">

        <PropertyGroup>

          <!--TestSuccessOrNot is the property specify whether the Test is sucess or not -->

          <TestSuccessOrNot>1</TestSuccessOrNot>

        </PropertyGroup>

        <!--Run MSTest.exe-->

        <Exec Command="$(VS90COMNTOOLS)..\IDE\mstest.exe /testcontainer:TestDLL.dll" >

          <Output TaskParameter="ExitCode" PropertyName="TestSuccessOrNot"/>

        </Exec>

        <!--Condition checks whether the MSTest was executed successfully, if so, deploy your web site-->

        <MSBuild Condition ="'$(TestSuccessOrNot)'=='0'" Projects="BuildDemoSite.csproj"

             Targets="ResolveReferences;_CopyWebApplication"

             Properties="WebProjectOutputDir=$(OutputFolder); 

               OutDir=$(WebProjectOutputDir)\" />

      </Target>

    Thanks
    Chao

    Wednesday, May 26, 2010 9:09 AM
    Moderator
  • An example of building and testing is here: https://github.com/jamestharpe/Rolcore/blob/master/src/Rolcore.build (note - the "Package" target currently does not work).

    For deployment, consider MS Web Deploy which can be installed via the Web Platform Installer. Pluralsight has a course that goes over the steps at http://pluralsight.com/training/Player?author=james-kovacs&name=ci-part6&mode=live&clip=8&course=continuous-integration - the course was free some time ago, I'm not sure if it still is.

    Thursday, December 27, 2012 3:45 PM