简体   繁体   English

C#预处理器在本地工作,但在部署时不工作

[英]C# Preprocessor working locally but not when deployed

Had a quick question. 有一个简单的问题。

I created a new build configuration and added a pre processor directive/symbol called "TEST" to test something out. 我创建了一个新的构建配置,并添加了一个称为“ TEST”的预处理程序指令/符号来测试某些内容。

I'm using web forms. 我正在使用网络表单。 When I do this in the .cs 当我在.cs中执行此操作时

var isTestSet = false

#if TEST
        isTestSet = true;
#else
        isTestSet = false;

and then in my ascx itself in the markup, I do a quick test: 然后在我的ascx本身的标记中,做一个快速测试:

<% if (isTestSet == true) 
     alert("test is set");
   else
     alert("test is not set");
%>

In my local development environment, this works perfectly. 在我的本地开发环境中,这非常有效。 If I build the solution in TEST, it alerts that it's set. 如果我在TEST中构建解决方案,它会警告它已设置。 When I build it in something like debug mode or release mode, it alerts that it's not set. 当我以调试模式或发布模式之类的方式构建它时,它会警告未设置。 When I take this very same dll that I compiled, however, and deploy it to another environment, it always comes up as false (never seems to work). 但是,当我使用与我编译的相同的dll并将其部署到另一个环境时,它总是出现为false(似乎从未起作用)。

Any thoughts? 有什么想法吗? Do preprocessor directives get carried over from the DLLs in which they were built? 预处理程序指令是否从生成它们的DLL中继承下来? Meaning as long as my dll was built using this new configuration that adds the symbol, then it should be set, no? 意思是只要我的dll是使用添加符号的新配置构建的,那么就应该对其进行设置,不是吗? Does anything else need to be carried over for this to work? 要进行此工作,是否还需要携带其他物品? I thought it was just the DLL. 我以为那只是DLL。

Thanks! 谢谢!

Most likely you are using wrong copy of DLL. 您很可能使用了错误的DLL副本。

Conditional statement are evaluated at compile time and IL does not include branches that are "if-def" out. 条件语句在编译时评估,并且IL不包括“ if-def”输出的分支。 You can verify what actually contained in the compiled DLL by using any decompiler ie ILSpy or even ILDasm (if you can only use tools that come with .Net/VS). 您可以使用任何反编译器(即ILSpy甚至ILDasm)(如果您只能使用.Net / VS附带的工具)来验证已编译DLL中实际包含的内容。

Note that if you use conditional attributes than they are present in compiled code and calling methods annotated with them will be compiled according to projects that references your DLL (see how Debug.Trace are marked for example). 请注意,如果您使用条件属性,而不是已存在于已编译代码中的条件属性 ,并且使用它们注释的调用方法将根据引用您的DLL的项目进行编译(例如,请参见Debug.Trace的标记方式)。 See #if DEBUG vs. Conditional("DEBUG") for more info. 有关更多信息,请参见#if DEBUG与Conditional(“ DEBUG”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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