如何使用安装程序在cmd.exe中运行c#命令行应用程序?

时间:2015-03-10 17:14:12

标签: c# windows visual-studio cmd installation

我在visual studio中编写了一个C#命令行应用程序。我希望能够在安装后从cmd.exe提示应用程序中将其作为命令运行。为此,我需要以这样的方式安装应用程序

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

具有此功能的应用程序的一个很好的示例,如node:.js,例如:

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

将导致节点运行server.js文件。如何使我的程序以其命令运行?

请注意我的应用不在文档中......在其他地方。

我使用this plugin创建安装程序

更新

这应该有效....我想我可能犯了一个错误:

enter image description here

2 个答案:

答案 0 :(得分:0)

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

部分用户报告使用SetEnvironmentalVariable未生效。你可以这样做:

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

答案 1 :(得分:0)

If you want to create an installation (msi file) recommend using the Wix installer for creating an installation, and using the environment tag. More details here.

Alternately, you can use the Visual Studio Installer project but it will require a custom action.

相关问题