Show a warning when the tools are used with a platform-specific app#37868
Show a warning when the tools are used with a platform-specific app#37868
Conversation
… app Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
src/dotnet-ef/RootCommand.cs
Outdated
| startupProject.AssemblyName + ".runtimeconfig.json"); | ||
| var projectAssetsFile = startupProject.ProjectAssetsFile; | ||
|
|
||
| if (!string.IsNullOrEmpty(startupProject.TargetPlatformIdentifier)) |
There was a problem hiding this comment.
@copilot Only show warning if TargetPlatformIdentifier is different from the platform currently being used to execute this code
There was a problem hiding this comment.
Updated in e60ab21. The warning now only shows when TargetPlatformIdentifier differs from the current execution platform. Added IsCurrentPlatform helper that maps "Windows"→OperatingSystem.IsWindows(), "Linux"→OperatingSystem.IsLinux(), "macOS"→OperatingSystem.IsMacOS(). Unknown platforms (Android, iOS, etc.) always trigger the warning. Also reverted the PMC change since it always runs on Windows.
…ution platform Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
src/dotnet-ef/RootCommand.cs
Outdated
| if (!string.IsNullOrEmpty(startupProject.TargetPlatformIdentifier) | ||
| && !IsCurrentPlatform(startupProject.TargetPlatformIdentifier)) |
There was a problem hiding this comment.
@copilot Use GetTargetPlatformIdentifier instead and move the logic to IsCurrentPlatform
There was a problem hiding this comment.
Done in 950dd96. Extracted GetTargetPlatformIdentifier() that returns the platform identifier string for the current OS, and moved the null/empty check into IsCurrentPlatform so the call site is just if (!IsCurrentPlatform(startupProject.TargetPlatformIdentifier)).
…urrentPlatform Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
…m TargetFramework Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
EF tools silently fail when used with platform-specific apps (e.g., WinUI 3 targeting
net8.0-windows10.0.19041.0). TheUnsupportedPlatformresource string already existed but was never wired up.src/dotnet-ef/RootCommand.cs: AddedGetTargetPlatformIdentifier(string targetFramework)that parses theTargetFrameworkTFM string to extract the platform identifier (replicating[MSBuild]::GetTargetPlatformIdentifier).IsCurrentPlatformmaps the extracted platform identifier (windows, linux, osx/macos) toOperatingSystem.Is*()checks. A warning is emitted viaReporter.WriteWarningwhen the startup project targets a platform that differs from the one currently executing the tool. Unknown platforms (e.g., Android, iOS) always trigger the warning.Original prompt
This section details on the original issue you should resolve
<issue_title>Show a warning when the tools are used with a platform-specific app</issue_title>
<issue_description>Hi Folks,
I am building a WinUI 3 app and want to use SQLite using ef core. When using the Microsoft.Extensions.Hosting package, the
dotnet ef migrations addcommand doesn't give any errors but also doesn't give or log any errors. When removed from the .csproj file the and use Microsoft.Extensions.DependencyInjection, the migration is created without any problems.I created a small sample 3 app with ef core. In the current state of the project within App1.zip is Microsoft.Extensions.Hosting included.
Am I missing something?
How to reproduce?
dotnet ef migrations add InitialCreate -vdotnet cleandotnet ef migrations add InitialCreate -vagainCode
Project zip
App1.zip
The constructor in the App.xaml.cs.
Context factory
Output
Using Microsoft.Extensions.DependencyInjection