如何指向 .NET Core PCL 中的不同 project.json 位置?

How to point to a different project.json location in a .NET Core PCL?

假设您有一个 .NET Core PCL,它应该针对多个平台进行编译。由于基于 csproj 的项目一次仅支持针对一个平台进行编译,因此您无法共享 project.json。因此,您的目录结构如下所示:

LibFoo
|
---- LibFoo.csproj
|
---- Platforms
     |
     ---- net45
     |    |
     |    ---- project.json
     |
     ---- netcore451
          |
          ---- project.json

您还有两个 MSBuild 目标平台:Net45NetCore451。为 Net45 构建时,您希望将项目文件包含在 Platforms/net45 中,而对于 NetCore451(顺便说一下,这是 Windows 8.1),您希望将项目文件包含在netcore451.

您将如何在 MSBuild 中实现它?这是我目前所拥有的:

<PropertyGroup>
  <ProjectJsonRoot>Platforms$(Platform.ToLower())</ProjectJsonRoot>
  <ProjectJson>$(ProjectJsonRoot)\project.json</ProjectJson>
</PropertyGroup>

<!-- Now $(ProjectJson) is set to the project.json location,
     what do I do to 'register' it with the compiler? -->

TL;DR: 如果 project.json 与 csproj 文件不在同一位置,您将如何将其设置为不同的位置?

感谢您的帮助。

如果您查看 AutoMapper repo,您可以看到 Jimmy Bogard 如何构建代码,其中 csproj 文件针对 "older" 项目类型。

嗯,很遗憾,您似乎必须创建自定义 MSBuild 任务才能执行此操作:

https://github.com/dotnet/corefx/issues/6169

我最终只是按照@Nyegaard 的回答写了多个 csproj 文件。