title: How to get a list of nuget packages installed via MSBuild macro?
body: <p>From following question <a href="https://stackoverflow.com/questions/22363960/how-do-i-list-all-installed-nuget-packages">How do I list all installed NuGet packages?</a></p>
  <p>I need to get a list of nuget packages from MSBuild itself.</p>
  <p>What I try to do:</p>
  <pre><code>&lt;Target Name=&quot;test&quot; AfterTargets=&quot;ResolveReferences&quot;&gt;
          &lt;ItemGroup&gt;
    &lt;BuildOutputInPackage Include=&quot;@(ReferenceCopyLocalPaths)&quot;/&gt;
  &lt;/ItemGroup&gt;
  
      &lt;Message Text=&quot;Files @(BuildOutputInPackage -&gt; '%(identity)', ', ')&quot; Importance=&quot;high&quot;/&gt;
  
  &lt;/Target&gt;
  </code></pre>
  <p>Above code return all references whether its nuget or project references dlls. How exactly to return a list of nuget package that currently project *.csproj used?</p>
  <p>Format i.e:   <code>packageid:Portable.BouncyCastle version = &quot;1.9.0&quot;</code></p>
  <p>I use old classic non-sdk csproj template and .NET 4.8 and <code>&lt;PackageReference&gt; not packages.config files.</code></p>
  <p>Its very bad to read *.csproj and do regex to get a list of &lt;packageReferences. Maybe there's a recommended MSBuild macro to do this like code shown above &lt;Target....</p>