• Blog
  • Info Support
  • Career
  • Training
  • International Group
  • Info Support
  • Blog
  • Career
  • Training
  • International Group
  • Search
logo InfoSupport
  • Latest blogs
  • Popular blogs
  • Experts
      • All
      • Bloggers
      • Speakers
  • Meet us
  • About us
    • nl
    • en
    • .NET
    • 3D printing
    • Advanced Analytics
    • Agile
    • Akka
    • Alexa
    • Algorithms
    • Api's
    • Architectuur
    • Artificial Intelligence
    • ATDD
    • Augmented Reality
    • AWS
    • Azure
    • Big Data
    • Blockchain
    • Business Intelligence
    • Chatbots
    • Cloud
    • Code Combat
    • Cognitive Services
    • Communicatie
    • Containers
    • Continuous Delivery
    • CQRS
    • Cyber Security
    • Dapr
    • Data
    • Data & Analystics
    • Data Science
    • Data Warehousing
    • Databricks
    • DataOps
    • Developers life
    • DevOps
    • Digital Days
    • Digital Twin
    • Docker
    • eHealth
    • Enterprise Architecture
    • Event Sourcing
    • Hacking
    • Infrastructure & Hosting
    • Innovatie
    • Integration
    • Internet of Things
    • Java
    • Machine Learning
    • Microservices
    • Microsoft
    • Microsoft Bot Framework
    • Microsoft Data Platform
    • Mobile Development
    • Mutation Testing
    • Open source
    • Pepper
    • Power BI
    • Privacy & Ethiek
    • Python
    • Quality Assistance & Test
    • Quality Assurance & Test
    • Requirements Management
    • Scala
    • Scratch
    • Security
    • SharePoint
    • Software Architecture
    • Software development
    • Software Factory
    • SQL Server
    • SSL
    • Start-up
    • Startup thinking
    • Stryker
    • Test Quality
    • Testing
    • TLS
    • TypeScript
    • Various
    • Web Development
    • Web-scale IT
    • Xamarin
    • All
    • Bloggers
    • Speakers
Home » MsBuild metadata
  • MsBuild metadata

    • By Martijn Beenes
    • .NET 17 years ago
    • .NET 0 comments
    • .NET .NET
    MsBuild metadata

    Last week I came across an interesting problem with MsBuild. I recently blogged about Web Deployment projects in a Team Foundation build. A big advantage of the Web Deployment projects is, that the website/web application output files are copied to a sub directory rather than being dropped in the build output directory which is the case for all other project types.


    Unfortunately this behavior was not enough for the build I was working on.


     


    In a TeamBuild, only containing Web Application projects and Web Deployment projects, I needed to copy the published websites to a new directory and add an extra subdirectory into the path.  


    Let me clarify this with an example: I needed to copy “c:Build_PublishedWebsitesWebSite1***.*” to “c:MyWebApplicationsWebSite1wwwroot***.*”.


     


    The key to solving this problem is getting a list of all the websites in the _PublishedWebSites directory and linking them to a collection of files that are contained in those website directories. Unfortunatly this can’t be accomplished in a single MsBuild statement. But I can be solved by using metadata on items and item collections.


     


    MetaData


    Metadata is extra information about items in a collection. This metadata can be used to manipulate the item collection.


    Each item in an item collection has some metadata that can be used. For instance each item has a metadata property FullPath specifying the full path to the item on disk. Here you can find a list of the well-known item metadata that is associated with each item in an item collection.


    It is also possible to add your own metadata to items in a collection.


     


    I used this feature in the build I was working on to create an item collection in which each item had some custom metadata.


    Lets take a look at the example again. The first step to take is getting a list of all the websites in the _PublishedWebSites directory.


    Just create a new item collection, selecting all the (first level) directories under the _PublishedWebSites directory. (A pre condition is that the directories you want to select must contain at least 1 file. Empty directories or directories only containing directories themselves are ignored by the CreateItem task.)


     



    <CreateItem Include=“c:Build_PublishedWebsites**“>


    <Output ItemName=“PublishedWebSites” TaskParameter=“Include” />


    </CreateItem>


     


    The new item collection contains all the files that are available in the directories. Each item will have some metadata we need to use. One being: RelativeDir. This metadata property holds the directory (part of a path) that corresponds with the * or ** specified in the Include filter when creating the item collection. In the example, it will contain “WebSite1”.


     


    Next we need an item collection of all the files that are part of the websites, grouped per website. This can be accomplished by selecting all the files and directories in the directories we collected in the PublishedWebSites item collection.


    By only using the RootDir and Directory metadata properties, it is possible to create an item collection containing all the files. When creating a new item collection based on a previous created item collection, the metadata properties of the previous created item collection must be copied to the new collection (if you need to use them again). In case of the example, the RecursiveDir property must be copied.
    It is not possible to overwrite the well-known metadata properties so a new metadata property must be created.


    By adding this metadata it is possible to ensure that the directory name of the website directory is preserved.


     



    <CreateItem


    Include=“@(PublishedWebSites->’%(RootDir)%(Directory)***.*’)“


          AdditionalMetadata=“WebSiteDir=%(RecursiveDir);“ >


          <Output ItemName=“FilesToCopy“ TaskParameter=“Include“/>


    </CreateItem>


     


    The FilesToCopy item collection will contain all the files that must be copied, and will have all the relevant metadata to create the destination path.


     



    <Copy


    SourceFiles=“@(FilesToCopy)“


    DestinationFiles=“@(FilesToCopy->’c:MyWebApplications%(WebSiteDir)wwwroot%(RecursiveDir)%(FileName)%(Extension)’)“


    />


     


    This is just one example of how you can use metadata on items and it shows that the use of metadata can be a powerful way to solve specific problems.

    Share this

Martijn Beenes

View profile

Related IT training

Go to training website

Related Consultancy solutions

Go to infosupport.com

Related blogs

  • Configuring SQL Server encrypted connections using Powe…

    Configuring SQL Server encrypted connections using Powe… Léon Bouquiet - 1 month ago

  • Where to position SpecFlow in the Test Pyramid?

    Where to position SpecFlow in the Test Pyramid? Ronald Bosma - 4 months ago

  • Building a custom Kubernetes operator in C#

    Building a custom Kubernetes operator in C# Willem Meints - 8 months ago

Data Discovery Channel

  • Data+AI Summit 2023

  • Blijf je Azure cloud omgeving de baas met CloudXcellence

  • MLOps

Nieuwsbrief

* verplichte velden

Contact

  • Head office NL
  • Kruisboog 42
  • 3905 TG Veenendaal
  • T +31 318 552020
  • Call
  • Mail
  • Directions
  • Head office BE
  • Generaal De Wittelaan 17
  • bus 30 2800 Mechelen
  • T +32 15 286370
  • Call
  • Mail
  • Directions

Follow us

  • Twitter
  • Facebook
  • Linkedin
  • Youtube

Newsletter

Sign in

Extra

  • Media Library
  • Disclaimer
  • Algemene voorwaarden
  • ISHBS Webmail
  • Extranet
Beheer cookie toestemming
Deze website maakt gebruik van Functionele en Analytische cookies voor website optimalisatie en statistieken.
Functioneel Always active
De technische opslag of toegang is strikt noodzakelijk voor het legitieme doel het gebruik mogelijk te maken van een specifieke dienst waarom de abonnee of gebruiker uitdrukkelijk heeft gevraagd, of met als enig doel de uitvoering van de transmissie van een communicatie over een elektronisch communicatienetwerk.
Voorkeuren
De technische opslag of toegang is noodzakelijk voor het legitieme doel voorkeuren op te slaan die niet door de abonnee of gebruiker zijn aangevraagd.
Statistieken
De technische opslag of toegang die uitsluitend voor statistische doeleinden wordt gebruikt. De technische opslag of toegang die uitsluitend wordt gebruikt voor anonieme statistische doeleinden. Zonder dagvaarding, vrijwillige naleving door uw Internet Service Provider, of aanvullende gegevens van een derde partij, kan informatie die alleen voor dit doel wordt opgeslagen of opgehaald gewoonlijk niet worden gebruikt om je te identificeren.
Marketing
De technische opslag of toegang is nodig om gebruikersprofielen op te stellen voor het verzenden van reclame, of om de gebruiker op een website of over verschillende websites te volgen voor soortgelijke marketingdoeleinden.
Manage options Manage services Manage vendors Read more about these purposes
Voorkeuren
{title} {title} {title}