Skip to content

NativeAOT publish fails at link step when NoDefaultCurrentDirectoryInExePath is set #129340

Closed

Description

@diontools

Description

Publishing a NativeAOT app on Windows fails at the native link step with MSB3073 (exit code 123) when the environment variable NoDefaultCurrentDirectoryInExePath is set.
The cmd error message 'vswhere.exe' is not recognized ... gets embedded into the linker command line.

I hit this with Claude Code, which sets NoDefaultCurrentDirectoryInExePath=1 for every shell it spawns: a NativeAOT dotnet publish run from a Claude Code session fails, while the same command succeeds from a plain cmd.exe. The repro below does not need Claude Code — setting the variable manually is sufficient.

Reproduction Steps

On Windows, with the Visual Studio C++ build tools installed (VS 2026):

dotnet new console --aot
set NoDefaultCurrentDirectoryInExePath=1
dotnet publish

Expected behavior

The publish succeeds. The C++ toolchain is actually found correctly.

Actual behavior

Restore complete (0.2s)
  NativeAotErrorTest net10.0 win-x64 failed with 1 error(s) (2.6s) → bin\Release\net10.0\win-x64\NativeAotErrorTest.dll
    C:\Users\user\.nuget\packages\microsoft.dotnet.ilcompiler\10.0.9\build\Microsoft.NETCore.Native.targets(396,5): error MSB3073: The command ""'vswhere.exe' is not recognized as an internal or external command, operable program or batch file.;C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\bin\Hostx64\x64\link.exe" @"obj\Release\net10.0\win-x64\native\link.rsp"" exited with code 123.

Build failed with 1 error(s) in 3.1s

Regression?

Not as far as I know.

Known Workarounds

Unset the variable for the build: set NoDefaultCurrentDirectoryInExePath= before dotnet publish.

Configuration

  • .NET SDK 10.0.301, Microsoft.DotNet.ILCompiler 10.0.9
  • Windows 11 Pro (10.0.26200), x64
  • VS Community 2026 18.5.3 (MSVC 14.50.35717)

Other information

No response

Activity

  1. added
    untriaged
    on Jun 12, 2026
  2. dotnet-policy-service commented on Jun 12, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
    See info in area-owners.md if you want to be subscribed.

  3. MichalStrehovsky commented on Jun 15, 2026

    @MichalStrehovsky
    Member

    This will likely get fixed with #129316 that deletes the problematic batch script, but we should re-check once it merges.

  4. MichalStrehovsky commented on Jun 16, 2026

    @MichalStrehovsky
    Member

    Actually, this is "fixed" in .NET 11 already. This is a message generated by vcvarsall.bat that comes with Visual Studio, so #126180 also "fixes" this (it redirects the error from vcvarsall to nul).

    So the real reason this doesn't work is because vcvarsall that comes with Visual Studio doesn't work with NoDefaultCurrentDirectoryInExePath. I checked and vcvarsall still configures the environment enough to be workable for our purposes despite the message.

  5. added this to the 11.0.0 milestone on Jun 16, 2026
  6. removed
    untriaged
    on Jun 16, 2026
  7. MichalStrehovsky commented on Jun 24, 2026

    @MichalStrehovsky
    Member

    Confirmed with the latest builds.

  8. locked and limited conversation to collaborators on Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions