Posts Tagged TFS

BizTalk MsBuild Generator Tips

Introduction
 
A couple days ago I was working on creating some msbuild scripts for building my BizTalk solutions. I am not particularly knowledgeable about the way this is usually done. I checked out my friend (and fellow MVP) Michael Stephenson’s CodePlex project, the BizTalk MsBuild Generator at http://biztalkmsbuildtool.codeplex.com/. This tool is really helpful for getting something rapidly created that you can run with. There were a couple things I did to make this free tool work a little better and I wanted to share some of these tips so that others could get the most out of Michael’s great contribution to the BizTalk community.
 
Tips
 
I was working on some solutions in BizTalk 2009, SQL 2008, Windows Server 2008 R1/R2. I first started with some solutions that were building fine in VS 2008. There were a couple of minor things I had to get some of my projects to build properly. Some of these tips will seem very simple for someone with experience doing automated builds in TFS. But for someone with less experience, it can be confusing.
 
1. After going through the wizard to generate the msbuild files, the generator created a folder full of files so I tried to kick off the build with one of the .cmd files. It got errors part way through. Basically the build was having trouble finding my projects because my solution file was in a different place than it expected it to be. After a bit of inspection of the generated files, I opened up the generated .proj file. Here is what was initially under the Build target:
 
<Target=Build>
    <
CallTarget Targets=CleanUp/>
    <
CallTarget Targets=Setup/>
    <
MSBuild Projects =$(SolutionName) Properties=Configuration=$(ConfigurationName);/>
    <
CallTarget Targets=Deployment/>
    <
CallTarget Targets=Publish/>
    <
CallTarget Targets=ApplyBindings />
    <
BizTalk.BuildGenerator.Tasks.StartApplication MessageBoxConnection=$(BizTalkManagementDatabaseConnectionString) ApplicationName=$(ProductName)/>
    <
CallTarget Targets=UnitTests Condition=$(IncludeTests) />
</
Target>

 

I changed the MSBuild element’s project attribute by setting it to $(SourceCodeRootFolder)$(SolutionName) so that it could find the location of my projects. You could use a hard coded path here if the SourceCodeRootFolder value is not valid for your solution.
 
2. I rebuilded after making the change above and the build file works almost completely until it executes the last steps and fails. Some of the default assumptions of the generator are that you will want to deploy the BizTalk applications immediately and part of the same process which is common in continuous integration environments. In my environment I am not able to do this due to some deployment rules and constraints of how my BizTalk applications are being used.
 
I seemed to particularly have trouble with the following line:
 
<BizTalk.BuildGenerator.Tasks.StartApplication MessageBoxConnection =$(BizTalkManagementDatabaseConnectionString) ApplicationName=$(ProductName)/>
 

 

My troubles were because in my local development environment I do not always maintain bindings and binding configurations for some ports. You can comment this line out to avoid trying to start the BizTalk application.
 
3. I used the tool a couple times and did not have any problems generating the file. For one of my solutions I was not able to complete the wizard and I got the following error:
 
************** Exception Text **************
System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
at System.Reflection.Assembly.nLoadFile(String path, Evidence evidence)
at System.Reflection.Assembly.LoadFile(String path)
at BizTalk.BuildGenerator.BizTalkHelper.AddResourceReferences(Resource resource, ApplicationResource applicationResource)
at BizTalk.BuildGenerator.BizTalkHelper.DescribeApplication(String applicationName)
at BizTalk.BuildGenerator.UI.UserControls.ApplicationDescriptionControl.GetDescription()
at BizTalk.BuildGenerator.UI.UserControls.ApplicationDescriptionControl.MoveNext()
at BizTalk.BuildGenerator.UI.WizardForm.ChooseApplicationPage_BeforeMoveNext(Object sender, CancelEventArgs e)
at Divelements.WizardFramework.WizardPageBase.OnBeforeMoveNext(CancelEventArgs e)
at Divelements.WizardFramework.Wizard.GoNext()
at Divelements.WizardFramework.Wizard.c(Object A_0, EventArgs A_1)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
 
This error occurs because one of the assemblies for a deployed BizTalk application cannot be found. This can happen if you have deployed your BizTalk application and then ungac an assembly by hand using gacutil /u or by deleting a file from c:Windowsassembly. For one of my solutions this was a problem. It can be notoriously hard to determine which assembly reference is the problem for large complicated solutions. This problem is repeatable – I tried a couple times.
 
I decided to dig into the problem a little deeper and downloaded the source for the generator from CodePlex. I was able to implement a quick workaround for the issue that resulted in being able to run the wizard successfully as well as generate a build file that built correctly. My patch for this issue can be found here: http://cid-62e68922e47bc425.office.live.com/self.aspx/Public/Community%20Contributions/BizTalk%20BuildGeneratorPatch%20-%207-12-2010.zip I also uploaded the patch to CodePlex and you can get it on the source codepatches link on the site. The patch includes both the assembly and the single source code file I updated.
 
If you just want the built file to fix your local installation of the BizTalk MsBuild generator, just copy the BizTalk.BuildGenerator assembly to your install folder and copy it to the GAC. If you want to build it from source, do the following. Take the BizTalkHelper.cs file from the patch and copy it over the same named file in the BizTalk.BuildGenerator project. The changes were just to wrap the body of the AddResourceReference method with a try/catch. I also added a line for logging the exception informatin.
 
Conclusion
 
These tips help you to be even more productive using the BizTalk MsBuild Generator tool. I was able to get quite a few solutions ready for MsBuild very quickly so I am glad Michael released this tool.
 
Thanks,
 
Advertisements

, ,

3 Comments

Swap in your Merge Tool in Visual Studio

During the middle of a maintenance release for MOSS (which by the way is not a easy thing to do), my team was working through a considerable amount of merging source code via TFS from our main source tree to a branch for a patch release. Working with the default Visual Studio merge tool is not the easiest thing to do. For example, if you want to remove a change from the resultant code file that say is 100 lines in a method, the line numbers get messed up and it becomes more difficult to follow along with the change comparison. Its also not that easy to choose which change you want to use when comparing the changes. So I did a brief search and it looks like you can swap in a different (or custom) merge tool that Visual Studio will use when you compare and merge changes. Here is a link I found on configuring Visual Studio to do this (thanks to Vitaly for the excellent content): http://www.vitalygorn.com/blog/post/2007/12/Better-DiffMerge-tool-for-TFS.aspx.
 
Since one of the diff merge tools listed here is on SourceForge you can look at the source and customize it like you want to so this opens the possibility for making a guided compare/merge tool which can be really helpful for a development team. Nice!

Leave a comment