sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Installing dotnet-ef throws error

Open Soeren-WBS opened this issue 1 year ago • 12 comments

Describe the bug

A clear and concise description of what the bug is.

Installing the ef tool thows error

To Reproduce

dotnet tool install --global dotnet-ef

Error:

Tool 'dotnet-ef' failed to update due to the following:
The settings file in the tool's NuGet package is invalid: Settings file 'DotnetToolSettings.xml' was not found in the package.
Tool 'dotnet-ef' failed to install. Contact the tool author for assistance.

However this command works:

dotnet tool install --global dotnet-ef --version 9.0.10

Soeren-WBS avatar Nov 11 '25 15:11 Soeren-WBS

Both recently released EF versions seem to be impossible to download by Nuget statistics alone:

Image

gabrielrainha avatar Nov 11 '25 20:11 gabrielrainha

The EF Core v10.0.0 package indicates it is available for net10 frameworks only. Testing myself, but suspect this could be it.

Update: after switching my docker image to sdk:10 the download and install of dotnet-ef completed successfully.

bouty avatar Nov 11 '25 20:11 bouty

@bouty is correct - the recently-published versions of the tool are targeting .NET 10 only. Users that are still on .NET 8/9 should use a version range on their dotnet tool install command, as the default behavior of the dotnet tool install command is to use the most recent package version available. Changing this is difficult, as Tool Runtime support is not available as part of NuGet package metadata.

baronfel avatar Nov 11 '25 21:11 baronfel

I don't remember this breaking before. We have tools on both .net8 and .net9, and dotnet tool install -g dotnet-ef worked perfectly fine for both, installing the correct version for the relevant framework. They only broke yesterday, when 10 was released.

I tried the following framework targeting commands (running dotnet 9.0.203), and they all failed, but --version 9.* worked fine. To me, that indicates a breaking change with the package:

  • dotnet tool install -g dotnet-ef --framework 9.x
  • ... --framework 9.0
  • ... --framework net9.x
  • ... --framework net9.0
  • ... --framework net9.0*
  • ... --framework NET9_0

FizzBuzz791 avatar Nov 12 '25 04:11 FizzBuzz791

@FizzBuzz791 here's an example of the EF tool having similar behaviors on previous SDK major version updates: https://github.com/dotnet/sdk/issues/36904

As always, the .NET SDK team's recommendations for tools is to be very aware of the versions of the tools that you use. Tool versions for dotnet-ef can be released for multiple TFMs at the same time (for example, today 8.0.22, 9.0.11, and 10.0.0 versions of this tool were released), so because the tool separates TargetFramework support by package version, you need to use a local tool manifest, or a --version range on your tool install commands if you want to maintain consistency over time.

We (SDK team) cannot force any tool provider to support multiple TFMs in a given version of their package . What we can do is try to provide better warnings if you install a tool that cannot run on your current runtimes. We've raised a PR to begin to try to do this.

baronfel avatar Nov 12 '25 05:11 baronfel

@baronfel right, but that error message is much nicer than the current error message... I'm not too sure why we didn't get a similar "package is not compatible" error here, but I assume the PR addresses that issue, so it's kind of moot.

My bigger questions:

  1. If dotnet tool install ... is running on .net9, why is it even trying to install something for a different TFM? Is that fixable?
  2. Why doesn't the --framework option seem to work?

Also, it feels like there's some missing or hidden documentation on the recommended version-pinning approach, if that's the ultimate outcome here?

FizzBuzz791 avatar Nov 12 '25 05:11 FizzBuzz791

Both of your numbered points touch on the same root issue. When you install tools, there are two phases:

  • version selection of the nuget package containing the tool
  • installation/execution of the package

The first phase happens purely driven off of nuget package versions, and takes the --version parameter into account. This is why folks are getting the new 10.0 package for dotnet-ef - they aren't specifying versions. Once version selection has happened, the package is downloaded. It's important to note that at this phase, we have no way of knowing what TFMs the tool actually supports. This information is not exposed via NuGet APIs in any way.

Now that we have a tool-containing package locally, we can inspect its contents and try to install or execute it. This is where the --framework option comes into play: it helps pick the TFM that you'd like to tool to run on - from the set of TFMs the package supports. All of the user failure here stems from the fact that 9.0 SDKs are auto-selecting the 10.0 dotnet-ef package, which only contains assets for the net10.0 TFM - the 9.0 SDK will never be able to run these assets.

Because we don't know the TFM-support information of the package until after its downloaded, it's hard to go back and try to infer/understand what version you might actually succeed with - just because for dotnet-ef there are packages whose versions roughly align with the rest of the Microsoft toolchain doesn't mean this is the case for arbitrary .NET Tools. As a result, our options to mitigate this are limited. On the SDK side, we should/are:

  • updating the check we do after-download, during-install to give a more clear error when the version of a tool we selected cannot be run on your current setup. This error should guide you towards specifying a --version, most likely.
  • continue to work with/ask our partners on the NuGet team for ways to expose more package-type-specific information in NuGet metadata to enable more efficient querying
  • continue to work with/ask our partners on the EF team to consider different packaging layouts/strategies
  • encourage the use of the new .NET 10 Runtime-specific packages, which can bundle the runtime with the package and sidestep missing-runtime errors like this entirely, at the cost of potentially-increased packages sizes, etc

As for a recommended version-pinning approach, this is something the EF Core team should provide that is specific to the way they have decided to ship their tool. It's not guidance that would apply generally or be authoritative coming from us. In general, if you provide versions of a package that don't support a given TFM, you cannot expect users of that TFM to run your package.

baronfel avatar Nov 12 '25 06:11 baronfel

+1 for @FizzBuzz791's comment.

--framework net9.0 is not working. It appears to take no effect and goes directly to latest, which currently implies net10.0.

After reading your answer @baronfel, shouldn't --framework be resolved first?

At least as a CLI user I think it's quite fair to expect dotnet tool install --global dotnet-ef --framework net9.0 to give me the latest version for that TFM rather than reverse engineering which version is the latest for my TFM and then pinning it.

~ dotnet tool install --global dotnet-ef --framework net9.0 -v d
[NuGet Manager] [Info]   GET https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/index.json
[NuGet Manager] [Info]   OK https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/index.json 197ms
[NuGet Manager] [Info]   GET https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/0.0.1-alpha/3.1.27.json
[NuGet Manager] [Info]   OK https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/0.0.1-alpha/3.1.27.json 125ms
[NuGet Manager] [Info]   GET https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/3.1.28/6.0.22.json
[NuGet Manager] [Info]   OK https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/3.1.28/6.0.22.json 123ms
[NuGet Manager] [Info]   GET https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/6.0.23/8.0.13.json
[NuGet Manager] [Info]   OK https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/6.0.23/8.0.13.json 139ms
[NuGet Manager] [Info]   GET https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/8.0.14/10.0.0.json
[NuGet Manager] [Info]   OK https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/8.0.14/10.0.0.json 125ms
[NuGet Manager] [Info]   GET https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/index.json
[NuGet Manager] [Info]   OK https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/index.json 166ms
[NuGet Manager] [Info]   GET https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/0.0.1-alpha/3.1.27.json
[NuGet Manager] [Info]   OK https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/0.0.1-alpha/3.1.27.json 124ms
[NuGet Manager] [Info]   GET https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/3.1.28/6.0.22.json
[NuGet Manager] [Info]   OK https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/3.1.28/6.0.22.json 124ms
[NuGet Manager] [Info]   GET https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/6.0.23/8.0.13.json
[NuGet Manager] [Info]   OK https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/6.0.23/8.0.13.json 140ms
[NuGet Manager] [Info]   GET https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/8.0.14/10.0.0.json
[NuGet Manager] [Info]   OK https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/8.0.14/10.0.0.json 124ms
[NuGet Manager] [Info]   GET https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/index.json
[NuGet Manager] [Info]   OK https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/index.json 131ms
[NuGet Manager] [Info]   GET https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/0.0.1-alpha/3.1.27.json
[NuGet Manager] [Info]   OK https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/0.0.1-alpha/3.1.27.json 125ms
[NuGet Manager] [Info]   GET https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/3.1.28/6.0.22.json
[NuGet Manager] [Info]   OK https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/3.1.28/6.0.22.json 123ms
[NuGet Manager] [Info]   GET https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/6.0.23/8.0.13.json
[NuGet Manager] [Info]   OK https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/6.0.23/8.0.13.json 126ms
[NuGet Manager] [Info]   GET https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/8.0.14/10.0.0.json
[NuGet Manager] [Info]   OK https://api.nuget.org/v3/registration5-gz-semver2/dotnet-ef/page/8.0.14/10.0.0.json 126ms
[NuGet Manager] [Info]   GET https://api.nuget.org/v3-flatcontainer/dotnet-ef/index.json
[NuGet Manager] [Info]   OK https://api.nuget.org/v3-flatcontainer/dotnet-ef/index.json 124ms
# HERE
[NuGet Manager] [Info]   GET https://api.nuget.org/v3-flatcontainer/dotnet-ef/10.0.0/dotnet-ef.10.0.0.nupkg
[NuGet Manager] [Info]   OK https://api.nuget.org/v3-flatcontainer/dotnet-ef/10.0.0/dotnet-ef.10.0.0.nupkg 8ms
Skipping NuGet package signature verification.
Tool 'dotnet-ef' failed to update due to the following:
The settings file in the tool's NuGet package is invalid: Settings file 'DotnetToolSettings.xml' was not found in the package.
Tool 'dotnet-ef' failed to install. Contact the tool author for assistance.

that-lucas avatar Nov 12 '25 13:11 that-lucas

@that-lucas what I'm trying to communicate with all of this is that there is no way for us to know anything about the framework support of a given package before downloading it. I would love to be able to implement what you suggest, but we simply lack the data at the fundamental NuGet level to do so efficiently.

If we tried to do what you suggested today, we'd probably download the same most recent version, see that it didn't meet your runtime requirements, and then start downloading every previous version in sequence until we found one that did run given your runtime requirements. That's kind of absurd and not at all respectful of the users bandwidth.

baronfel avatar Nov 12 '25 14:11 baronfel

Sorry @baronfel, with my CI broken I was in a rush to just get it back to work so I TLDR your answer.

Understood now. Although you deem it absurd, I'd rather have a fallback until it works option (a switch or an env var) rather than breaking it. It wouldn't be hard to assume that every failure needs to minor-- and try again, maybe a with --max-retry 3 in place to at least give it a good shot before giving up on the task?

Not great design I know but a CLI that stops working in the middle of the night because the framework released a new version doesn't sound great design either.


Bit unrelated but why doesn't the --version accept a wildcard in the minor part? --version 9.*.* doesn't work ❌ --version 9.0.* works ✅

learn.microsoft.com/en-us/dotnet/core/tools/dotnet-tool-install

Starting with .NET 8, --version Major.Minor.Patch refers to a specific major/minor/patch version, including unlisted versions. To get the latest version of a certain major/minor version instead, use --version Major.Minor.*.

that-lucas avatar Nov 12 '25 15:11 that-lucas

Bit unrelated but why doesn't the --version accept a wildcard in the minor part? --version 9.*.* doesn't work ❌ --version 9.0.* works ✅

I think we're using the NuGet version range syntax here, and 9.. isn't supported. I think you'd just use 9.* in that case.

dsplaisted avatar Nov 12 '25 18:11 dsplaisted

Same issue I just encountered and set the version to 9.0.11 and solved the problem.

dotnet tool install dotnet-ef --global --version 9.0.11

breaker05 avatar Nov 12 '25 22:11 breaker05