2

Say you have a .NET Core PCL that's supposed to compile for multiple platforms. Since csproj-based projects only support compiling for one platform at a time, you can't have a shared project.json. Thus, your directory structure looks like this:

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

You also have two MSBuild target platforms: Net45 and NetCore451. When building for Net45 you want to include the project file in Platforms/net45, and for NetCore451 (which is Windows 8.1, by the way) you want to include the one in netcore451.

How would you go about implementing this in MSBuild? Here is what I have so far:

<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: How would you set the project.json to a different location from your csproj file, if it isn't in the same location as it?

Thanks for helping.

James Ko
  • 32,215
  • 30
  • 128
  • 239

2 Answers2

1

If you look at the AutoMapper repo you can see how Jimmy Bogard have structured the code, where csproj files are targeting "older" project types.

James Ko
  • 32,215
  • 30
  • 128
  • 239
Nyegaard
  • 1,309
  • 3
  • 16
  • 24
  • Thanks for answering! Unfortunately, I don't think this answers my question. The repo you linked to uses multiple csproj files to target different platforms. My question is asking how to use multiple `project.json` files to achieve this affect. – James Ko Feb 17 '16 at 18:04
0

Well, unfortunately it looks as if you have to create a custom MSBuild task to do this:

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

I ended up just going with @Nyegaard's answer and writing multiple csproj files.

James Ko
  • 32,215
  • 30
  • 128
  • 239