<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>andreas-schlapsi.at &#187; MSBuild</title>
	<atom:link href="http://www.andreas-schlapsi.at/tag/msbuild/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andreas-schlapsi.at</link>
	<description>Software-Entwicklung, .NET &#38; Co.</description>
	<lastBuildDate>Sat, 17 Sep 2011 16:28:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Auswertung von ItemGroups in msbuild</title>
		<link>http://www.andreas-schlapsi.at/2006/10/02/auswertung-von-itemgroups-in-msbuild/</link>
		<comments>http://www.andreas-schlapsi.at/2006/10/02/auswertung-von-itemgroups-in-msbuild/#comments</comments>
		<pubDate>Mon, 02 Oct 2006 20:11:17 +0000</pubDate>
		<dc:creator>Andreas Schlapsi</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[MSBuild]]></category>

		<guid isPermaLink="false">http://www.andreas-schlapsi.at/2006/10/02/auswertung-von-itemgroups-in-msbuild/</guid>
		<description><![CDATA[Neulich hatte ich das Problem, dass ItemGroups in msbuild offenbar einmal zu Beginn ausgewertet werden und danach die Liste der Items bis zum Ende des Builds nicht mehr aktualisiert wird. Wenn während des Builds Verzeichnisse oder Dateien gelöscht bzw. erzeugt werden, stimmt der Inhalt der ItemGroup nicht mehr mit dem tatsächlichen Dateisysteminhalt überein. Normalerweise ist [...]]]></description>
			<content:encoded><![CDATA[<p>Neulich hatte ich das Problem, dass ItemGroups in msbuild offenbar einmal zu Beginn ausgewertet werden und danach die Liste der Items bis zum Ende des Builds nicht mehr aktualisiert wird. Wenn während des Builds Verzeichnisse oder Dateien gelöscht bzw. erzeugt werden, stimmt der Inhalt der ItemGroup nicht mehr mit dem tatsächlichen Dateisysteminhalt überein.<br />
<span id="more-6"></span><br />
Normalerweise ist das kein Problem, weil erstens der Source-Code zu Beginn feststeht und diese Dateien während des Build-Prozesses nicht gelöscht werden und zweitens Build-Artefakte, die in den nächsten Buildsteps weiterverarbeitet werden, als Output-Parameter der Tasks zur Verfügung stehens.</p>
<p>Ein Problem hat man allerdings, wenn man Tasks verwendet, die die erzeugten Dateien nicht als Output-Parameter zur Verfügung stellen (können) und diese Dateien weiterverarbeitet werden sollen.</p>
<p>Im folgenden Code-Snippet werden rekursiv alle Namen von C#-Quellcodedateien ausgegeben, ein Verzeichnis gelöscht und danach wieder alle C#-Dateinamen ausgegeben:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;project</span> <span style="color: #000066;">DefaultTargets</span>=<span style="color: #ff0000;">&quot;TestItems&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;...&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;itemGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;myItems</span> <span style="color: #000066;">Include</span>=<span style="color: #ff0000;">&quot;**.cs&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/itemGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;TestItems&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;@(MyItems)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;removeDir</span> <span style="color: #000066;">Directories</span>=<span style="color: #ff0000;">&quot;TestDir&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;@(MyItems)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Auch nach dem Löschen des Verzeichnisses sind alle Dateien dieses Verzeichnisses in der ItemGroup &#8220;MyItems&#8221; enthalten.</p>
<p>Um die ItemGroups aktuell zu halten, kann man den CreateItem-Task verwenden:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;project</span> <span style="color: #000066;">DefaultTargets</span>=<span style="color: #ff0000;">&quot;TestItems&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;...&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;itemGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;myItems</span> <span style="color: #000066;">Include</span>=<span style="color: #ff0000;">&quot;**.cs&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/itemGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;TestItems&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;@(MyItems)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;removeDir</span> <span style="color: #000066;">Directories</span>=<span style="color: #ff0000;">&quot;TestDir&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;createItem</span> <span style="color: #000066;">Include</span>=<span style="color: #ff0000;">&quot;**.cs&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;output</span> <span style="color: #000066;">TaskParameter</span>=<span style="color: #ff0000;">&quot;Include&quot;</span> <span style="color: #000066;">ItemName</span>=<span style="color: #ff0000;">&quot;CurrentItems&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/createItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;@(MyItems)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>In einigen Situationen ergeben sich daraus ziemlich unleserliche Build-Skripts. Doch sollte man sich dann überlegen, ob msbuild das richtige Tool ist.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andreas-schlapsi.at/2006/10/02/auswertung-von-itemgroups-in-msbuild/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

