get current project path

本文介绍了多种获取程序启动路径的方法,包括使用AppDomain、System.IO.Directory、Environment等API,以及针对不同应用程序类型如Windows Forms应用的特定解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

string path = AppDomain.CurrentDomain.BaseDirectory
/*This is the best option all round. 
It will give you the base directory for class libraries, 
including those in ASP.NET applications.*/

string startupPath = System.IO.Directory.GetCurrentDirectory();
/*
This does an interop call using the winapi GetCurrentDirectory call inside kernel32.dll,
 which means the launching process’ folder will often be returned. 
 Also as the MSDN documents say, it’s not guaranteed to work on mobile devices.
*/

string startupPath = Environment.CurrentDirectory;
/*
This simply calls Directory.GetCurrentDirectory()
*/


Assembly.Location
/*
called using : this.GetType().Assembly.Location
This returns the full path to the calling assembly, 
including the assembly name itself. 
If you are calling a separate class library, 
then its base directory will be returned, 
such “C:\myassembly.dll” – depending obviously on which Assembly instance is being used.
*/

Application.StartupPath
/*
This is inside the System.Windows.Forms namespace, 
so is typically used in window forms application only.
*/

Application.ExecutablePath
/*
The same as Application.StartupPath, 
however this also includes the application name, such as “myapp.exe”
*/


改进以下代码 currentpath = os.path.dirname(os.path.realpath(__file__)) time_date = '{}{}'.format(self.time_date,self.random_char(5)) contents = os.path.join(currentpath, time_date, self.ref.split('/')[-1]) ref = self.ref.split('/')[-1] private_token = self.gl.private_token path = "lib" if ref == "master": if os.path.exists(os.path.join(contents, self.name)): subprocess.call("rm -rf {} ".format(os.path.join(contents, self.name)), shell=True, cwd=contents) time.sleep(3) retcode = start.clone(int(self.project_id), ref, contents, private_token) if retcode == 0: start.clone_frontend(self.get_frontend()[0],self.get_frontend()[1], contents, private_token,self.get_frontend()[2] ) start.clone_abc(self.get_abc()[0], self.get_abc()[1], contents, private_token,"mc_abc") start.clone_model(start.get_clkrst()[0], start.get_clkrst()[1], contents, private_token,"clkrst") start.clone_model(start.get_ara()[0], start.get_ara()[1], contents, private_token,"ara") start.clone_model(start.get_wfl()[0], start.get_wfl()[1], contents, private_token,"wfl") subprocess.call("echo '*.t' >> {}".format(os.path.join(contents, self.name, ".gitignore")),shell=True) code = start.make_lib(os.path.join(contents, self.name)) rel, err = code.communicate() if "make: *** [main] Error 2" in err.decode('utf-8'): print("loading push error log") filename = os.path.join(contents, self.name, "error_make_log") subprocess.call("echo '' > {}".format(filename), shell=True, cwd=contents) start.error_make(filename, rel.decode('utf-8') ) start.error_make(filename, err.decode('utf-8') ) else: print("loading push libs") # start.push_lib(os.path.join(contents, self.name), path, ref)
06-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值