Dotnet build of solution containing projects with different target frameworks

45 views Asked by At

I have a solution containing multiple projects. To simplify:

The Gui project targets net7.0-android and net7.0-windows10.0.19041.0

The Library project targets net7.0 and is referenced by the Gui project.

The problem is that I can't launch a solution-wide build, e.g. dotnet publish -f net7.0-android, because I'll get the infamous error:

error NETSDK1005: Assets file 'library\obj\project.assets.json' doesn't have a target for 'net7.0-android'.

But if I launch the build by explicitly passing the Gui project, it works: dotnet publish ./library/library.csproj -f net7.0-android

This workaround is quite clumsy and won't compile other projects that are not dependencies of the Gui one (e.g. the Tests project).

Is there a way to tell the compiler that "If a dependency doesn't target the passed framework, use net7.0 as default"?

Maybe I'm wrong, but it doesn't feel right to me to target multiple targets in the library project, since it's a generic library and the net7.0 target is just enough. Also, the Gui project build works exactly as I would expect, so the same behavior for the solution-wise build would be very appreciated.

0

There are 0 answers