简体   繁体   English

如何运行相同解决方案中的项目?

[英]How can I run a project that is in the same solution?

I have two projects in one solution. 一个解决方案中有两个项目。 What I want to do is have one project as a main project(Project 1) and every now and then it will launch the other project(Project 2). 我要做的是将一个项目作为主要项目(Project 1),然后不时地启动另一个项目(Project 2)。 I want make Project 1 continuously running and every minute,I want Project 2 to launch, run, then close. 我希望Project 1持续运行并每分钟运行一次,我希望Project 2启动,运行然后关闭。

Here is what I have tried so far: 到目前为止,这是我尝试过的:

        if (CurrentTime.Minute % 2 == 1 && CurrentTime.Second == 30 && CurrentTime.Millisecond < 5)
        {
            try
            {
                string ThisDir = Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.FullName + "\\Project2\\bin\\Debug\\Project2.exe";
                Process.Start(ThisDir);
            }
            catch
            {

            }
        }

The problem is that if I want to run it in release this doesn't work. 问题是,如果我想在发行版中运行它,将无法正常工作。

Another note is that because I don't want this always running, I don't want to set it as a starting project in the solution properties. 另一个要注意的是,因为我不想让它一直运行,所以我不想在解决方案属性中将其设置为启动项目。 Is there a better way of starting another project that is in the same solution? 是否有更好的方法启动相同解决方案中的另一个项目?

I can't really think of a "pretty" way of doing this off the top of my head. 我真的想不出一种“漂亮”的方法来做到这一点。 I guess you could use preprocessor directives to determine the path if you want a quick and dirty solution. 我想如果需要快速而肮脏的解决方案,可以使用预处理程序指令来确定路径。 Something like 就像是

#if DEBUG
    string ThisDir = Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.FullName + "\\Project2\\bin\\Debug\\Project2.exe";
#else
    string ThisDir = Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.FullName + "\\Project2\\bin\\Release\\Project2.exe";
#endif

What we've done in the past is Properties -> Build Tab -> Output path . 我们过去所做的是Properties > Build Tab > Output path We usually set it to ..\\Output\\Debug\\ for the Debug config, and ..\\Output\\Release\\ for the release config. 对于调试配置,我们通常将其设置为..\\Output\\Debug\\ ,对于发布配置,我们将其设置为..\\Output\\Release\\ This will put both of your projects in the same output directory, and they will be in the appropriate Debug/Release directories. 这会将您的两个项目放在相同的输出目录中,并且它们将在相应的Debug / Release目录中。

This way, you can reference the other .exe in the local directory context. 这样,您可以在本地目录上下文中引用另一个.exe。

EDIT: Do this for both projects, and your output folder will be $(SOLUTION_DIR)\\Output\\Debug\\ 编辑:对两个项目都执行此操作,并且您的输出文件夹将是$(SOLUTION_DIR)\\ Output \\ Debug \\

Then, you simply have to call: 然后,您只需调用:

Process.Start("Project2.exe");

I don't quite understand why you want that. 我不太明白你为什么要那样。 But something I only learnt recently is that you can start multiple projects at the same time. 但是我最近才了解到的一点是,您可以同时启动多个项目。

eg press F5, and the startup project starts running. 例如,按F5键,启动项目开始运行。

Now right-click your secondary project, select Debug->Start New Instance, and it will also run side-by-side with your startup project. 现在,右键单击您的辅助项目,选择“调试”->“启动新实例”,它还将与启动项目并排运行。

暂无
暂无

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

相关问题 在同一个解决方案中,如何从另一个项目获得相对于项目的相对路径? - How can I get the relative path to a project from another project in the same solution? 如何调试从同一解决方案的项目中引用的DLL? - how can i Debug A DLL that is referenced from a project from the same solution? 如何从同一解决方案中的单独项目引用资源 (png) - How can I reference a resource (png) from a seperate project in the same solution 从同一解决方案中运行第二个项目 - Run a second project from within the same solution 无法在其他 PC 上运行 windows 窗体应用程序,无法从相同解决方案的项目中找到 dll - Can't run a windows form app on other PC, can't find a dll from a project of the same solution 如何创建包含具有相同输出程序集名称的应用程序和类库项目的C#解决方案? - How can I create a C# solution that contains an application and class library project that have the same output assembly name? 我可以从同一解决方案中的另一个项目访问项目的类和方法吗? - Can I access a project's class and methods from an another project in the same solution? 我可以从同一解决方案中的不同项目访问另一个项目的嵌入式资源吗? - Can I access another project's Embedded Resource from a different project in the same solution? 我可以在同一解决方案中使用.NET Framework 4.5.2和4.6.2的另一个项目吗? - Can I have a project which uses .NET Framework 4.5.2 and another project with 4.6.2 in the same solution? 同一解决方案中的现有项目,但无法调试 - existing project in the same solution but can't debug it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM