1、C#程序编译编译前,要用到VS2005提供的一个编译工具 devenv.exe,这个在VS安装目录\Common7\IDE 下可以使用控制台命令:
- devenv /rebuild debug "【sln path】"
2、C#程序编译在代码中要运行指定的程序,可以使用process方法:
- using System.Diagnostics
- System.Diagnostics.Process.StartInfo
- info=new StartInfo();
- info.FileName="你想要用的特定的程序";
- Info.Arguments="要打开的文件:;
- System.Diagnostics.Process.Start(info);
3、在C#程序编译的实际使用过程中会遇到一个问题:各人VS安装目录不同,程序中调用devenv的路径就不同。解决这个问题的方法就是读取注册表中的vs的ApplicationPath键值(这个在前面有过介绍)综上,实现方法如下:
- using System.Diagnostics;
- using Microsoft.Win32;
- private const string REGISTKEY ="
- SOFTWARE\\Microsoft\\MSEnvCommunityContent
- \\ContentTypes\\Addin\\ContentHosts\\
- 1.0\\Visual Studio 2005";
- RegistryKey rkey = Registry.LocalMachine;
- //The second parameter tells it to open
- the key as writable
- RegistryKey rkey1 = rkey.OpenSubKey
- (REGISTKEY, true);
- string visualStudio8Path = rkey1.GetValue(
- "ApplicationPath").ToString();
- ProcessStartInfo startInfo =
- new ProcessStartInfo(visualStudio8Path);
- startInfo.Arguments = "/rebuild debug "
- + "【sln path】";
- Process process = new Process();
- process.StartInfo = startInfo;
- process.Start();
- process.WaitForExit();
【编辑推荐】