applejag / Newtonsoft.Json-for-Unity

Newtonsoft.Json (Json.NET) 10.0.3, 11.0.2, 12.0.3, & 13.0.1 for Unity IL2CPP builds, available via Unity Package Manager
https://github.com/jilleJr/Newtonsoft.Json-for-Unity
MIT License
1.16k stars 131 forks source link

Bug: MSBuild doesn't build all variants #45

Open applejag opened 4 years ago

applejag commented 4 years ago

Expected behavior

Building with MSBuild either via dotnet build, MSBuild.exe, or via Visual Studio 2019 results in all the different DLLs used in the package:

/bin/Debug/unity-aot/Newtonsoft.Json.dll
/bin/Debug/unity-standalone/Newtonsoft.Json.dll
/bin/Debug/unity-editor/Newtonsoft.Json.dll
/bin/Debug/unity-portable/Newtonsoft.Json.dll
/bin/Debug/unity-tests/Newtonsoft.Json.dll

Actual behavior

Only some build. Sometimes it even takes multiple builds to get the most builds. But never the full list.

The missing build DLLs are:

/bin/Debug/unity-aot/Newtonsoft.Json.dll
/bin/Debug/unity-standalone/Newtonsoft.Json.dll

Steps to reproduce

Details

Host machine OS running Unity Editor πŸ‘‰ Windows

Unity build target πŸ‘‰ N/A

Newtonsoft.Json-for-Unity package version πŸ‘‰ 12.0.301

I was using Unity version πŸ‘‰ N/A

Checklist

applejag commented 4 years ago

Suggested solution is to abuse the MSBuild Batching feature.

I successfully did a small sample in the jilleJr/Newstonsoft.Json-for-Unity.Converters repo to target multiple files after a build (https://github.com/jilleJr/Newtonsoft.Json-for-Unity.Converters/blob/880c3d350f1eb3832d553dd0003e245df5b1e520/Src/Newtonsoft.Json.UnityConverters.Tests/Newtonsoft.Json.UnityConverters.Tests.csproj).

I wonder if the same technique can be applied to force multiple builds of the same target framework, as the AOT, Standalone, and Editor builds all use .NET Standard 2.0.

applejag commented 4 years ago

Nah abusing the Platform targets seems much more appropriate. There should be no harm in defining a platform for AOT, one for Standalone, one for Editor, etc. Then rely on the "Batch Build" feature to build them all. Links:

To fix the TargetFramework issue, maybe that could be resolved with having platform-specific target frameworks? Something like:

<Project Sdk="Microsoft.NET.Sdk">

  <Choose>
    <When Condition="'$(Platform)'=='Tests'">
      <PropertyGroup>
        <TargetFramework>net46</TargetFramework>
      </PropertyGroup>
    </When>
    <When Condition="'$(Platform)'=='Portable'">
      <PropertyGroup>
        <TargetFramework>portable-net45+win8+wpa81+wp8</TargetFramework>
      </PropertyGroup>
    </When>
    <Otherwise>
      <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
      </PropertyGroup>
    </Otherwise>
  </Choose>

</Project>

(MSDN on the <Choose> element: https://docs.microsoft.com/en-us/visualstudio/msbuild/choose-element-msbuild?view=vs-2019)