1

The project that I've cloned locally uses the following dependencies:

<TargetFrameworks>netstandard2.0;MonoAndroid10.0;Xamarin.iOS10;Xamarin.Mac20;netcoreapp3.0;netcoreapp3.1;net40;net45;net46;net47;net48</TargetFrameworks>

I need to tell Visual Studio to ignore those frameworks and projects<->frameworks dependencies that aren't installed in my system and build only existing ones without manually deleting them from the whole solution and every project in the solution, without installing them and setting up. Let's say build .sln projects with netcoreapp3.1 if it's installed.

Is there a way to do this?

Ivan Silkin
  • 381
  • 1
  • 7
  • 15
  • 'build .sln projects with netcoreapp3.1 if it's installed.' and what should happen if both netcoreapp33.1 and netstandard2.0 are installed? In any case you will probably have to change all projects, because the logic for conditionally selecting the framework is going to have to be in the projects. – stijn Jan 18 '22 at 08:35
  • @stijn, a huge amount of target frameworks result in a huge amount of errors that these project dependencies produce, but still the github authors tend to implement as much as they possibly can, especially if their repository has a nuget package integration. Forking one results in an error chaos. – Ivan Silkin Jan 18 '22 at 19:48
  • 1
    I understand, but that does not answer my question; I'll rephrase: do you just want to be able to build for a specific framework, no matter how, or is it really so that you want msbuild to figure out automatically which framework(s) is/are installed and use that (and if yes: what should happen exactly if in fact you have multiple frameworks installed)? Thing is, answer to the first question could be simple, as in `msbuild my.sln /p:TargetFramework=xxx` will use xxx no matter what. The answer to the second is complicated probably. – stijn Jan 19 '22 at 08:31
  • stijn, your answer to the first one answers my question. – Ivan Silkin Jan 19 '22 at 08:44

1 Answers1

3

See documentation on TargetFrameworks: it is ignored when TargetFramework (singular) is specified hence you can build with the framework of choice using

msbuild my.sln /p:TargetFramework=netcoreapp3.1

(argueably, just specifying a bunch of possible frameworks hardcoded in the project files is not super user-friendly, would be better if the authors did that conditionally somehow)

stijn
  • 34,664
  • 13
  • 111
  • 163