title: How make MSBuild build custom target specified in csproj building sln?
body: <p>I am facing an issue with <code>MSBuild</code> I can't overcome it by myself. As a result I rely on community's wisdom.</p>
  
  <p><strong>The real situation I'm having troubles with</strong> </p>
  
  <p>I have a soluiton file containing several projects with dependencies to other projects in same solution. I'd like to append a custom target to one of the project's csproj file and build it from the command line. It will allow me to make all the necessary output binaries for this project for further processing during the building of the custom target. But the main thing is that I can't figure out how to do it, googling doesn't help either.</p>
  
  <p><strong>Simplification</strong></p>
  
  <p>To make thing simplier I decided to make a new C# console project, add a simple custom target to the project's file and try to make it build. Still no success! Here what I've done so far:</p>
  
  <ol>
  <li><p>Created a solution app with a default console project coreapp. This gaves me at least two files:</p>
  
  <ul>
  <li>app.sln </li>
  <li>coreapp\coreapp.csproj</li>
  </ul></li>
  <li><p>Modified coreapp.csproj with addition of my custom target inside of the Project tag</p>
  
  <pre><code>&lt;Target Name="SampleTarget"&gt;
    &lt;Message Text="This is a SampleTarget" /&gt;
  &lt;/Target&gt;
  </code></pre></li>
  <li><p>Run on the command line the following command</p>
  
  <p><code>%windir%\Microsoft.NET\framework\v3.5\msbuild.exe app.sln /t:coreapp:SampleTarget</code></p>
  
  <p>or even</p>
  
  <p><code>%windir%\Microsoft.NET\framework\v3.5\msbuild.exe app.sln /t:coreapp.csproj:SampleTarget</code></p></li>
  </ol>
  
  <p><strong>Results</strong></p>
  
  <p>No luck, facing the error </p>
  
  <p><code>MSB4057: The target "coreapp.csproj:SampleTarget" does not exist in the project.</code></p>
  
  <p>I suspect that <code>MSBuild</code> thinks somehting fundamentally different from what I want it to think...</p>
  
  <p>BEsides that, I also tried to set on the same command line the environment variable MSBuildEmitSolution=1 to force msbuild dump a temporary solution file it creates while processing the solution. In this file, indeed, no such target. However I guess it isn't the reason because I asked msbuild to build coreapp.proj where target SampleTarget really resides.</p>
  
  <p>The question is how to build SampleTarget in this simplified scenario using solution file since potencially it can contain dependencies for the project containing this SampleTarget target?</p>
  
  <p>I'd be greatful for any sort of help or firection for further investigation!</p>