Building setup projects with Team Build and running tests on product install


Setup projects (.vdproj) do not have a project system format that can be understood by MSBuild. Hence MSBuild cannot build these projects directly and consequently neither can Team Build. What we can do however is use the devenv /build command to build the vdproj files and generate msi installers. As I set out to build setup projects and install them on the build machine in order to run tests on those, I followed the sequence of steps listed below:


Override the target AfterCompile in the TFSBuild.proj file. Include an Exec task in the target to build the setup project separately using devenv /build.


<Target Name=”AfterCompile“>
    <Exec Command=”&quot;$(VSINSTALLDIR)\Common7\IDE\devenv&quot; ..\Sources\MySolution\MySetup\MySetup.vdproj /Build“/>
  </Target>


Now, if you kick off a build, the msi is built, but is dropped into the bin folder under the Sources folder in the build directory. But in order to get it into the drop location, you need to edit the “Output file name” property in the setup project properties to ..\..\..\Sources\ since you cannot pass the output directory to the command line. Now, when you kick off a build, you see the msi file in the Binaries folder on the build machine and consequently the drop location. The caveat is that you will need VS installed on the build machine if you want to build using devenv.


Invariably the problem arises that you would want to build the setup project in different flavors now. The solution to that one is slightly tricky. Remember, you cannot pass in the output directory on the command line, that is why you have to build the setup project in the Binaries folder and then include a task to copy the dlls to the appropriate flavor’s folder. Then again, you can build the setup project in a different flavor and re copy the dlls into the appropriate folder. You can use the /ProjectConfig switch to specify the flavor in which the setup project is to be built.


Now that you have built setup projects, you want to do something else. Run tests on the installed product to pronounce it good or bad. Consider a solution that has a console application, a setup project and a test project. The setup project is built into an msi that dumps the created exe into a folder called say “D:\Program Files\MySetup”. Now, the test project has a generic test that calls the console application’s exe from the same folder. If the install has happened successfully on a machine, the test calls the console application exe and based on the behaviour may either pass or fail. But, in case the product is not even installed, then the test aborts saying that the exe is not found. So, now after the AfterCompile custom task builds the setup project, you put in another custom target BeforeTest. Include a task “Exec” in this target that will call the setup.msi file with the /quiet switch to install the product without launching the UI. Right after this target, tests are run in the Test target and the generic test will not abort if the install has succeeded.


<Target Name=BeforeTest>
    <Exec Command=..\Binaries\Setup1.msi /quiet/>
</Target>


While writing this task, I hit an error in install. This was due to the build service account not being an admin on the build machine and install rights being denied to the account. After adding the build service account as admin on the machine, remember to restart the build service. Now, the install succeeds and the tests run on the installed product.


Feel free to post comments if you need help with any other related scenarios.

Comments (24)

  1. Anonymous says:

    Rob Caron points us to a process guidance print tool. He also talks about TDD in Agitator and Team System….

  2. Anonymous says:

    This article describes how to have

    TFS’s build functionality accomodate and build setup and deploy…

  3. Anonymous says:

    Better even, just use Wix (http://wix.sourceforge.net) that has native support for MSBuild ;).

  4. Anonymous says:

    Hi ,
    When using BuildTypes ,I am not getting the DeploymentPackage (.msi)file in Release mode,instead it is always creating the deployment package in Debug mode .

    The following content is my TFSBuild.proj

    < ?xml version="1.0" encoding="utf-8"?>


    test build

    tmserver

    Test

    D:BuildSample

    \prog_126Build

    false

    Symptom=build break;Steps To Reproduce=Start the build using Team Build
    <!– CODE ANALYSIS
    To change CodeAnalysis behavior edit this value. Valid values for this
    can be Default,Always or Never.

     Default - To perform code analysis as per the individual project settings
     Always  - To always perform code analysis irrespective of project settings
     Never   - To never perform code analysis irrespective of project settings
     -->
    <RunCodeAnalysis>Never</RunCodeAnalysis>
    <!--  UPDATE ASSOCIATED WORK ITEMS
     Set this flag to enable/disable updating associated workitems on a successful build
    -->
    <UpdateAssociatedWorkItems>true</UpdateAssociatedWorkItems>
    <!-- Title for the work item created on build failure -->
    <WorkItemTitle>Build failure in build:</WorkItemTitle>
    <!-- Description for the work item created on build failure -->
    <DescriptionText>This work item was created by Team Build on a build failure.</DescriptionText>
    <!-- Text pointing to log file location on build failure -->
    <BuildlogText>The build log file is at:</BuildlogText>
    <!-- Text pointing to error/warnings file location on build failure -->
    <ErrorWarningLogText>The errors/warnings log file is at:</ErrorWarningLogText>
    


    <Target Name="AfterCompile">
    
        <Exec  Command='"C:Program FilesMicrosoft Visual Studio 8Common7IDEdevenv.com" "$(SolutionRoot)TT1WebSetupWebSetup.vdproj" /ReBuild /ProjectConfig ' />
        <Copy SourceFiles="$(SolutionRoot)TT1WebSetupReleaseWebSetup.msi" DestinationFolder="$(DropLocation)$(BuildNumber)" />
    
    </Target>
    

    My objective is ,After building this build type ,i have to get the deployment package in Release mode

    Help me out with this issue

  5. Anonymous says:

    You could also use the DevEnv build task to simplify it. You will still need VS installed.

    Tasks: http://www.gotdotnet.com/codegallery/codegallery.aspx?id=b4d6499f-0020-4771-a305-c156498db75e

    Sample:

       <Tools.DevEnv VisualStudio="8.0" Path="MySetup.vdproj" Config="Release" OutputFolder="$(SolutionRoot)..BuildType" Clean="true"/>

    Regards… FreeToDev

  6. Anonymous says:

    Does this still work with the released bits? When I gave it a try the build service never returned so the build went on forever. I had to kill it via task manager and restart the build service.

  7. Anonymous says:

    I whant to automate the proceses in our teem. But I can’t build the msi project neither with msbuild.exe nor Nant nor through the command prompt. Even devenv.exe cann’t build *.vdproj through the command prompt. I will aprisiate very much if  anutthara tell me how to do any of these steps correctly.

    Thank you.

  8. Anonymous says:

    Thanks for the tips it got my build server running. I forgot the whole installation permissions thing, I assumed that the configuration of the build server would have given the appropriate permissions to the TFS Service Account.

  9. Anonymous says:

    Alex, you should be able to build a .vdproj through the command line.  

    Instead of specifying the .vdproj file, I used the .sln and it seems to be working well for me.

    Good Luck,

    Joey

  10. Anonymous says:

    Because many Visual Studio project types are not supported in MSBuild, many Team Build users end up needing

  11. Anonymous says:

    I am able to build and install succesfully by following above mentioned step.

    Issue arises in scenario where i run the build for the second time. Since it has already installed the application during first build. It cannot install again. It runs in silence mode, actually its waiting for user intervention whether to reinstall or repair the application. Due this build process runs infinetly without ending.

    Any help on this scenario is appreciated.

  12. Hi Jignesh- You should probably include a task to uninstall the build in your tfsbuild proj file after tests are executed. HTH.

    Also, I am on a different team now and dont have the full context on the current scene on setup proj scenario with Team Build. 🙁

    http://blogs.msdn.com/buckh should be the best place to ask setup proj or Team Build related qs

  13. Buck Hodges says:

    Jignesh, if you are installing the application you would need to uninstall the application before installing it again.  The Build forum on MSDN is a good place to ask questions: http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=481&SiteID=1.

    Buck

  14. Anonymous says:

    The article is good… But I tried the thing suggested by you in my TFS build script. But Unfortunately it’s keep on going…

    what went wrong here.Any idea?

  15. Anonymous says:

    hi,

    i have two configuration set up.

    <ConfigurationToBuild Include="Development|Mixed Platforms">

         <FlavorToBuild>Development</FlavorToBuild>

         <PlatformToBuild>Mixed Platforms</PlatformToBuild>

       </ConfigurationToBuild>

     &nbsp;&lt;ConfigurationToBuild Include=&quot;Testing|Mixed Platforms&quot;&gt;
    
         &nbsp;&lt;FlavorToBuild&gt;Testing&lt;/FlavorToBuild&gt;
    
         &nbsp;&lt;PlatformToBuild&gt;Mixed Platforms&lt;/PlatformToBuild&gt;
    
     &nbsp;&lt;/ConfigurationToBuild&gt;
    

     </ItemGroup>

    i can run one environment at one time .

    Can you help me how we can run both(development&testing) at one time.

  16. Anonymous says:

    For Shefeek:

    I presume the name of your TFS build and/or project path contains spaces.

    it is easy to work this around by adding a second quote after devenv and another one before the /build.

    This should do the trick

  17. Anonymous says:

    How can I build a solution that has

    -asp.net webservice

    -VC++ DLL

    -C# DLL

    -setup project

    from Team build, using devenv command line for the vdproj file. I get "Unable to find dependencies error". also in which flavor should I build – Release/Debug?

  18. Anonymous says:

    I have been trying different flavors of this fix and still do not have it working. After several issues surrounding the fact we code with VSTS2008 but build on TFS2005 I finnaly got the build to run without an error, however the command line building the vdproj using devenv just rebuilds the solution and still skips the setup project. The line is :

    "C:Program FilesMicrosoft Visual Studio 9.0Common7IDEdevenv" c:tfs1JurisSuiteMpMainDevBuildType..SourcesMainServicesConfigurationConfigurationServiceSetupConfigurationServiceSetup.vdproj /Build "Debug|x86"

    Any ideas from those who have this working?

  19. Anonymous says:

    В идеале, при гибкой (Agile) разработке процесс сборки решения и его развертывания в среде тестирования

  20. Anonymous says:

    Is it possible to build a setup project without installing VS on the build server? Because I’m required not to install VS there

  21. Anonymous says:

    Thanks for the assistence – you answered my questions perfectly.

  22. Anonymous says:

    This post is almost 2 years old. Are we still not able to build Set project (vdproj) via MSBuild???