Montag, 4. Juni 2012

Incremental Builds with TFS

A very handy TFS feature is kind of well hidden in the settings. The setting is so "tiny" that I did not find it for a long time. But first things first.

The task: set up a team build that compiles only those assemblies that have been modified since the last build. You can call this an incremental build.

The whole magic is the "Clean Workspace" parameter in the build definitions process tab. Here one can choose how the build handles its workspace. You have three choices:

  1. All: Delete Sources & Binaries, then get all and build all. This is a complete rebuild. This is the default
  2. Outputs: Delete the binaries but keep the sources. Gets only the sources that have changed (incremental get). Recompiles all the sources so you get a full set of binaries.
  3. None: Delete nothing. Gets only the sources that have changed and rebuilds only assemblies that have changed. 

Option three is the one that does the trick. If you trigger a build, than change something and trigger another build, your drop location will hold two folders. You will see all the files in both folders but dont be disappointed. All files are moved to the drop location, but mind the changed date: they are all different.


This way you can figure out easily what has acutally changed. This comes in handy if you want to ship hotfixes that only contain files that have really changed to keep installing the hotfix quick.

Have a nice build ;-)
Tobias.

Dienstag, 29. Mai 2012

Code Quality mit Visual Studio und TFS

Besser spät als nie, hier die Slides und Beispiele zu meinem Vortrag "Steigerung der Codequalität mit Visual Studio und TFS".

Bei Fragen und Anregungen gerne melden.

Viel Spaß und viel Erfolg beim clean coden :-)

Montag, 21. Mai 2012

Limits of COM Interop in Silverlight 5?

You can read a whole lot of posts about the P/Invoke capabilities of Silverlight 5. For some weired reasons I needet to initiatie an OLE Drag and Drop from Silverlight to Visual Basic 6.

I thought to use P/Invoke to call the Ole32.dll DoDragDrop Method, which is used under the hood by equally named WinForms function. It has the following signature:

[DllImport("ole32.dll")]
static extern int DoDragDrop(IDataObject pDataObject, IDropSource pDropSource,
   int dwOKEffect, int[] pdwEffect);

Even though there is a IDataObject Interface in Silverlight it is not the matching one for this COM call. So I decided to marshal it by hand, as well as the IDropSource interface. This is were the trouble starts.

The IDataObject interface looks like this (at least this is what I think is right):

  [ComImport]
  [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  [Guid("0000010E-0000-0000-C000-000000000046")]
  public interface IDataObject
  {
    void GetData([In] ref FORMATETC format, out STGMEDIUM medium);
    void GetDataHere([In] ref FORMATETC format, ref STGMEDIUM medium);
    [PreserveSig]
    int QueryGetData([In] ref FORMATETC format);
    [PreserveSig]
    int GetCanonicalFormatEtc([In] ref FORMATETC formatIn, out FORMATETC formatOut);
    void SetData([In] ref FORMATETC formatIn, [In] ref STGMEDIUM medium,
      bool release);

    IEnumFORMATETC EnumFormatEtc(DATADIR direction);
    [PreserveSig]
    int DAdvise([In] ref FORMATETC pFormatetc, ADVF advf, IAdviseSink adviseSink, out int connection);
    void DUnadvise(int connection);
    [PreserveSig]
    int EnumDAdvise(out IEnumSTATDATA enumAdvise);
  }

As you can see, there are lots of other types and interfaces in there. All in all there are nine further interfaces, six structs and six enumerations needed to merely define this interface. I did all of it, but when I try to run the code I get the following error:



The error message is "Invalid managed / unmanaged type combination" - which is refered to on stack overflow with the solution that the struct layout must be set to sequential. I felt that this was not my problem but I tried it - with no luck.

What makes me wonder is the second part of the error message. It tells us that marshalling from and to COM interface pointer is not supported. As far as I can see this is a limitation of P/Invoke in Silverlight - but I can find no reference elsewehere on the net. All P/Invoke samples call rather simple functions that accept only primitive data types.

Anyway I have uploaded the whole source code so anyone who feels lucky today can give it a try...

Freitag, 27. April 2012

Silverlight DataBinding und NULL

I recently noticed that, if you have an ObservableCollection<Something> in Silverlight bound to an ItemsControl with an explicit DataTemplate attached to it, that if you insert a NULL reference in to the collection you get the following error message:


Zeile: 1587
Fehler: Unhandled Error in Silverlight Application
Code: 4004   
Category: ManagedRuntimeError      
Message: System.Collections.Generic.KeyNotFoundException: Der angegebene Schlüssel war nicht im Wörterbuch angegeben.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at System.Windows.ResourceManagerWrapper.GetResourceForUri(Uri xamlUri, Type componentType)
    



While this seems cryptic in the first place, it still makes perfectly sense: for the type of object you add there is no something in the resource dictionaries to display it - hence the error.

The ugly thing is, that the error causes Silverlight to crash completely. A registered ApplicationUnhandledException handler just setting e.Handled = true does not seem to help either. So if you add something to a bound collection always check for null.

Maybe this saves some of you some time...

Cheers,
Tobias.

Samstag, 31. März 2012

Team Build Anpassungen

Besser spät als nie - hier die Demos aus meinem Vortrag zum Thema TFS Team Build Anpassungen, für alle die selber Anpassungen planen.

Bei Fragen fragen - ansonsten happy builiding :-)

Build Workflow Demos