【发布时间】:2016-02-17 00:57:13
【问题描述】:
编辑 3: 看起来我正在尝试做的事情不受支持;实际上不可能跨配置“共享” project.json 文件。我用How to point to a different project.json location in a .NET Core PCL?代替这个问题
编辑 2: 是的,我的怀疑是正确的。 ProjectJson 和 ProjectLockJson 实际上并不是特殊的 MSBuild 属性,它们的值正在另一个导入的 MSBuild 项目中用于执行实际工作。当我有更新时,我会在此发布更多信息(希望以答案的形式)。
编辑:我已经发布了整个项目to GitHub,所以你们可以得到一个复制品。只需 git clone 存储库,在 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 文件的相关sn-p:
<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 我起初尝试过,但我收到此错误:“包含 MSBuild 目标和道具文件的包无法完全安装在针对多个框架的项目中。”然后 VS 就决定忽略所有的 .cs 文件。
标签: c# .net msbuild asp.net-core dnx