Skip to content

Calling .NET Core-compiled custom executables via symlinks on Windows should be supported #2923

Closed
@livarcocc

Description

@livarcocc

From @mklement0 on September 30, 2017 21:27

Trying to call a .NET Core 2.0 *.exe file via a symbolic link doesn't work as-is, resulting in the following error message:

The managed DLL bound to this executable: '<original-name>.dll', did not match own 
name '<symlink-name>.dll'.
A fatal error was encountered. This executable was not bound to load a managed DLL.

The idea is to use a symlink to provide an efficient, shell-agnostic way to invoke an executable by a shorter name (without having to resort to shell-specific aliases or cumbersome wrapper batch files) - just like on Unix platforms, where this scenario is already supported.

This came up while discussing a shell-agnostic way to invoke PowerShell Core with a shorter name.


Steps to reproduce

Run the following from an elevated PowerShell prompt on (64-bit) Windows:

Create a hello-world project with executable foo.exe in %TEMP%\foo:

PS> Set-Location (mkdir $env:Temp/foo)
PS> dotnet new console
PS> dotnet publish -c Release -r win-x64

Invoke the resulting executable, which works fine:

PS> .\bin\Release\netcoreapp2.0\win-x64\foo.exe
Hello World!

Now create a symlink named fooL.exe that points to the executable and try to invoke it:

PS> cmd /c mklink fooL.exe .\bin\Release\netcoreapp2.0\win-x64\foo.exe
PS> .\fooL.exe  # !! Fails as of .NET Core 2.0

This results in the error message cited at the top.

Note that creating the symlink without extension (fooL instead of fooL.exe) half works:

  • From cmd.exe, you can't call this symlink as an executable at all.
  • PowerShell does allow invocation and even succeeds in calling the target executable with the arguments specified, but invariably runs it in a new console window.

Use Set-Location ~; Remove-Item -Recurse $env:TEMP/foo to remove the temp. directory afterwards.

Copied from original issue: dotnet/cli#7739

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-HostenhancementProduct code improvement that does NOT require public API changes/additions

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions