习惯了Unity和Android开发,需要发布到多个渠道(猪大家业务多多,赚大发)
在开发过程中,一般需要知道时Debug版本还是Releas版本
C# Code:
string codeBase = Assembly.GetExecutingAssembly().GetName().CodeBase;
返回结果:"file:///c:/users/administrator/documents/visual studio 2015/Projects/WindowsFormsApplication4/WindowsFormsApplication4/bin/Debug/WindowsFormsApplication4.EXE"
string file = Assembly.GetExecutingAssembly().GetName().Name;
返回结果:"WindowsFormsApplication4"
string location = Assembly.GetExecutingAssembly().Location;
返回结果:"c:\\users\\administrator\\documents\\visual studio 2015\\Projects\\WindowsFormsApplication4\\WindowsFormsApplication4\\bin\\Debug\\WindowsFormsApplication4.exe"
string fileName = Path.GetFileName(Assembly.GetExecutingAssembly().Location);
返回结果:"WindowsFormsApplication4.exe"
再可以用以下方法:
或许在开发过程中,你会遇到这种情况,我们拿到一个dll或者exe,不知道这个程序集是debug还是release版本。其实C#开发中,我们是在JIT运行环境中来判断程序集,是否是debug还是release版本。直接上代码吧,如下是控制台程序,比较简单:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Reflection;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(DebugBuild("D:\\Test.exe")); //这里就是要验证的程序集路径
}
private static bool DebugBuild(string path)
{
return DebugBuild(Assembly.LoadFile(Path.GetFullPath(path)));
}
private static bool DebugBuild(Assembly assembly)
{
foreach (object attribute in assembly.GetCustomAttributes(false))
{
if (attribute is DebuggableAttribute)
{
DebuggableAttribute _attribute = attribute as DebuggableAttribute;
return _attribute.IsJITTrackingEnabled;
}
}
return false;
}
}
}
另外有关JIT知识补充点,有的时候,我们会遇到JIT运行时出错,解决方式参考上上篇文章:http://blog.csdn.net/u014650759/article/details/78042043
————————————————
版权声明:本文为CSDN博主「习明然」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u014650759/article/details/78220796