title: MSBuild incorrectly resolves references in custom build target
body: <p>I had to create a custom MSBuild Target, because I have multiple CS files with naming convention and all files (mostly 1-3 files) have to be compiled into a single assembly. To make it simple, let's make an assumption there is 1 file per DLL. It means there are:</p>
  
  <pre><code>files/file1.cs
  files/file2.cs
  files/file3.cs
  </code></pre>
  
  <p>and in the output there should be File1.dll, File2.dll File3.dll</p>
  
  <p>So I created a custom MSBuild target, which looks like:</p>
  
  <pre><code>&lt;ItemGroup&gt;
      &lt;CSFile Include="file\*.cs" Exclude="" /&gt;
  &lt;/ItemGroup&gt;
  
  &lt;ItemGroup&gt;
      &lt;Reference Include="System.dll"/&gt;
      &lt;Reference Include="..\libs\customdll.dll"/&gt;
  &lt;/ItemGroup&gt;
  
  &lt;Target Name="CompileFiles" Inputs="@(CSFile)" Outputs="$(OutputPath) (CSFile.Filename).dll" &gt;
      &lt;CSC Sources="%(CSFile.Identity)" TargetType="library" OutputAssembly="$(OutputPath)%(CSFile.Filename).dll" References="@(Reference)"/&gt;
  &lt;/Target&gt;
  </code></pre>
  
  <p>And it worked at some point, but now when I want to hook some Nuget packages to it (it's not related to NuGet itself, but it appeared when I tried to change some references paths) and </p>
  
  <pre><code>&lt;Reference Include="..\libs\customdll.dll"/&gt;
  </code></pre>
  
  <p>Is changed to </p>
  
  <pre><code>&lt;Reference Include="customdll"/&gt;
    &lt;HintPath&gt;..\libs\customdll.dll&lt;/HintPath&gt;
  &lt;/Reference&gt;
  </code></pre>
  
  <p>It simply doesn't work. It looks like MSBuild doesn't resolve references correctly and only uses value in "Include" attribute. It doesn't check HintPaths, System paths etc. Moreover, when I try to add <code>DependsOnTargets="ResolveAssemblyReferences"</code> to the <code>Target</code> then I see full paths in references when <code>CSC</code> is invoked (when <code>@(Reference)</code> is changed to <code>@(ReferencePath)</code>), but surprisingly some basic references like <code>System</code> or <code>System.Core</code> etc. seem to be included multiple times and compiler complains that I have to remove duplicates. Even if I remove them from the <code>&lt;ItemGroup&gt;&lt;Reference&gt;..</code> the error is still the same.</p>
  
  <p>So generally there are 2 kinds of errors. First that basically says <code>Metadata file</code>System<code>could not be found</code> when I don't use that <code>ResolveAssemblyReferences</code> target from common targets in Microsoft.CSharp, which basically means it cannot resolve references and the second error is when I use it and references are resolved correctly, but libs are included somehow multiple times and it still cannot be compiled.</p>
  
  <p>Any idea how to fix that? or maybe how should my MSBuild target look like to achieve a goal which is DLL per some criteria, without full working CSPROJ genrated by VisualStudio.</p>
  
  <p>I've tried MSBuild tools 4.0, 12.0. and various combinations of .NET4.0/.NET4.5 target frameworks.</p>