简体   繁体   English

C#.NET中的编译问题

[英]Compilation issue in C# .NET

I have the following code (inherited from a contractor): 我有以下代码(从承包商那里继承):

public partial class StoredProcedures  
{  
    #if NO_THREAD      
        readonly static String version = "XXXX, Version 1.02, Apr/29/2010";
    #else 
        readonly static String version = "XXXX, Version 0.93, Dec/21/2006";
    #endif

I can't seem to find NO_THREAD anywhere else. 我似乎在其他任何地方都找不到NO_THREAD。 This is code that compiles and installs as a SQL assembly. 这是可作为SQL程序集编译并安装的代码。 Is it something special or am I missing something simple? 是特别的东西还是我缺少简单的东西?

尝试检查项目具有的所有Build配置的Project Properties-> Build-> General-> Conditional编译符号 ,它可能在那里。

Look for a #define statement. 寻找一个#define语句。 See the docs for #if preprocessor conditionals : http://msdn.microsoft.com/en-us/library/4y6tbswk.aspx 请参阅#if预处理条件的文档: http : //msdn.microsoft.com/zh-cn/library/4y6tbswk.aspx

If you can't find a 如果找不到

define #NO_THREAD

Anywhere in the code, then it's probably because the contractor was defining the symbol by passing the /define compiler option. 在代码中的任何地方,这可能是因为承包商通过传递/ define编译器选项来定义符号。

See here for more details (typing from a cell, sorry for the format): 请参阅此处以获取更多详细信息(在单元格中键入内容,对不起格式):

http://msdn.microsoft.com/en-us/library/0feaad6z.aspx http://msdn.microsoft.com/zh-CN/library/0feaad6z.aspx

you should probably have a look at the c# pre-processor directives 您可能应该看看c# 预处理程序指令

No_Thread here is a symbol which can be defined by using #define No_Thread and when #define No_Thread is present then #if NO_THREAD will result in true and at compile time readonly static String version = "XXXX, Version 1.02, Apr/29/2010"; No_Thread这里是可以通过使用定义的符号#define No_Thread和时#define No_Thread存在,则#if NO_THREAD将导致真正和在编译时readonly static String version = "XXXX, Version 1.02, Apr/29/2010"; this statement will be compiled otherwise the next statement will be compiled. 该语句将被编译,否则下一个语句将被编译。

this is generally used to differentiate between debug and release versions. 通常用于区分调试版本和发行版本。 have you noticed there are 2 versions in VS when you create a new project. 您是否在创建新项目时注意到VS中有2个版本。 if you write something like this somewhere in you code 如果您在代码中的某处编写这样的内容

 #if DEBUG
 Console.WriteLine("DEBUG VERSION");
 #endif

then the string "DEBUG VERSION" would only be printed on the console when the project is in debug mode because the VS inserts a symbol DEBUG if you manually do it using the #define pre-processor then too this line would be compiled 那么只有在项目处于调试模式时,字符串"DEBUG VERSION"才会显示在控制台上,因为如果您使用#define预处理器手动执行此操作,则VS会插入一个符号DEBUG ,那么该行也将被编译

NO_THREAD is a symbol for conditional compilation. NO_THREAD是用于条件编译的符号。

It can come from, #define NO_THREAD , from the project file, or from the nant file (or whatever method you use for building). 它可以来自#define NO_THREAD ,来自项目文件或nant文件(或用于构建的任何方法)。

If it's defined, the first line of code is counted as part of the C# code. 如果已定义,则第一行代码将计为C#代码的一部分。 If it isn't, then the second is. 如果不是,那么第二个是。

If that's the sole occurence, I'd say it was a hangover from something removed, but if you're uesd to using visual studio to build, then make sure there isn't a build file for nant in case the previous developer used that instead. 如果这是唯一的情况,那么我想这是从已删除内容中解脱出来的,但是如果您需要使用Visual Studio进行构建,请确保没有用于nant的构建文件,以防以前的开发人员使用过代替。

This is a conditional compilation symbol. 这是一个条件编译符号。 In Visual Studio 2010, these appear on the Build page of your Project Properties in the Conditional compilation symbols text box. 在Visual Studio 2010中,这些将显示在“项目属性”的“生成”页面上的“条件编译符号”文本框中。 Probably one of your Configuration Manager configurations either contains this symbol or has at some point in the past. 您的Configuration Manager配置之一可能包含此符号,或者在过去的某个时候具有。 Presumably, there is another #if somewhere that disables a block of code that uses multiple threads if the NO_THREAD symbol is present. 如果存在NO_THREAD符号,则大概还有一个#if地方将禁用使用多个线程的代码块。

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

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