简体   繁体   English

如何使用安装程序使cmd.exe中的ac#命令行应用程序可运行?

[英]How can I make a c# command line application runnable in cmd.exe with installer?

I've written a C# command line application in visual studio. 我已经在Visual Studio中编写了一个C#命令行应用程序。 I would like to be able to run it as a command from the cmd.exe prompt application, after it installs. 我希望能够在安装后以cmd.exe提示符应用程序的命令运行它。 To do this I need to install the application in such a way that this would work 为此,我需要以一种可行的方式安装应用程序

C:\Users\user3765372\Documents\>myAppName argument

a good example of an application with this functionality ins node.js eg: 一个具有此功能ins node.js的应用程序的好例子,例如:

C:\Users\user3765372\Documents\>nodejs server.js

Will cause node to run the server.js file. 将导致节点运行server.js文件。 How can I make my program run like this for its commands? 如何使我的程序按其命令运行?

Note my app isn't in Documents... its somewhere else. 请注意,我的应用不在文档中……在其他地方。

I'm using this plugin to create the installer 我正在使用此插件来创建安装程序

Update: 更新:

This should work.... I think I may be making a mistake: 这应该可以工作。。。我想我可能会犯一个错误:

在此处输入图片说明

string yourAppPath = //whateverdirectoryyouwant;
string path = string.Format("{0};{1}", Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine),yourAppPath);
Environment.SetEnvironmentVariable("Path", path, EnvironmentVariableTarget.Machine);

Some users report using SetEnvironmentalVariable not taking effect. 某些用户报告使用SetEnvironmentalVariable无效。 You can do this instead: 您可以改为:

Process.Start("setx", string.Format("/M Path {0}",path));

If you want to create an installation (msi file) recommend using the Wix installer for creating an installation, and using the environment tag. 如果要创建安装(msi文件),建议使用Wix安装程序创建安装,并使用环境标签。 More details here . 更多细节在这里

Alternately, you can use the Visual Studio Installer project but it will require a custom action. 或者,您可以使用Visual Studio Installer项目,但需要自定义操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM