mhutch / MonoDevelop.MSBuildEditor

Improved MSBuild editing support
Other
211 stars 24 forks source link

Some TFM (Target Framework Moniker) not recognized #213

Closed wherewhere closed 3 months ago

wherewhere commented 3 months ago

It recognizes net20 but not recognizes net2.0. image And this image And more... image image

mhutch commented 3 months ago

This should be fixed by #218 with the following exceptions:

wherewhere commented 3 months ago

netcore50 is not equal to uap10.0. It is a pure .NET platform without WinRT supports. You can build a netcore50 console app and it will running on .NET Framework. The moniker of netcore50 is .NETCore, Version=5.0 and uap10.0 is UAP, Version=10.0 Both netcore and uap are not supported by MSBuild SDK in default. It need to set by yourself. https://github.com/SharpAdb/AdvancedSharpAdbClient/blob/main/Directory.Build.props#L38-L62 .NET/WinRT for C++ projects should target to native. https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/main/Microsoft.Toolkit.Uwp.Notifications/Microsoft.Toolkit.Uwp.Notifications.csproj#L19-L39

mhutch commented 2 months ago

I did add netcore50 as a separate TFM shortname so that the editor can represent it in the form it was specified 🙂 https://github.com/mhutch/MonoDevelop.MSBuildEditor/pull/218/files#diff-f6022ed4ae947a7d938bee206bef2e5c20afd3f6a32a4b69e2aaffcc3cba1b2aR244

However, note that the docs https://learn.microsoft.com/en-us/dotnet/standard/frameworks describe some frameworks as equivalent, and some as deprecated in favor of equivalent frameworks.

Some of this equivalency is built into NuGet. For example, the short TFM win8 las the long form Windows,Version=v8.0, and the short TFM netcore45 has the long form .NETCore,Version=v4.5. However, NuGet considers them to be equivalent even though they are not identical: https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Frameworks/DefaultFrameworkMappings.cs#L129

The case of uap0.0 and netcore50 is an outlier as the docs say they are equivalent but NuGet does not. I'm not sure if this is intentional.

Anyways, the editor doesn't currently have any special behavior for equivalent TFMs, and treats them independently. It might be nice to have some kind of tooltip for equivalency and aliases, but I guess that will require more thought.

mhutch commented 2 months ago

Regarding treatment of native, I don't want to build in behavior without having a good definition of what it should mean outside of a NuGet package.

The link you provide for native isn't internally consistent. For NuGet restore, these targets leave native a native (i.e. native,Version=v0.0) or treat it as an alias for uap10.0 depending on whether it's a design-time build or not:

<NuGetTargetMoniker Condition="'$(DesignTimeBuild)' == 'true'">native</NuGetTargetMoniker>
<NuGetTargetMoniker Condition="'$(DesignTimeBuild)' != 'true'">UAP,Version=v10.0</NuGetTargetMoniker>

But for all other purposes, e.g. reference assembly pack resolution, it treats native an alias for .UAP,Version=v10.0.19041.0, then immediately overrides it to .NETCore,Version=v5.0 instead:

<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
...
<TargetPlatformVersion>10.0.19041.0</TargetPlatformVersion>
...
<TargetFrameworkIdentifier>.NETCore</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>

In future I'd like to move away from hardcoding the TFMs in MSBuild Editor like this, and instead allow TFMs to be defined in the .buildschema.json MSBuild schema files for the targets files that support/handle those TFMs. This would allow targets like these to define whatever TFMs they need without affecting completion/validation for projects that don't use those targets.

wherewhere commented 2 months ago

netcore50 is really different from uap10.0. It has some references differents. https://github.com/SharpAdb/AdvancedSharpAdbClient/blob/main/AdvancedSharpAdbClient/AdvancedSharpAdbClient.csproj#L88-L104 netcore50 can not reference to Microsoft.NETCore.UniversalWindowsPlatform. It will throw error:

error NU1202: 包 System.Numerics.Vectors.WindowsRuntime 4.0.1 与 netcore50 (.NETCore,Version=v5.0) 不兼容。 包 System.Numerics.Vectors.WindowsRuntime 4.0.1 支持: uap10.0 (UAP,Version=v10.0)

NETCoreTest.zip And is that any way to write comments in MSBuild XML? Just like comments in C# and other languages. I don't want to write comments in new files...

wherewhere commented 2 months ago

And how about this pr #219