locked
Wildcards with <Import> RRS feed

  • Question

  • Is there any way to import all of the targets files matching a wildcard?  It would be nice if one could do this:

    <Import Project="Custom.After.Bentley.*.targets" />

    Since that doesn't work , is there some more elaborate incantation that can work?

     

     

    Wednesday, May 31, 2006 6:06 PM

Answers

  • Hi Bern,

    I don't think wildcards work with the Import element. I think this is generally done in a kind of recursive fashion. Just create a .targets file that contains all the <Import> elements you need 'so just a list of Import elements and nothing else), and Import this file into any other script you are creating.

    cheers,
    Stephane

    Wednesday, May 31, 2006 8:14 PM

All replies

  • Hi Bern,

    I don't think wildcards work with the Import element. I think this is generally done in a kind of recursive fashion. Just create a .targets file that contains all the <Import> elements you need 'so just a list of Import elements and nothing else), and Import this file into any other script you are creating.

    cheers,
    Stephane

    Wednesday, May 31, 2006 8:14 PM
  • You generally may not want do something like this because in that case you wouldn't have control on the order in which target files are imported other than having to name them in a particular order. In MSBuild the order of import of target files can have an impact on the build process in case there are properties/items/targets in them with same names across these target files.
    Thursday, June 1, 2006 2:25 AM
  • Found this thread when wanting to ask the same question...

    Any update on this chaps.  Seems like a useful piece of extensibility to me...  I was hoping that Import would became a child of Target - as ItemGroups and PropertyGroups did.

    N

    P.S.  I think a self-executing target would help in this instance which would dynamically write a proj file with the actual imports you want.

    I did ask about self-executing targets on this forum (something akin to a self-executing anonymous function in javascript i.e. something which executes at parse time) - but there appears to be no mechanism.

    The only alternative I can think is to have a Property function calling custom code (the downside being that one needs to set MSBUILDENABLEALLPROPERTYFUNCTIONS=1) which actually does the work.  But that is a nasty hack...

    N

    Thursday, July 18, 2013 8:54 AM
  • http://msdn.microsoft.com/en-us/library/92x05xfs.aspx

    "In the .NET Framework 4, MSBuild allows wildcards in the Project attribute. When there are wildcards, all matches found are sorted (for reproducibility), and then they are imported in that order as if the order had been explicitly set.

    This is useful if you want to offer an extensibility point so that someone else can import a file without requiring you to explicitly add the file name to the importing file. For this purpose, Microsoft.Common.Targets contains the following line at the top of the file."

    Hurrah!


    • Edited by LudwigHoff Wednesday, July 31, 2013 8:44 AM
    Wednesday, July 31, 2013 8:44 AM