在调试和发布设置visual studio中运行不同的代码

Fah*_*lim 6 c# silverlight visual-studio-2010

是否可以在C#中在调试设置中运行特定的行代码,以及在发布设置中运行其他代码.

if #debug

//run some lines of code

else 

// run different lines of code
Run Code Online (Sandbox Code Playgroud)

小智 9

你可以这样做:

#if DEBUG
// Debug Code

#else
// Release Code

#endif
Run Code Online (Sandbox Code Playgroud)

我在WCF服务中使用它在调试中将其作为控制台应用程序运行,但在发布时作为Windows服务运行

HTH,鲁珀特.