简体   繁体   中英

How do I debug my C# app and simulate that its running from a specfic folder?

How do I debug my C# app when it really needs to be running from a specific folder and not from bin/debug? One of the first things my program does for example is determine what set of tools will be presented based on the executable file it finds. But since its running from the debug folder it can't find them. I can add the file there but that seems silly. There has to be a better way. Plus, there's really a bunch of other thighs it does that really requires it to be running from the proper folder eg. Z:\\test.

I thought it might be the "Working Directory" setting under the "Debug" tab in Properties but that didn't seem to do anything. I'm using VS2010 and C# btw...

I hope I'm making sense.

Thanks

您可以为构建指定另一个输出文件夹。

尝试将Environment.CurrentDirectory设置为要模拟的目录。

Environment.CurrentDirectory = @"C:\SimulateThisDirectory\";

You can use

System.IO.Directory.SetCurrentDirectory("your-path");

from your code.

You need to differ between two things:

  • path from which process is started
  • current working directory of the process

First one you can't simulate easily. It would probably involve creating a symbolic link or creating some sort of rootkit.

As for second one, your method is fine, and you can check working directory in runtime by using Directory.GetCurrentDirectory or set it using Directory.SetCurrentDirectory .

Take note that if you are looking up directory of executing assembly , you will get path from which process is started.

You can run your program from as normal from the specific directory and then just attach the debugger

http://msdn.microsoft.com/en-us/library/c6wf8e4z.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM