Search code examples
visual-studiomsbuildcsprojcilsln-file

MSBuild Ignore absent <TargetFrameworks> for every .csproj in .sln?


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?


Solution

  • 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)