msbuildcross-platformvisual-studio-2019uno-platformmultitargeting

VStudio always compiles all the TargetFrameworks for referenced multi-target projects, whatever head is specified for a build in Uno-platform solution


I'm working on a cross-platform application using the Uno Platform. The app consists of 5 standard head projects for my App and a dozen of referenced cross-platform libraries projects (Uno-platform cross-platform library projects, MSBuild.Sdk.Extras, VStudio 2019). Referenced project libraries have multi-target frameworks specified like: netstandard2.0;xamarinios10;xamarinmac20;MonoAndroid90;monoandroid10.0. Solution structure looks like this:

- SolutionApp
    - App.Droid
    - App.iOS
    - App.macOS
    - App.UWP
    - App.Wasm
    - App.Shared
    - MultiTargetLibrary1
    ...
    - MultiTargetLibraryN

The problem is that each time I rebuild any of the head app projects, VStudio rebuilds referenced projects for all the target frameworks available.

How to avoid a compilation of unnecessary target platforms? How can a referenced project get which head project has triggered a build? Is there any possibility to pass which exact target framework is needed in referenced project building from VStudio?

Example: I choose to rebuild App.iOS and it triggered a rebuild of referenced projects. I want projects with only 'xamarinios10' TargetFramework to be built.

If there are only a few target frameworks or projects compilation isn't slow, but with an increasing amount of referenced projects time extremely grows.

As I've got from msbuild reference: VStudio calls msbuild for each project on solution separately, so msbuild doesn't know which head project has triggered the build of the referenced project and which target platform is required.


Solution

  • This is a known Visual Studio 2019 issue, where all targets are built regardless of the actual head project being compiled.

    In the meantime, you can manually exclude some target frameworks when building the application, and use the solution filter feature of Visual Studio so that nuget does not complain about invalid project references. That way, you can make 4 filters, with each excluding the projects that are not used for the platform you're currently working on.