如何保证VSVARS32.BAT批处理文件永久生效?

发布于 2024-09-10 04:14:50 字数 381 浏览 5 评论 0原文

如果我需要从普通命令提示符使用 microsoft C# 编译器,它会显示 就在这里如何以及就在这里我如何设置环境变量(通过运行 VSVARS32.BAT)。我执行它,然后我可以运行“csc”(编译器)。但是,当我关闭运行 VSVARS32.BAT 的命令行窗口时,效果似乎消失了。

有没有办法使环境变量永久存在,以便我可以从应用程序运行 csc.exe?

If I need to use microsoft C# compiler from the normal command prompt, it says right here how and it says right here how I set the environment variable (by running VSVARS32.BAT). I execute it and after that I can run "csc" (the compiler). However the effect seems to disappear when I close the command line window that run VSVARS32.BAT

Is there a way to make the environment variables permanent, so that I can run csc.exe from an application?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

不羁少年 2024-09-17 04:14:50

我建议您创建一个新的 .bat 文件来启动 vcvars.bat,然后启动您的应用程序。这将确保环境设置正确。

I would suggest that you create a new .bat file that launches the vcvars.bat and then your application. This will make sure that the environment is setup appropriately.

罗罗贝儿 2024-09-17 04:14:50

VSVAR32.bat 文件仅修改一些环境变量(将目录附加到路径、设置 LIB 和 INCLUDE 等)。您始终可以对主 Windows 环境进行相同的更改,以便所有后续进程(从控制面板“系统”小程序)继承它们。

相当多的其他开发工具使用相同的环境变量(包括早期的 Visual Studio 版本)。当您想要在同一台 PC 上使用需要冲突设置的开发工具时,在主环境中进行配置更改并不那么方便(这就是微软将它们放在 MSVAR32.bat 中而不是修改主环境的原因)。 ,因此仅在需要时应用这些设置很有用,因为它们与其他开发工具所需的设置发生冲突。如果您想在同一台 PC 上使用不同的开发工具,将这些更改放在主环境中会导致问题。

另一种可能性是让调用 csc.exe 的应用程序以与 MSVAR32.bat 相同的方式修改它传递给子进程的环境。

The VSVAR32.bat file just modifies some environment variables (appends a directory to path, sets LIB and INCLUDE, etc.). You can always make the same changes to the main Windows envirnonment so they are inherited by all subsequent processes (from the control panel "system" applet).

Quite a few other development tools use the same environment variables (including earlier Visual Studio versions). Making the configuration changes in the main environment is not so convenient when you want to use development tools that require conflicting settings on the same PC (that's why Microsoft puts them in MSVAR32.bat instead of modifying the main environment). , so it is useful to only apply these settings when they are required, as they conflict by the settings required by other development tools. Putting these changes in the main environment casues problems if you want to use different developmemnt tools on the same PC.

The other possibility to to have your application that will invoke csc.exe modify the enviroment it passes to the child process in the same manner as MSVAR32.bat.

月亮是我掰弯的 2024-09-17 04:14:50

尝试在windows目录下的autoexec.NT文件中添加运行它的命令。

Try to add the command to run it in the autoexec.NT file in windows directory.

千秋岁 2024-09-17 04:14:50

就像 laurent-rpnet 所说,您可以在 autoexec.nt 文件中调用它。或者,您可以将其设置的环境变量添加到“控制面板”|“控制面板”中的列表中。系统|高级|环境变量。

或者您可以创建一个 make 文件并将它们放入其中(或调用 bat),然后使用该 make 文件从命令行构建您的项目。

Like laurent-rpnet says, you can call it in your autoexec.nt file. Alternately, you can add the environmental variables that it sets to the list in Control Panel | System | Advanced | Environment Variables.

Or you could create a make file and put them in there (or call the bat), and use the make file to build your project from the command line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文