Skip to content

Show a warning when the tools are used with a platform-specific app#37868

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/show-warning-for-platform-apps
Draft

Show a warning when the tools are used with a platform-specific app#37868
Copilot wants to merge 5 commits intomainfrom
copilot/show-warning-for-platform-apps

Conversation

Copy link
Contributor

Copilot AI commented Mar 6, 2026

EF tools silently fail when used with platform-specific apps (e.g., WinUI 3 targeting net8.0-windows10.0.19041.0). The UnsupportedPlatform resource string already existed but was never wired up.

  • src/dotnet-ef/RootCommand.cs: Added GetTargetPlatformIdentifier(string targetFramework) that parses the TargetFramework TFM string to extract the platform identifier (replicating [MSBuild]::GetTargetPlatformIdentifier). IsCurrentPlatform maps the extracted platform identifier (windows, linux, osx/macos) to OperatingSystem.Is*() checks. A warning is emitted via Reporter.WriteWarning when 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 add command 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?

  1. Open project, :)
  2. Run dotnet ef migrations add InitialCreate -v
  3. Watch it do nothing
  4. Remove Microsoft.Extensions.Hosting in the .csproj
  5. Run dotnet clean
  6. Run dotnet ef migrations add InitialCreate -v again
  7. Watch it create a migration

Code

Project zip

App1.zip

The constructor in the App.xaml.cs.

    public App()
    {
        this.InitializeComponent();

        var serviceProvider = new ServiceCollection().AddDbContext<AppDbContext>(ServiceLifetime.Transient).BuildServiceProvider();

        //var host = new HostBuilder()
        //    .ConfigureServices(services =>
        //    services.AddDbContext<AppDbContext>(ServiceLifetime.Transient))
        //    .Build();
        //host.Start();
    }

Context factory

internal class TestDatabaseContextFactory : IDesignTimeDbContextFactory<AppDbContext>
{
    public AppDbContext CreateDbContext(string[] args)
    {
        var folder = Environment.SpecialFolder.LocalApplicationData;
        var path = Environment.GetFolderPath(folder);
        var DbPath = System.IO.Path.Join(path, "blogging.db");
        var optionsBuilder = new DbContextOptionsBuilder<AppDbContext>();
        optionsBuilder.UseSqlite($"Data Source={DbPath}");

        return new AppDbContext(optionsBuilder.Options);
    }
}

Output

Using Microsoft.Extensions.DependencyInjection

PS C:\Users\User\source\repos\App1\App1> dotnet ef migrations add InitialCreate -v
Using project 'C:\Users\User\source\repos\App1\App1\App1.csproj'.
Using startup project 'C:\Users\User\source\repos\App1\App1\App1.csproj'.
Writing 'C:\Users\User\source\repos\App1\App1\obj\App1.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\User\AppData\Local\Temp\tmpp110d3.tmp /verbosity:quiet /nologo C:\Users\User\source\repos\App1\App1\App1.csproj
Writing 'C:\Users\User\source\repos\App1\App1\obj\App1.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\User\AppData\Local\Temp\tmp5psv0t.tmp /verbosity:quiet /nologo C:\Users\User\source\repos\App1\App1\App1.csproj
Build started...
dotnet build C:\Users\User\source\repos\App1\App1\App1.csproj /verbosity:quiet /nologo /p:PublishAot=false
c:\program files\dotnet\sdk\8.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(284,5): warning NETSDK1206: Found version-specific or distribution-specific runtime identifier(s): win10-arm64, win10-x64, win10-x86. Affected libraries: Microsoft.WindowsAppSDK. In .NET 8.0 and higher, assets for version-specific and distribution-specific runtime identifiers will not be found by default. See https://aka.ms/dotnet/rid-usage for details. [C:\Users\User\source\repos\App1\App1\App1.csproj]

Build succeeded.

c:\program files\dotnet\sdk\8.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(284,5): warning NETSDK1206: Found version-specific or distribution-specific runtime identifier(s): win10-arm64, win10-x64, win10-x86. Affected libraries: Microsoft.WindowsAppSDK. In .NET 8.0 and higher, assets for version-specific and distribution-specific runtime identifiers will not be found by default. See https://aka.ms/dotnet/rid-usage for details. [C:\Users\User\source\repos\App1\App1\App1.csproj]
    1 Warning(s)
    0 Error(s)

Time Elapsed 00:00:14.96
Build succeeded.
dotnet exec --depsfile C:\Users\User\source\repos\App1\App1\bin\Debug\net8.0-windows10.0.19041.0\App1.deps.json --additionalprobingpath C:\Users\User\.nuget\packages --additionalprobingpath "C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages" --additionalprobingpath "c:\program files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig C:\Users\User\source\repos\App1\App1\bin\Debug\net8.0-windows10.0.19041.0\App1.runtimeconfig.json C:\Users\User\.dotnet\tools\.store\dotnet-ef\8.0.1\dotnet-ef\8.0.1\tools\net8.0\any\tools\netcoreapp2.0\any\ef.dll migrations add InitialCreate --assembly C:\Users\User\source\repos\App1\App1\bin\Debug\net8.0-windows10.0.19041.0\App1.dll --project C:\Users\User\...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes dotnet/efcore#32835

<!-- START COPILOT CODING AGENT TIPS -->
---

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. [Learn more about Advanced Security.](https://gh.io/cca-advanced-security)

… app

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title [WIP] Add warning for tools in platform-specific apps Show a warning when the tools are used with a platform-specific app Mar 6, 2026
startupProject.AssemblyName + ".runtimeconfig.json");
var projectAssetsFile = startupProject.ProjectAssetsFile;

if (!string.IsNullOrEmpty(startupProject.TargetPlatformIdentifier))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Only show warning if TargetPlatformIdentifier is different from the platform currently being used to execute this code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Comment on lines +109 to +110
if (!string.IsNullOrEmpty(startupProject.TargetPlatformIdentifier)
&& !IsCurrentPlatform(startupProject.TargetPlatformIdentifier))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Use GetTargetPlatformIdentifier instead and move the logic to IsCurrentPlatform

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants