Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Msbuild NoTargets csproj requires TargetFramework?

Tags:

msbuild

csproj

I want to package some tools as a nuget and am using the Microsoft.Build.NoTargets project SDK format to achieve the same.

As mentioned in the docs, NoTargets is used when the project file does not compile any assembly. However, it needs a TargetFramework property to be set.

msbuild fails with NETSDK1013 if I don't specify some TargetFramework property.

Why does msbuild mandate that TargetFramework be specified for the NoTargets SDK csproj?

like image 642
shekhar Avatar asked Sep 15 '25 04:09

shekhar


1 Answers

Currently this is required for it to load in VS: VS checks if the project contains TargetFramework or TargetFrameworks in the xml to load sdk-based projects in the "new" project system (the thing that powers the IDE integration of the project). Otherwise it would use the legacy system that would not understand the features the SDK uses and either not load or give you a bad experience.

The MSBuild errors could be fixed in the SDK by defaulting the property but that will still fail IDE integrations.

Also note that the SDK imports other SDKs that are meant for .NET projects (language-independent over F#/C#/VB) and so you should get features like NuGet restore or packing working without much friction when a TargetFramework is set (even if it could be defaulted to whatever the SDK is basdded on in the NoTargets itself as mentioned)

like image 58
Martin Ullrich Avatar answered Sep 17 '25 21:09

Martin Ullrich