Topher
Topher

Reputation: 35

.Net Console application as a CLI Command

I want to build make a .Net Console application available globally as a CLI command. I tried creating a small application, then adding the executable to my path variable. I then referenced the executable name in the console and it was not found.

I did find that I could add a custom verb through .net core, however that really isn't what I was looking for.

Any ideas?

Upvotes: 1

Views: 446

Answers (2)

Cesar
Cesar

Reputation: 527

You can try to add the Directory instead of the .exe.

  1. Type Edit environment variables
  2. Open the option Edit the system environment variables
  3. Click Environment variables... button
  4. There yousee two boxes, in System Variables box find path variable
  5. Click Edit
  6. A window pops up, click New
  7. Type the Directory path of your .exe or batch file ( Directory means exclude the file name from path)
  8. Click Ok on all open windows and restart your system.

See here for more information in AmiNadimi post : "Register" an .exe so you can run it from any command line in Windows

Upvotes: 2

ProgrammingLlama
ProgrammingLlama

Reputation: 38850

You need to add the directory of the application to your PATH variable, not the full path including the filename.

For example:

c:\users\john\documents\MyPrograms\test.exe

would be added to PATH as:

c:\users\john\documents\MyPrograms\

and then could be used simply as "test" from Command Prompt.

Note that you need to log out of Windows and log back in for your changes to take effect.

Upvotes: 2

Related Questions