1

我为一种名为 clojure 的编程语言创建了一个自定义项目类型(cljproj 而不是 csproj)。当项目编译时,它会输出多个 .dll 文件以及一些依赖的 .clj 文件。

这是通过覆盖 cljproj 文件中的默认 CoreCompile 目标来完成的。它基本上将所有需要编译的文件复制到 bin 目录,然后执行一个单独的应用程序来编译它们。

<Target Name="CoreCompile">
  <PropertyGroup>
    <ClojureNamespaces>@(Compile -> '%(RelativeDir)%(Filename)', ' ')</ClojureNamespaces>
  </PropertyGroup>
  <Copy SourceFiles="@(Compile)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" DestinationFiles="@(Compile -> '$(OutDir)%(RelativeDir)%(Filename)%(Extension)')" />
  <Exec WorkingDirectory="$(OutDir)" Command="&quot;$(ClojureRuntimesDirectory)\$(ClojureVersion)\Clojure.Compile&quot; $(ClojureNamespaces.Replace('\', '.'))" />
</Target>

我已将 ac# 项目 (csproj) 的引用添加到我的 clojure 项目 (cljproj) 中。

<ProjectReference Include="..\Clojure ASP.Net MVC Controller Library1\Clojure ASP.Net MVC Controller Library1.cljproj">
  <Project>{8fe1995b-4b6d-4911-b563-a759467fdf53}</Project>
  <Name>Clojure ASP.Net MVC Controller Library1</Name>
</ProjectReference>

默认情况下,Visual Studio 不能正确解析项目引用,因为它假定只有一个输出 Clojure ASP.Net MVC Controller Library1.dll。实际输出文件的示例是 MvcApplication1.Controllers.HomeController.dll 和 HomeController.clj

我想在不对 C# .csproj 文件进行任何更改的情况下完成这项工作,以便可以轻松地从任何 .csproj 文件中引用 .cljproj 。

我尝试通过覆盖 GetTargetPath 目标来解决项目引用。

<Target Name="GetTargetPath" DependsOnTargets="$(GetTargetPathDependsOn)" Returns="@(TargetPath)">
  <ItemGroup>
    <TargetPath Include="$(TargetDir)\**\*.dll" />
    <!-- <TargetPath Include="$(TargetDir)\**\*.clj" /> -->
  </ItemGroup>
</Target>

如果我使用 *.dll 设置 TargetPath,它会起作用并将 .dll 文件复制到 c#.csproj 输出目录。它甚至将 .pdb 文件复制到该目录,尽管我没有将它们添加到 TargetPath。但是,如果我取消注释 *.clj TargetPath,CSC 会抱怨 .clj 文件已损坏(可能是因为它们是纯文本,而不是 .net 程序集)。

我很高兴使用复制命令而不是覆盖 TargetPath,但是我不确定将哪个变量用于将它们输出到的目录,因为 $(outdir) 给了我自定义项目 (.cljproj) 的 bin,而不是尝试解析项目引用 (.csproj) 的 c# 项目的 bin。我不确定除了 GetTargetPath 还需要覆盖什么其他目标,因为在编译 c# (.csjproj) 项目时不会调用大多数 clojure 项目 (.cljproj) 目标,例如: .cljproj:AfterBuild 仅在直接编译 cljproj 时调用,不是在编译具有对 .cljproj 的项目引用的 .csproj 时。

4

1 回答 1

2

我能够通过覆盖 GetCopyToOutputDirectoryItems 目标来使其工作。

<Target Name="GetCopyToOutputDirectoryItems" Returns="@(CopyToOutputDirectoryItemsWithTargetPath)">
  <ItemGroup>
    <CopyToOutputDirectoryItems Include="$(TargetDir)\**\*.clj">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </CopyToOutputDirectoryItems>
  </ItemGroup>
  <AssignTargetPath Files="@(CopyToOutputDirectoryItems)" RootFolder="$(TargetDir)">
    <Output TaskParameter="AssignedFiles" ItemName="CopyToOutputDirectoryItemsWithTargetPath" />
  </AssignTargetPath>
</Target>
于 2013-03-18T17:58:20.800 回答