Dialyzer error when checking Mix task

I have a Mix task that extracts the version number of the project (for use in a build pipeline):

defmodule Mix.Tasks.VersionNumber do
  @moduledoc "Mix task to print the current version number to stdout"
  use Mix.Task

  @shortdoc "Print the current application version number"
  def run(_) do
    MyApp.MixProject.project |> Keyword.fetch!(:version) |> IO.puts

This all works fine. However, when I run mix dialyzer on my project, I get an error:

$ mix dialyzer
Compiling 1 file (.ex)
Finding suitable PLTs
Checking PLT...
[:asn1, :castore, :certifi, :compiler, :connection, :cowboy, :cowboy_telemetry, :cowlib, 
:crypto, :dart_sass, :db_connection, :decimal, :ecto, :ecto_sql, :eex, :elixir, :esbuild, 
:expo, :file_system, :finch, :geo, :geo_postgis, :gettext, :hackney, :heroicons, :hpax, 
:httpoison, :idna, :jason, :kernel, :logger, :metrics, :mime, :mimerl, :mint, :mix, 
:nimble_options, :nimble_pool, :parse_trans, :phoenix, :phoenix_copy, :phoenix_ecto, 
:phoenix_html, :phoenix_live_dashboard, :phoenix_live_reload, :phoenix_live_view, 
:phoenix_pubsub, :phoenix_template, :plug, :plug_cowboy, ...]
PLT is up to date!
No :ignore_warnings opt specified in mix.exs and default does not exist.

Starting Dialyzer
  check_plt: false,
  init_plt: '/home/ian/projects/verna/myapp/_build/dev/dialyxir_erlang-25.1.2_elixir-1.14.2_deps-dev.plt',
  files: ['/home/ian/projects/verna/myapp/_build/dev/lib/myapp/ebin/Elixir.MyApp.LocationSearch.SearchResult.beam',
  warnings: [:unknown]
Total errors: 1, Skipped: 0, Unnecessary Skips: 0
done in 0m4.56s
Function MyApp.MixProject.project/0 does not exist.
done (warnings were emitted)
Halting VM with exit status 2

At a guess, the problem is maybe related to project/0 being defined in an .exs file rather than .ex? Is there a way to either ignore the mix task in the Dialyzer analysis, or, better, help it to find the definition of project/0?