tags:

views:

616

answers:

1

I'm trying to work with MSBuild and TFS.

I've managed to create my own MSBuild script, that works great from the command-line. The script works with csproj files, and compiles, obfuscate, sign and copies everything that's needed.

However, looking at the documentation of TFS & Team Build, it appears that it expect solutions as the "input" for the script.

Also, I haven't found an easy/intuitive way of performing a "Get Latest Version" from the TFS as part of the script. I'm assuming that the Team Build automatically do a "Get Latest" on the solutions it's suppose to compile, but again - I don't (want to) work with solutions...

Any insights? any pointers? any links?

+3  A: 

Team Build defines about 25 targets of its own. When you queue a Team Build, they are automatically run for you in the predefined order listed @ MSDN. Don't modify this process. Instead, simply set a couple of these properties that determine how the tasks behave. For example, set <IncrementalGet> to "true" if you want ordinary Get behavior, or "false" if you want something closer to tf get /force.

As far as running your own MSBuild script, again this shouldn't be necessary. Start with the TFSBuild.proj file that's provided for you. It should only require minimal modifications to do everything you describe. Call your obfuscation & signing code by overriding a task like AfterCompile or AfterTest. Put your auto-deploy code in AfterDropBuild. Etc.

Even really complex scenarios are possible if you refactor appropriately. See past answers #1 #2.

As far as the actual compile, you're right that Team Build operates on solutions. I recommend giving it what it wants. I'll be the first to admit that *.sln files are ugly and largely undocumented, but at least you're offloading the work to a well tested & supported product.

If you really wanted to, you could give it a blank/dummy solution and override the CoreCompile task with your custom compiler logic. But this is really asking for trouble. At bare minimum, you lose all of Team Build's flexibility WRT building multiple platforms and flavors. More practically, you're bound to spend a lot of time debugging something that's designed to "just work" -- and there are no good MSBuild debuggers yet (that I know of). Not worth it, IMO.

BTW, the solution files do not affect the Get process. As you can see in the 1st link, the Get is done very early on, long before Team Build even reads the solution file(s). Apart from a few options like <IncrementalGet>, this is not controlled from MSBuild at all -- in particular, the paths to be downloaded are determined by the workspace mappings associated with the build definition. I.e., they are stored in the Team Build SQL database, not the filesystem, and managed with tools (like Team Explorer) that call the TFS webservice API.

Richard Berg
I have a follow-up question regarding this - you mention that I should run the obfuscation/signing in the AfterCompile task. Is that the recommended solution, or can I use the Dotfuscator projects?Also, what about Wix projects? how can I tell them where to take the files from?
SaguiItay
Overriding tasks such as AfterCompile simply tells Team Build *when* to run your code. *What* Team Build does at that time is entirely up to you. If you `<Call`> into Dotfuscator's msbuild projects, perfect. If you have custom code that invokes the command line signing tool yourself, that's fine too. Same goes for Wix. I'd personally reuse the msbuild tasks that come with such tools as much as possible, just to take the work out of your hands, but it's up to you.
Richard Berg
The question was a more general one - do I use the MSBuild tasks provided by the tools, or do I use the MSBuild task to build the projects created by those tools? (basically, do I obfuscate, or do I compile an Obfuscation project that will do the work for me?)
SaguiItay
IMO: building the created projects > using the provided tasks > invoking the EXEs from your own tasks. The former options are easier the latter are more flexible.
Richard Berg