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

▼魔方 西西 提交于 2019-12-22 11:37:16

问题


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.


回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/35448622/how-to-point-to-a-different-project-json-location-in-a-net-core-pcl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!