title: Msbuild resolve project reference to custom project type
body: <p>I've created a custom project type (cljproj instead of csproj) for a programming language called clojure. When the project compiles it outputs multiple .dll files as well as some dependent .clj files.</p>
  
  <p>This is done by overriding the default CoreCompile target in the cljproj file. Which basically copies all files needing compilation to the bin directory and then executes a separate app to compile them.</p>
  
  <pre><code>&lt;Target Name="CoreCompile"&gt;
    &lt;PropertyGroup&gt;
      &lt;ClojureNamespaces&gt;@(Compile -&gt; '%(RelativeDir)%(Filename)', ' ')&lt;/ClojureNamespaces&gt;
    &lt;/PropertyGroup&gt;
    &lt;Copy SourceFiles="@(Compile)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" DestinationFiles="@(Compile -&gt; '$(OutDir)%(RelativeDir)%(Filename)%(Extension)')" /&gt;
    &lt;Exec WorkingDirectory="$(OutDir)" Command="&amp;quot;$(ClojureRuntimesDirectory)\$(ClojureVersion)\Clojure.Compile&amp;quot; $(ClojureNamespaces.Replace('\', '.'))" /&gt;
  &lt;/Target&gt;
  </code></pre>
  
  <p>I've added a reference from a c# project (csproj) to my clojure project (cljproj).</p>
  
  <pre><code>&lt;ProjectReference Include="..\Clojure ASP.Net MVC Controller Library1\Clojure ASP.Net MVC Controller Library1.cljproj"&gt;
    &lt;Project&gt;{8fe1995b-4b6d-4911-b563-a759467fdf53}&lt;/Project&gt;
    &lt;Name&gt;Clojure ASP.Net MVC Controller Library1&lt;/Name&gt;
  &lt;/ProjectReference&gt;
  </code></pre>
  
  <p>Visual Studio by default doesn't resolve the project reference correctly, because it assumes there will only be one output, Clojure ASP.Net MVC Controller Library1.dll. 
  Examples of the actual output files are MvcApplication1.Controllers.HomeController.dll and HomeController.clj</p>
  
  <p>I'd like to make this work without making any changes to the C# .csproj file, so that a .cljproj can easily be referenced from any .csproj file.</p>
  
  <p>My attempt to resolve the project reference is by overriding the GetTargetPath target.</p>
  
  <pre><code>&lt;Target Name="GetTargetPath" DependsOnTargets="$(GetTargetPathDependsOn)" Returns="@(TargetPath)"&gt;
    &lt;ItemGroup&gt;
      &lt;TargetPath Include="$(TargetDir)\**\*.dll" /&gt;
      &lt;!-- &lt;TargetPath Include="$(TargetDir)\**\*.clj" /&gt; --&gt;
    &lt;/ItemGroup&gt;
  &lt;/Target&gt;
  </code></pre>
  
  <p>If I set the TargetPath using *.dll, it works and copies the .dll files to the c#.csproj output directory. It even copies the .pdb files to that directory, although I didn't add them to the TargetPath. However, if I uncomment the *.clj TargetPath, CSC complains that the .clj files are corrupt (probably because they are plain text, not .net assemblies).</p>
  
  <p>I'm happy to use a copy command instead of overriding TargetPath, however I'm not sure which variable to use for the directory to output them to, because $(outdir) gives me the bin of my custom project (.cljproj) not the bin of the c# project trying to resolve the project reference (.csproj). I'm not sure what other target to override besides GetTargetPath, because most clojure project (.cljproj) targets are not called when compiling the c# (.csjproj) project, for example: .cljproj:AfterBuild is only called when compiling cljproj directly, not when compiling .csproj which has a project reference to .cljproj.</p>