user1752736
user1752736

Reputation: 105

Starting an app through code with a relative path in c#

Can anyone explain to me how to navigate to a relative path using

AppDomain.CurrentDomain.BaseDirectory

or something similar?

I want to start up a web service from inside my unit tests. i know how to get the relative path of the unit test like above or using the system reflection version but i do no know how to navigate using it.

The unit test is in a separate project in visual studio with separate folders than the service but they are both in the same solution so the path relative to one another is always the same but i do not know to use that with

Process.Start

so i can tell it to start the service.

If anyone knows please let me know, or if by chance you know another way to start a web service in TFS automated builds.

Upvotes: 0

Views: 322

Answers (1)

Jsinh
Jsinh

Reputation: 2579

There is a object called "System.Diagnostics.ProcessStartInfo" which can help you to invoke an external process or start an application from your .NET application. Traversing to the folder can be done using some kind of Path.Combine() methods and you can pass the same path where the application lies to the "WorkingDirectory" property of ProcessStartInfo object.

var processStartInfo = new ProcessStartInfo(string.Format("cmd /c start some service"))
            {
                WorkingDirectory = ==PathWhereApplicationIs==,
                WindowStyle = ProcessWindowStyle.Hidden,
                ErrorDialog = false,
                CreateNoWindow = true,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                UseShellExecute = false,
            };

In above code snippet : cmd is the command prompt, /c is the indication that we are passing some arguments, the rest can be any command you wish to execute

Upvotes: 2

Related Questions