假设我正在制作一个游戏(或类似的东西),解决方案中的第一个项目是1级,第二个是2级,依此类推......想象一下游戏从1级开始,玩家可以在2级和3级之间做出选择,以便继续。根据他的选择,运行项目2或3。我怎么能这样做(如果可以的话)?如果重要的话,我正在使用Visual Studio 2012 Pro ...
答案 0 :(得分:1)
如果您需要从“MainProject.exe”调用“Project1.exe”,这可以帮助您
使用System.Diagnostics;
class Program
{
static void Main()
{
int level ;
//ask or determine which level wants to be played
LaunchCommandLineApp(level);
}
/// <summary>
/// Launch the legacy application with some options set.
/// </summary>
static void LaunchCommandLineApp(int level)
{
// For the example
const string ex1 = "C:\\";
const string ex2 = "C:\\Dir";
// Use ProcessStartInfo class
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "Project" + level + ".exe";
//I guess you dont need this
//startInfo.WindowStyle = ProcessWindowStyle.Hidden;
//If your project needs som parameters use this, if not removeit
startInfo.Arguments = "-f j -o \"" + ex1 + "\" -z 1.0 -s y " + ex2;
try
{
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
catch
{
// Log error.
}
}
}
答案 1 :(得分:0)
您可以使用VS SolutionExplorer在项目1中添加对项目2的引用 - &gt;项目1 - &gt;右键单击References
并选择Add Reference
,然后指定dll。
答案 2 :(得分:0)
我不完全确定我理解你的情景,但是......
有两种选择: