Geeks With Blogs

@jakobehn

News

Microsoft Community Contributor Award 2011


Jakob Ehn Visual Studio ALM MVP @Inmeta Crayon

UPDATE: 2010-09-15 – Added details about the use of the ExitCode variable

 

One of the most common complaints from people starting to use Team Build is that is doesn’t support building Microsoft’s own Setup and Deployment project (*.vdproj). When creating a default build definition that compiles a solution containing a setup project, you’ll get the following warning:

The project file "MyProject.vdproj" is not supported by MSBuild and cannot be built.

 

This is what the problem is all about. MSBuild, that is used for compiling your projects, does not understand the proprietary vdproj format defined by Microsoft quite some time ago. Unfortunately there is no sign that this will change in the near future, in fact the setup projects has barely changed at all since they were introduced. VS 2010 brings no new features or improvements hen it comes to the setup projects.

VS 2010 does include a limited version of InstallShield which promises to be more MSBuild friendly and with more or less the same features as VS setup projects. I hope to get a closer look at this installer project type soon.

But, how do we go about to build a Visual Studio setup project and produce an MSI as part of a Team Build process? Well, since only one application known to man understands the vdproj projects, we will have to installa copy of Visual Studio on the build server. Sad but true. After doing this, we use the Visual Studio command line interface (devenv) to perform the build.

In this post I will show how to do this by using the InvokeProcess activity directly in a build workflow template. You’ll want to run build your setup projects after you have successfully compiled the projects.
 

  1. Install Visual Studio 2010 on the build server(s)

     
  2. Open your build process template /remember to branch or copy the xaml file before modifying it!)

     
  3. Locate the Compile the Project activity

     
  4. Select the activity and open the Variables tab at the lower right

  5. Add a new variable called ExitCode of type Int32. This variable will contain the exit code from the devenv process and can be validated for errors.

    image
  6. Drop an instance of the InvokeProcess activity from the toolbox onto the designer, after the Run MSBuild for Project activity

     
  7. Drop an instance of the WriteBuildMessage activity inside the Handle Standard Output section.
    • Set the Importance property to Microsoft.TeamFoundation.Build.Client.BuildMessageImportance.High
      (NB: This is necessary if you want the output from devenv to show up in the build log when running the build with the default verbosity)
    • Set the Message property to stdOutput

       
  8. Drop an instance of the WriteBuildError activity to the Handle Error Output section
    • Set the Message property to errOutput

       
  9. Select the InvokeProcess activity and set the values of the parameters to:


    image 

    Note that the Result is piped to the ExitCode variable.
  10. The finished workflow should look like this:


    image 

     
  11. This will generate the MSI files, but they won’t be copied to the drop location. This is because we are using devenv and not MSBuild, so we have to do this explicitly

     
  12. Drop a Sequence activity somewhere after the Copy to Drop location activity.

     
  13. Create a variable in the Sequence activity of type IEnumerable<String> and call it GeneratedInstallers

     
  14. Drop a FindMatchingFiles activity in the sequence activity and set the properties to:


    image 

     
  15. Drop a ForEach<String> activity after the FindMatchingFiles activity. Set the Value property to GeneratedInstallers

     
  16. Drop an InvokeProcess activity inside the ForEach activity.
    •  FileName: “xcopy.exe”
    • Arguments: String.Format("""{0}"" ""{1}""", item, BuildDetail.DropLocation)

  17. The Sequence activity should look like this:


    image 

     
  18. Save the build process template and check it in.

     
  19. Run the build and verify that the MSI’s is built and copied to the drop location.

 

Note 1: One of the drawback of using devenv like this in a team build is that since all the output from the default compilations is placed in the Binaries folder, the outputs is not avaialable when devenv is invoked, which causes the whole solution to rebuild again. In TFS 2008, this was pretty simple to fix by using the CustomizableOutDir property. In TFS 2010, the same feature is not avaialble. Jim Lamb blogged about this recently, have a look at it if you have a problem with this: http://blogs.msdn.com/jimlamb/archive/2010/04/13/customizableoutdir-in-tfs-2010.aspx
 

Note 2: Although the above solution works, a better approach is to wrap this in a custom activity that you can use in your builds. I will come back to this in a future post.

Posted on Friday, May 14, 2010 8:38 AM TFS , Team Build , Visual Studio 2010 | Back to top


Comments on this post: Building Visual Studio Setup Projects with TFS 2010 Team Build

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
I'm trying to follow these steps but I'm stuck on step 7. Alongside where I've entered [ExitCode] in the Result property there's a Compiler error stating: "Compiler error(s) encountered processing expression "[ExitCode]". 'ExitCode' is not declared. It may be inaccessible due to its protection level."

Please help.
Left by Rob on Jul 06, 2010 4:02 AM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
I have created a build agent on another server so I can take the load off compiling on the TFS Server itself. I guess I need to install VS 2010 on the Build Server to get my applications to compile correctly. You mentioned installing VS 2010 on the build server, but what edition did you end up installing. I am cheap, I want to install the least expensive edition that I can. Can I install the Shell and get by with that?
Left by Steve on Jul 15, 2010 9:10 AM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
excellent.
can you give an example or a step by step procedure of how to proceed ,for the same scenario?
Appreciate your help!

Thanks,
eswar
Left by eswar on Jul 28, 2010 8:22 AM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Thanks for the article, very well laid out and very helpful!

I get the same problem as Rob at step #7. If i just leave that field blank, though, instead of putting "[ExitCode]" in there then everything seems to work fine. I'm curious if I even need to do anything about it.

Also, on a side note, it seems to expect VB code in all the configuration properties. Is there an option somewhere to make it use C# ?

Thanks,
Jeremy
Left by Jeremy on Aug 02, 2010 1:40 AM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Thanks for the help, I managed to get this working, *except* that when the devenv command runs on the build server, the following error is logged. Package 'Microsoft.VisualStudio.TestTools.TestCaseManagement.QualityToolsPackage, Microsoft.VisualStudio.QualityTools.TestCaseManagement, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed to load.

Any ideas, can provide more info if necessary.
Left by Chris on Aug 04, 2010 9:11 AM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
I was able to solve The package load failure by just using the arguments: "/Build " + localProject on the InvokeProcess activity
Left by Rudi on Aug 18, 2010 10:49 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
addendum: switching to devenv.exe did the trick.
Left by Rudi on Aug 19, 2010 12:54 AM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
All: i have updated the post with the details about the ExitCode variable, sorry for that. Note that in this example I do not actually check the variable afterwards. Do this by adding an If- or Switch activity after the InvokeProcess activity.
Left by Jakob Ehn on Sep 14, 2010 7:17 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Absolutely brilliant, this little article solved several issues that the MS documentation was useless for.

Thanks!
Left by Kenn on Sep 21, 2010 6:16 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Excellent post, very helpful. The trouble is I also have the QualityTools.TestCaseManagement issue mentioned above by Chris.

I think Rudi's solution above is a red herring, it actually results in devenv failing but it doesn't fail the build so it looks like the build has passed (check the log).

I think the issue is that I'm using VS2010 Premium instead of Ultimate and that the QualityTools.TestCaseManagement.DLL is failing to load because the LoadTest.DLL file isn't installed (I'm not trying to do Load Testing btw).

Does anyone have a solution to this problem?

I'm currently participating in a thread on it, but we don't seem to be getting anywhere, over here: http://social.msdn.microsoft.com/Forums/en-US/tfsbuild/thread/cbfb80ed-0c8f-4f2a-889c-635ccca9db8c/
Left by Rob on Sep 28, 2010 8:29 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
The issue I mentioned above seems to be resolved by using devenv.exe instead of devenv.com

If you know of or find a problem with this method then please, please, please post a comment on the MSDN thread mentioned in my above comment.
Left by Rob on Nov 09, 2010 2:52 AM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
This is very good and helpful but I still have a problem. I'm using devenv to build some non-Microsoft compiler projects (e.g., C, Fortran) that MSBuild can't handle. I see the logged output and in some cases I see errors (e.g., no such source file), but the devenv errors don't seem to come in as error output so the TFS build says no errors (even though the devenv log clearly shows compile and link errors). What are people doing for this?
Left by MattC on Dec 02, 2010 10:23 AM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
MattC, see Jakob's post from 9/21/2010 7:17 PM

I think you'll need to check the ExitCode variable and then raise errors accordingly. Does that help?
Left by Rob on Dec 15, 2010 10:36 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Thanks for such a comprehensive post. I am able to get the .msi's but I am unable to get the dll's which are a result of building this project... I have tried to copy the ExitCode at some location but I found no success... can you please help me through this.
Left by Nachiket on Dec 23, 2010 7:00 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
This is a good work around.
But as a permanent solution if you share an article/steps how to leverage the free install shield version comes with VS2010 it will be more help ful..
Left by Senthilraj on Jan 11, 2011 10:48 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Hi,

I tried these steps to build the .vdproj. Unfortunately, no msi's are generated/copied to the drop folder.
I've checked in the process template after making changes.
Can you guide..what could be wrong?
Left by Sonali Noolkar on Feb 15, 2011 8:21 AM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Sonali: Make sure that you are building the solution configuration that contains the setup project. By default, this is the Release configuration, but it might be different in your setup. Otherwise, run the build in diagnostic mode and check the log for details
Left by Jakob Ehn on Feb 15, 2011 8:24 AM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Thanks Jakob for the reply.

The solution file contains the setup project. The issue was that I had space in the folder name in TFS. enclosed the variable localproject in queotes like ...+ """" + localProject + """" and it worked.

However I am getting below errors:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.com /Build Debug "D:\Builds\5\AO SDMC.NET\WebApplicationStarterKit4_CI\Sources\WebApplication.sln"

Microsoft (R) Visual Studio Version 10.0.30319.1.
Copyright (C) Microsoft Corp. All rights reserved.

Package 'Microsoft.VisualStudio.TestTools.TestCaseManagement.QualityToolsPackage, Microsoft.VisualStudio.QualityTools.TestCaseManagement, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed to load.

Package 'Microsoft.VisualStudio.TestTools.TestCaseManagement.QualityToolsPackage, Microsoft.VisualStudio.QualityTools.TestCaseManagement, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed to load.

Also there are 4 other errors with no message associated.

Can you please guide for these unknown errors?
Left by Sonali Noolkar on Feb 21, 2011 9:51 AM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Jakob,
It looks like I am missing something. Would you please let me know the parameters to be passed as part of MSBuild argument?

I am trying to get the msi deployed onto destination server from TFS.
Left by Sumit on Feb 24, 2011 9:58 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Hi,

at the begining, thanks for the post, it helped me a lot.

I got similar problem with "Package 'Microsoft.VisualStudio.TestTools.TestCaseManagement.QualityToolsPackage, Microsoft.VisualStudio.QualityTools.TestCaseManagement, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed to load.".

I resolved it by changing devenv.com to devenv.exe in path to visual studio.

Hope this will help somebody.

Best regards,
Maciej
Left by Maciej Wolniewicz on Mar 04, 2011 1:46 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
I came across a fairly simple way to have the output of each project end up in their respective bin/[configuration] so that when compiling the .vdproj, the entire solution is not rebuilt. In step 10 listed above, find "Run MSBuild for Project". Select this activity, and in the properties window, clear the property OutDir. This will enable the normal OutputPath of project. However, none of the output files will be copied to the Binaries directory and will then not end up in the drop folder. There will be a warning about in the tfs build log. However, what you will see in the drop folder is the log file and the .msi/.exe, depending on which files were specified to be copied over the drop folder in step 14 when defining the "Find generated installers" activity.
Left by Dave on Mar 18, 2011 10:44 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
I can't figure out where the Copy to Drop activity is... Maybe I am just blind. Is it possible that the label is something else? Also, could you tell me what high-level parent this is supposed to be in?
Left by Nate on Mar 22, 2011 10:30 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Hi Jakob,

Thanks for the post. It is really helpful. I have a couple of questions though:

(1) Regarding the ExitCode variable, I'm still not quite sure with what condition should I use with a If or switch because I'm getting "Compiler error(s) encountered processing expression "[ExitCode]". 'ExitCode' is not declared. It may be inaccessible due to its protection level." error.
(2) Also, I'm getting the same error for localProject.

I would really appreciate if you could help me fix these errors. I'm new to MSBuild 4.0.

Thanks a ton,
Paresh
Left by Paresh on Mar 24, 2011 9:58 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Hi Jakob,

I'm still waiting for your response on the two queries I have above. Please please help me, its real urgent.

Can anyone else help me out please?

Thanks a ton,
Paresh
Left by Paresh on Mar 26, 2011 10:40 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
@Paresh: Sorry for the late answer.

If you can't reference a workflow variable (such as localProject), the reason is usually that you the variable is not in the current scope. localProject is declared inside the "Compile the Project" sequence activity,
which means that you can only reference the variable within that activity.

Reagarding the ExitCode variable, have you added the variable to the "Compile the Project" sequence activity (Step 5 above). If so, you should be able to reference the variable later in the same scope.
Left by Jakob Ehn on Mar 29, 2011 9:05 AM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Hi Jakob,

I'm still waiting for your response on the two queries I have above. Please please help me, its real urgent.

Can anyone else help me out please?

folding mountain bike
Left by eric on Apr 21, 2011 7:40 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Hi. I have some problems. I think that I misunderstood some section.
Until section 11 you describe how to create msi, but where can I find created files?
In section 12 you wrote drop a sequence somewhere after "copy to drop", but where should I find "copy to drop" sequence? Where do you mean by "somewhere"?
Left by Rami on Jul 03, 2011 10:02 AM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Hi,

I have configured the TFS system in my client Win 7 machine and the MSIs are not getting built and the error is showing as "These files could not be found and will not be loaded.
The operation could not be completed". I modified the argument for devenv as String.Format("{0} /build {1}|{2}", localProject, platformConfiguration.Configuration, platformConfiguration.Platform) as the argument shown in this article was showing error to "use devenv [solutionfile | projectfile | anyfile.ext] [switches]""

When I invoke the command from console it builds the MSI But not from the Teambuild system.

Please let me know what could be the error.

Earlier I was always
Left by Mush on Jul 25, 2011 1:02 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Hi -

When I removed the build configurations, the error is not shown and the project is getting built, but throws error related to DLL reference path. Please elt me know the best way to fix this.
Left by Mush on Jul 25, 2011 2:19 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Thank you! this is exactly what I was looking for and your steps are very detailed!
Left by GratefulCoder on Aug 08, 2011 8:30 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Whole solution is getting copied into the sources folder but i fo not see the compiled files under bin folder...
Left by Jas on Aug 17, 2011 5:34 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
I found the problem. I was trying to build a business intelligence solution. For some reason it does not like to specify the project configuration.I set it as default. But how can i specify the solution and the project to build inside a single build definition?
Left by Jas on Aug 17, 2011 6:34 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Xcopy does not work when a build is scheduled in TFS 2010
Left by TJ on Aug 23, 2011 2:19 AM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
I'm trying to follow these steps but I'm stuck on step 16. Returned message is saying: 'Item' is a type and cannot be used as an expression.
Left by Amanda on Sep 13, 2011 7:42 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
This is just awesome!

For those wondering where to find the "Copy To Drop" activity, this is where I found it
Run On Agent-->Try Compile, Test...(Finally Block)-->Revert Workspace and Copy Files to Drop Location

Cheers!
Left by Gandalf on Oct 05, 2011 7:28 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
This is awesome!

I do have a few questions though. I have implemented this for one of our projects and it was successfully building the MSI files and copying them, however it has stopped working. Any ideas on how to update this to handle any potential errors?

The MSI files doesn't seem to be generated by the invoking of DevEnv. However when we build manually on TFS machine running DevEnv the MSI file is found in the \release folder for our setup project. Any ideas?
Left by Bill on Oct 07, 2011 4:11 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
@Bill: Make sure that you are building the correct solution configuration, e.g. Release|Any CPU for example, and that this configuration includes the setup project. Otherwise you need to check the output from devenv, run the build with diagnostic verbosity and examine the output from devenv
Left by Jakob Ehn on Oct 10, 2011 9:22 AM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
great post, one of the few on tfs 2010
Left by james on Oct 11, 2011 11:07 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Hi there,
for step 13, i couldn't find type "IEnumerable<String>" from the dropdown window to create the variable. am i missing some assamplies?
thanks!
Left by Lin on Oct 13, 2011 8:11 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Which edition of Visual Studio is needed on the build system?
Does the Express Edition also work?
Left by J. Meyer on Oct 17, 2011 8:10 AM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
For xcopy failing on scheduled builds, check permissions for the Build Service account on the sourcecode folder (e.g. C:\Builds). I use the Network Service account and so gave Full Control to Network Service on C:\Builds. The scheduled build was then successful.
Left by Darren on Nov 01, 2011 3:21 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Lin
The IEnumerable<String> is found by; Browse for types. find IEnumerable<t>. Then there will be a combo slection allowing you to change the 't' to String.
Now when you select OK it will fill that cell and there will be an additional entry for that cell that will be "system.collections.generic.ienumerable<System.String>

Randy
Left by Ransch on Nov 11, 2011 9:53 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Can you post the xaml file you used for this project?
Left by Philip Ammann on Dec 09, 2011 11:35 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
It worked great for me. However,as a side note, I did run into a problem with just building it in a command prompt on the build server. Turns out there is a hot fix for this for Visual studio 2010: https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=30681
Left by Ken on Mar 19, 2012 8:53 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Looking assistance for build/automate process in TFS2010. Is there any article shows end -end process which will help to setup the project.
Left by Vilas Tajane on Jul 10, 2012 1:58 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Works great. The only issue I have is that it's creating setups for each referenced project in the solution (that have setups defined) such as webservices. Not a big deal, I'm working on modifying the template to build the setup for a specific project within the solution.
Left by DL on Jul 12, 2012 10:56 PM

# re: Building Visual Studio Setup Projects with TFS 2010 Team Build
Requesting Gravatar...
Hey there, thanks for the great article! It worked like charm! Let me suggest two small improvements (hopefully I did not overlooked some in the other comments):
1) It would be really great if you could show up the path to the activities mentioned in the article, I have searched some time to find
(Compile the Project = Process -> Sequence -> Run on Agent -> Try Compile, Test... -> Sequence -> Compile, Test, an... ->
Try Compile and Test -> Compile and Test -> For Each Configur... -> Compile and Test ... ->
If BuildSettings.HasProjectsTo -> For Each Proejct in BuildSettin… -> Try to Compile the Project -> Compile the Project)
2) If you set an relative "Output file name" on the setup project properties you can skip steps 12-17 because the msi file will be automatically build to the right location and is included in the normal Copy to Drop Location.
I am not pretty sure with the 2) improvement because I already modified the template slightly concerning source and binary directory but if someone could try it would be a pleasure!

Anyway great job and thanks for the solution! Hopefully we can get this working also in VS & TFS 2012 where deployment project type is kicked out completely!
Best Regards
Balu

Left by Balu on Oct 09, 2012 1:48 PM

Your comment:
 (will show your gravatar)
 


Copyright © Jakob Ehn | Powered by: GeeksWithBlogs.net | Join free