编辑3: 看起来我的尝试不被支持;在不同的配置之间“共享”project.json文件实际上是不可能的。我将用如何在.NET Core PCL中指向另一个project.json位置?替换这个问题。
编辑2: 是的,我的猜测是正确的。 ProjectJson
和ProjectLockJson
并不是特殊的MSBuild属性,它们的值被用于另一个导入的MSBuild项目中进行实际工作。当我有更新时(希望以答案的形式),我会发布更多信息。
编辑: 我已经将整个项目发布到GitHub,这样你们就可以获取重现了。只需克隆存储库,在VS中打开它并开始构建,您应该会遇到错误。
原始帖子
我正在尝试创建一个基于.NET Core的便携式类库。我正在尝试关联多个project.json文件与我的csproj。这是我的目录结构:
LibFoo
|
---- LibFoo.csproj
|
---- project.json
|
---- Platforms
|
---- Net45
| |
| ---- project.json
|
---- Profile32
|
---- project.json
我有两个 MSBuild 平台(除了 AnyCPU),即
Net45
和Profile32
。基本上,当它设置为 .NET Framework 4.5 时,我希望它编译包括根目录下的 project.json,和 Platforms/Net45
中的 project.json。当它被设置为 Profile32
时,我希望它在 Platforms/Profile32
中使用 project.json 来编译。我的问题是:如何在 MSBuild 中使这个工作?以下是我的
csproj
文件的相关代码片段:<ItemGroup Condition=" '$(Platform)' == 'Net45' ">
<!-- Target WPF apps -->
<TargetPlatform Include=".NETFramework, Version=4.5" />
</ItemGroup>
<ItemGroup Condition=" '$(Platform)' == 'Profile32' ">
<!-- Target Windows 8.1 Universal apps -->
<TargetPlatform Include="Windows, Version=8.1" />
<TargetPlatform Include="WindowsPhoneApp, Version=8.1" />
</ItemGroup>
<ItemGroup>
<None Include="Platforms\Net45\project.json" />
<None Include="Platforms\Profile32\project.json" />
</ItemGroup>
<PropertyGroup>
<ProjectJsonRoot>Platforms\$(Platform)</ProjectJsonRoot>
<ProjectJson>$(ProjectJsonRoot)\project.json</ProjectJson>
<ProjectLockJson>$(ProjectJsonRoot)\project.lock.json</ProjectLockJson>
</PropertyGroup>
<ItemGroup>
<!-- Include a common project.json for shared configs -->
<None Include="project.json" />
</ItemGroup>
由于某种原因,我发现
ProjectJson
和ProjectLockJson
部分似乎无法正常运作。我怀疑它们是问题的根源,因为在MSBuild中找不到官方文档,但CoreFX在其csproj文件中似乎可以很成功地使用它。我做错了什么吗?
project.json
文件,其中提到了不同的运行时。还有一个公共部分。 - moswald