【发布时间】:2018-12-26 09:35:33
【问题描述】:
当我构建并运行我的项目时,下面的代码
Console.WriteLine("I am running in debug {0}", StaticConfiguration.IsRunningDebug);
在 debug 模式下产生 true,在 release 模式下产生 false 模式,正如预期的那样。然后我使用 nuget 添加一个包,nuget 服务器是我们本地的 nuget 服务器,它是我们拥有和发布的库。
当我再次运行上述代码时,我在 debug 模式下得到 true 和 true 也处于发布模式。
//Get all non-nancy assemblies, and select the custom attributes
var assembliesInDebug
= AppDomainAssemblyTypeScanner.TypesOf<INancyModule>(ScanMode.ExcludeNancy)
.Select(x => x.Assembly.GetCustomAttributes(typeof(DebuggableAttribute), true))
.Where(x => x.Length != 0);
//if there are any, then return the IsJITTrackingEnabled
//else if the collection is empty it returns false
return assembliesInDebug.Any(d => ((DebuggableAttribute)d[0]).IsJITTrackingEnabled
);
当我查看构建服务器时,看起来好像这些库是在发布模式下构建的。有什么想法可以去哪里看?
更新:
我通过在 Scott Hanselman 网站上找到的代码运行程序集,以检测它们是在调试模式还是发布模式下构建的。出于某种原因,下载的两个 DLL 都是在 debug 模式下构建的。尽管构建服务器上的调用非常明确地说明了发布模式。
所以我现在假设,如果任何 DLL 是在调试模式下构建的,那么整个构建都是因为调试模式
【问题讨论】:
-
即使在发布模式下构建,该值是否仍然为真?你能解释一下为什么你使用这个代码,而不是
#if DEBUG return true;吗? -
如果您指的是程序集的扫描,则来自 Nancy 源代码。其他一些代码依赖于该结果
标签: c# visual-studio nuget nancy