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

时间:2015-10-25 18:05:36

标签: c# asp.net visual-studio visual-studio-2012 webforms

有一个简单的问题。

我创建了一个新的构建配置并添加了一个名为" TEST"的预处理器指令/符号。测试一下。

我正在使用网络表单。当我在.cs中执行此操作时

var isTestSet = false

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

然后在我的ascx本身的标记中,我做了一个快速测试:

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

在我的本地开发环境中,这非常有效。如果我在TEST中构建解决方案,它会警告它已设置。当我在调试模式或发布模式下构建它时,它会警告它没有设置。然而,当我使用我编译的这个dll,并将其部署到另一个环境时,它总是出现错误(似乎永远不会起作用)。

有什么想法?预处理程序指令是否从构建它们的DLL中继承?意思是只要我的dll是使用这个添加符号的新配置构建的,那么应该设置它,不是吗? 还有什么需要继续进行才能实现吗?我以为这只是DLL。

谢谢!

1 个答案:

答案 0 :(得分:1)

您很可能使用的是错误的DLL副本。

条件语句在编译时进行评估,IL不包含&#34; if-def&#34;出。您可以使用任何反编译器(即ILSpy甚至ILDasm)来验证编译的DLL中实际包含的内容(如果您只能使用.Net / VS附带的工具)。

请注意,如果使用conditional attributes而不是它们在编译代码中存在,则使用它们注释的调用方法将根据引用您的DLL的项目进行编译(例如,请参见void keybord::init_panel_window() { //prepare the window int x, y, i; bool show_it=true; char label[1000]; y = 2; x = 10; my_wins = newwin(10, 40, y, x); field[0] = new_field(1, 10, y, x, 0, 0); field[1] = NULL; field[2] = NULL; //char user_input[1000]; //attach panel to window and put this panel on top my_panels = new_panel(my_wins); set_panel_userptr(my_panels, &show_it); update_panels(); doupdate(); sprintf(label, " enter your message "); //show the window by printing box arround window int startx, starty, height, width; getbegyx(my_wins, starty, startx); getmaxyx(my_wins, height, width); box(my_wins, 0, 0); mvwaddch(my_wins, 2, 0, ACS_LTEE); mvwhline(my_wins, 2, 1, ACS_HLINE, width - 2); mvwaddch(my_wins, 2, width - 1, ACS_RTEE); print_in_middle(my_wins, 1, 0, width, label, COLOR_PAIR(2)); //show_panel(my_panels); }` void keybord::print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color) { int length, x, y; float temp; char user_input[100]; show_panel(my_panels); //show the panel if(win == NULL) win = stdscr; getyx(win, y, x); if(startx != 0) x = startx; if(starty != 0) y = starty; if(width == 0) width = 80; length = strlen(string); temp = (width - length)/ 2; x = startx + (int)temp; // mvwprintw(win, y, x, " %s", string); mvwscanw(win,y+5,x+4,"%s",user_input); //USER INPUT , IT'S WORKINK BUT THE INPUT IS NOT DISPLAYING WHILE THE USER IS TYPING refresh(); printw("value : %s************************* ",user_input ); wattron(win, color); mvwprintw(win, y, x, " %s", user_input); refresh(); wattroff(win, color); // hide_panel(my_panels); } 如何标记)。有关详细信息,请参阅#if DEBUG vs. Conditional("DEBUG")