<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[test blog]]></title><description><![CDATA[test blog]]></description><link>https://omar.aaouatif.ma</link><generator>RSS for Node</generator><lastBuildDate>Sat, 30 May 2026 04:24:27 GMT</lastBuildDate><atom:link href="https://omar.aaouatif.ma/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Comprendre MSBuild : le moteur de compilation derrière vos projets .NET]]></title><description><![CDATA[MSBuild est souvent perçu comme une boîte noire dans les projets .NET. Pourtant, le comprendre permet d'automatiser, personnaliser et optimiser vos builds. Voici un tour d'horizon structuré, avec des exemples pratiques.

1. Qu’est-ce que MSBuild ?
MS...]]></description><link>https://omar.aaouatif.ma/comprendre-msbuild-le-moteur-de-compilation-derriere-vos-projets-net</link><guid isPermaLink="true">https://omar.aaouatif.ma/comprendre-msbuild-le-moteur-de-compilation-derriere-vos-projets-net</guid><dc:creator><![CDATA[Omar Aaouatif]]></dc:creator><pubDate>Wed, 23 Jul 2025 19:39:14 GMT</pubDate><content:encoded><![CDATA[<blockquote>
<p><em>MSBuild est souvent perçu comme une boîte noire dans les projets .NET. Pourtant, le comprendre permet d'automatiser, personnaliser et optimiser vos builds. Voici un tour d'horizon structuré, avec des exemples pratiques.</em></p>
</blockquote>
<h2 id="heading-1-quest-ce-que-msbuild">1. Qu’est-ce que MSBuild ?</h2>
<p>MSBuild (Microsoft Build Engine) est l’outil utilisé par .NET et Visual Studio pour compiler, packager, tester et déployer vos projets. Il lit les fichiers <code>.csproj</code> ou <code>.vbproj</code>, qui sont en réalité des fichiers <strong>XML</strong> définissant les étapes du build.</p>
<h2 id="heading-2-structure-dun-fichier-csproj">2. Structure d’un fichier <code>.csproj</code></h2>
<p>Voici un exemple simple de fichier <code>.csproj</code> moderne :</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">Project</span> <span class="hljs-attr">Sdk</span>=<span class="hljs-string">"Microsoft.NET.Sdk"</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">PropertyGroup</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">OutputType</span>&gt;</span>Exe<span class="hljs-tag">&lt;/<span class="hljs-name">OutputType</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">TargetFramework</span>&gt;</span>net8.0<span class="hljs-tag">&lt;/<span class="hljs-name">TargetFramework</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">PropertyGroup</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">Project</span>&gt;</span>
</code></pre>
<h2 id="heading-3-ajout-de-proprietes-personnalisees">3. Ajout de propriétés personnalisées</h2>
<p>Vous pouvez définir vos propres propriétés dans le fichier <code>.csproj</code> :</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">PropertyGroup</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">MyCustomProperty</span>&gt;</span>HelloWorld<span class="hljs-tag">&lt;/<span class="hljs-name">MyCustomProperty</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">PropertyGroup</span>&gt;</span>
</code></pre>
<p>Ensuite, vous pouvez utiliser cette propriété dans un <code>Target</code> personnalisé comme suit :</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">Target</span> <span class="hljs-attr">Name</span>=<span class="hljs-string">"AfficherMessage"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">Message</span> <span class="hljs-attr">Text</span>=<span class="hljs-string">"Valeur : $(MyCustomProperty)"</span> <span class="hljs-attr">Importance</span>=<span class="hljs-string">"high"</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">Target</span>&gt;</span>
</code></pre>
<h2 id="heading-4-cibles-personnalisees-target">4. Cibles personnalisées (<code>Target</code>)</h2>
<p>Un <strong>Target</strong> représente une action ou un groupe d’actions que MSBuild peut exécuter.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">Target</span> <span class="hljs-attr">Name</span>=<span class="hljs-string">"AfficherMessage"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">Message</span> <span class="hljs-attr">Text</span>=<span class="hljs-string">"Build en cours..."</span> <span class="hljs-attr">Importance</span>=<span class="hljs-string">"high"</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">Target</span>&gt;</span>
</code></pre>
<p>Exécution depuis la ligne de commande :</p>
<pre><code class="lang-bash">dotnet msbuild -target:AfficherMessage
</code></pre>
<h2 id="heading-5-declencher-un-target-a-une-etape-du-build">5. Déclencher un <code>Target</code> à une étape du build</h2>
<p>Pour exécuter une cible <strong>avant le build</strong>, utilisez <code>BeforeTargets</code> :</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">Target</span> <span class="hljs-attr">Name</span>=<span class="hljs-string">"LogAvantBuild"</span> <span class="hljs-attr">BeforeTargets</span>=<span class="hljs-string">"Build"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">Message</span> <span class="hljs-attr">Text</span>=<span class="hljs-string">"Préparation du build..."</span> <span class="hljs-attr">Importance</span>=<span class="hljs-string">"high"</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">Target</span>&gt;</span>
</code></pre>
<h2 id="heading-6-utilisation-des-itemgroup">6. Utilisation des <code>ItemGroup</code></h2>
<p>Les <code>ItemGroup</code> servent à gérer des collections de fichiers ou d’éléments.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">ItemGroup</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">FichiersTexte</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"docs\*.txt"</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ItemGroup</span>&gt;</span>
</code></pre>
<p>Puis plus loin :</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">Target</span> <span class="hljs-attr">Name</span>=<span class="hljs-string">"ListerFichiers"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">Message</span> <span class="hljs-attr">Text</span>=<span class="hljs-string">"Fichier : %(FichiersTexte.Identity)"</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">Target</span>&gt;</span>
</code></pre>
<h2 id="heading-7-exemple-dun-build-conditionnel">7. Exemple d’un build conditionnel</h2>
<p>Avec l’attribut <code>Condition</code>, vous pouvez conditionner l’exécution :</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">PropertyGroup</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">DoAction</span>&gt;</span>true<span class="hljs-tag">&lt;/<span class="hljs-name">DoAction</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">PropertyGroup</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">Target</span> <span class="hljs-attr">Name</span>=<span class="hljs-string">"Conditionnel"</span> <span class="hljs-attr">Condition</span>=<span class="hljs-string">"'$(DoAction)' == 'true'"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">Message</span> <span class="hljs-attr">Text</span>=<span class="hljs-string">"Action activée !"</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">Target</span>&gt;</span>
</code></pre>
<h2 id="heading-8-execution-de-code-c-en-tache-personnalisee">8. Exécution de code C# en tâche personnalisée</h2>
<p>MSBuild permet d’écrire ses propres tâches en C# :</p>
<pre><code class="lang-csharp"><span class="hljs-keyword">using</span> Microsoft.Build.Framework;
<span class="hljs-keyword">using</span> Microsoft.Build.Utilities;

<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">HelloTask</span> : <span class="hljs-title">Task</span>
{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">bool</span> <span class="hljs-title">Execute</span>(<span class="hljs-params"></span>)</span>
    {
        Log.LogMessage(<span class="hljs-string">"Salut depuis C#!"</span>);
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    }
}
</code></pre>
<p>Ensuite, référence cette tâche compilée dans ton projet via une DLL MSBuild.</p>
<h2 id="heading-9-execution-sans-visual-studio">9. Exécution sans Visual Studio</h2>
<p>MSBuild fonctionne aussi en ligne de commande avec le SDK .NET :</p>
<pre><code class="lang-bash">dotnet msbuild MonProjet.csproj
</code></pre>
<p>Utile pour les environnements CI/CD et multiplateformes.</p>
<h2 id="heading-10-conclusion">10. Conclusion</h2>
<p>✅ Maîtriser MSBuild permet de :</p>
<ul>
<li>Personnaliser votre pipeline de build</li>
<li>Intégrer des étapes d’analyse statique, tests, packaging</li>
<li>Créer des builds reproductibles</li>
<li>Automatiser vos déploiements</li>
</ul>
<p>Même si l’interface de Visual Studio cache ces détails, MSBuild reste <strong>le vrai moteur sous le capot</strong>.</p>
<h2 id="heading-pour-aller-plus-loin">📚 Pour aller plus loin</h2>
<ul>
<li><a target="_blank" href="https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild">📘 Docs officielles MSBuild</a></li>
<li><a target="_blank" href="https://learn.microsoft.com/en-us/visualstudio/msbuild/how-to-write-a-task">🧠 Tâches personnalisées en C#</a></li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Test article]]></title><description><![CDATA[if (x is { Length: 10, Text: "hello" })
{
    Call();
}

test hello world welcome test no

1

2

3]]></description><link>https://omar.aaouatif.ma/test-article</link><guid isPermaLink="true">https://omar.aaouatif.ma/test-article</guid><dc:creator><![CDATA[Omar Aaouatif]]></dc:creator><pubDate>Wed, 23 Jul 2025 19:31:36 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1753298994925/b8dc820e-362f-4def-833e-fd3a2f10682b.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<pre><code class="lang-csharp"><span class="hljs-keyword">if</span> (x <span class="hljs-keyword">is</span> { Length: <span class="hljs-number">10</span>, Text: <span class="hljs-string">"hello"</span> })
{
    Call();
}
</code></pre>
<p>test hello <strong>world welcome</strong> <s>test</s> no</p>
<ul>
<li><p>1</p>
</li>
<li><p>2</p>
</li>
<li><p>3</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1753298946145/850d80ac-7b24-4c7b-bc7a-4ea9e640c9ad.gif" alt class="image--center mx-auto" /></p>
]]></content:encoded></item></channel></rss>