473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Can I change my code depending on the build type?

I've got a function that needs to work slightly differently on the
development server from the production server, but of course I don't want to
be changing code just before compiling a release version!?

I'm thinking I could use some #if #else #endif type statements to change
certain things, depending on the build type. I'm thinking of something like
this in my .cs file...

#if DEBUG
private string MyFunc()
{
// debug version
}
#else
private string MyFunc()
{
// release version
}
#end if

Would this work!? If not, how could I achieve a similar effect? (.net 2)

Cheers
Dan
May 8 '06 #1
10 1484
Yes, that works.

I use it myself in an application that adds a lot of records to a
database. The release version puts data in a buffer and saves them when
the buffer is full or has lived a certain time, but the debug version
flushes the buffer for each record so that they show up in the database
immediately.

musosdev wrote:
I've got a function that needs to work slightly differently on the
development server from the production server, but of course I don't want to
be changing code just before compiling a release version!?

I'm thinking I could use some #if #else #endif type statements to change
certain things, depending on the build type. I'm thinking of something like
this in my .cs file...

#if DEBUG
private string MyFunc()
{
// debug version
}
#else
private string MyFunc()
{
// release version
}
#end if

Would this work!? If not, how could I achieve a similar effect? (.net 2)

Cheers
Dan

May 8 '06 #2
fantastic! cheers :D

"Göran Andersson" wrote:
Yes, that works.

I use it myself in an application that adds a lot of records to a
database. The release version puts data in a buffer and saves them when
the buffer is full or has lived a certain time, but the debug version
flushes the buffer for each record so that they show up in the database
immediately.

musosdev wrote:
I've got a function that needs to work slightly differently on the
development server from the production server, but of course I don't want to
be changing code just before compiling a release version!?

I'm thinking I could use some #if #else #endif type statements to change
certain things, depending on the build type. I'm thinking of something like
this in my .cs file...

#if DEBUG
private string MyFunc()
{
// debug version
}
#else
private string MyFunc()
{
// release version
}
#end if

Would this work!? If not, how could I achieve a similar effect? (.net 2)

Cheers
Dan

May 8 '06 #3
Hi Goran...

I can't get this to work - I wonder if you could shed any light on it...

Basically, I've just setup a simple web, with a config and an aspx page,
which has the following in Page_Load()...

#if DEBUG
Response.Write("debug!");
#else
Response.Write("release!");
#endif

However, when I run this page (thru IIS), it *always* writes "debug!" - even
if I set compilation debug="false" in web.config.

Is there something else I need to enable?! I'm not using Web Publish or
anything like that, just a straightforward Rebuild and then point IE at the
webserver.

Any suggestions!?

"Göran Andersson" wrote:
Yes, that works.

I use it myself in an application that adds a lot of records to a
database. The release version puts data in a buffer and saves them when
the buffer is full or has lived a certain time, but the debug version
flushes the buffer for each record so that they show up in the database
immediately.

musosdev wrote:
I've got a function that needs to work slightly differently on the
development server from the production server, but of course I don't want to
be changing code just before compiling a release version!?

I'm thinking I could use some #if #else #endif type statements to change
certain things, depending on the build type. I'm thinking of something like
this in my .cs file...

#if DEBUG
private string MyFunc()
{
// debug version
}
#else
private string MyFunc()
{
// release version
}
#end if

Would this work!? If not, how could I achieve a similar effect? (.net 2)

Cheers
Dan

May 8 '06 #4
The setting in web.config is only used if the web server does the
compilation. If you build the solution in Visual Studio, it's the
setting in the Configuration Manager that is used.

musosdev wrote:
Hi Goran...

I can't get this to work - I wonder if you could shed any light on it...

Basically, I've just setup a simple web, with a config and an aspx page,
which has the following in Page_Load()...

#if DEBUG
Response.Write("debug!");
#else
Response.Write("release!");
#endif

However, when I run this page (thru IIS), it *always* writes "debug!" - even
if I set compilation debug="false" in web.config.

Is there something else I need to enable?! I'm not using Web Publish or
anything like that, just a straightforward Rebuild and then point IE at the
webserver.

Any suggestions!?

"Göran Andersson" wrote:
Yes, that works.

I use it myself in an application that adds a lot of records to a
database. The release version puts data in a buffer and saves them when
the buffer is full or has lived a certain time, but the debug version
flushes the buffer for each record so that they show up in the database
immediately.

musosdev wrote:
I've got a function that needs to work slightly differently on the
development server from the production server, but of course I don't want to
be changing code just before compiling a release version!?

I'm thinking I could use some #if #else #endif type statements to change
certain things, depending on the build type. I'm thinking of something like
this in my .cs file...

#if DEBUG
private string MyFunc()
{
// debug version
}
#else
private string MyFunc()
{
// release version
}
#end if

Would this work!? If not, how could I achieve a similar effect? (.net 2)

Cheers
Dan

May 8 '06 #5
Thanks.. think that's it.

Only problem is that for the Release profile, it won't let me select
"Release" configuration for one of projects in the solution - the only option
is debug.

Any idea why?!
"Göran Andersson" wrote:
The setting in web.config is only used if the web server does the
compilation. If you build the solution in Visual Studio, it's the
setting in the Configuration Manager that is used.

musosdev wrote:
Hi Goran...

I can't get this to work - I wonder if you could shed any light on it...

Basically, I've just setup a simple web, with a config and an aspx page,
which has the following in Page_Load()...

#if DEBUG
Response.Write("debug!");
#else
Response.Write("release!");
#endif

However, when I run this page (thru IIS), it *always* writes "debug!" - even
if I set compilation debug="false" in web.config.

Is there something else I need to enable?! I'm not using Web Publish or
anything like that, just a straightforward Rebuild and then point IE at the
webserver.

Any suggestions!?

"Göran Andersson" wrote:
Yes, that works.

I use it myself in an application that adds a lot of records to a
database. The release version puts data in a buffer and saves them when
the buffer is full or has lived a certain time, but the debug version
flushes the buffer for each record so that they show up in the database
immediately.

musosdev wrote:
I've got a function that needs to work slightly differently on the
development server from the production server, but of course I don't want to
be changing code just before compiling a release version!?

I'm thinking I could use some #if #else #endif type statements to change
certain things, depending on the build type. I'm thinking of something like
this in my .cs file...

#if DEBUG
private string MyFunc()
{
// debug version
}
#else
private string MyFunc()
{
// release version
}
#end if

Would this work!? If not, how could I achieve a similar effect? (.net 2)

Cheers
Dan

May 8 '06 #6
Hi Dan,

As for the following behavior you mentioned:

============
it won't let me select
"Release" configuration for one of projects in the solution - the only
option
is debug.
============

this is due to the new dynamic compilation model of ASP.NET 2.0
application, and as for ASP.NET 2.0 web project, it is different from
original ASP.NET 1.X/VS 2003 web project, there is no prebuilt project
assembly, all the stuffs are dynamically get compiled. So the debug/release
is depend on the web.config file's <compilation debug=xxx> setting. The
following blog article has a detailed description on the new compilation
behavior:

#Debug and Release Builds in ASP.NET 2.0
http://odetocode.com/Blogs/scott/arc...1/15/2464.aspx

Also, for ASP.NET 2.0 application, we can precompile the whole site, and
the ASP.NET dev team has provided a web deployment project that can help
control the precompilation more convenient which include specifying the
release/debug precompilation setting:
#Visual Studio 2005 Web Deployment Projects
http://msdn.microsoft.com/asp.net/re...structure/wdp/

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)




May 10 '06 #7
Hi Steven,

That's the third time I've read that blog post :o) Unfortunately, I'm still
no wiser.

Reading that, it looks like I can't get a release build of my code from
VS2005 unless I use the Publish command - is that right?

If that's the case, that's fine - but I'm getting "Ambiguous match" problems
when I do that. Is there no way to make a Release build without Publish or
WDP?

Thanks for your time (and patience!)
Dan

"Steven Cheng[MSFT]" wrote:
Hi Dan,

As for the following behavior you mentioned:

============
it won't let me select
"Release" configuration for one of projects in the solution - the only
option
is debug.
============

this is due to the new dynamic compilation model of ASP.NET 2.0
application, and as for ASP.NET 2.0 web project, it is different from
original ASP.NET 1.X/VS 2003 web project, there is no prebuilt project
assembly, all the stuffs are dynamically get compiled. So the debug/release
is depend on the web.config file's <compilation debug=xxx> setting. The
following blog article has a detailed description on the new compilation
behavior:

#Debug and Release Builds in ASP.NET 2.0
http://odetocode.com/Blogs/scott/arc...1/15/2464.aspx

Also, for ASP.NET 2.0 application, we can precompile the whole site, and
the ASP.NET dev team has provided a web deployment project that can help
control the precompilation more convenient which include specifying the
release/debug precompilation setting:
#Visual Studio 2005 Web Deployment Projects
http://msdn.microsoft.com/asp.net/re...structure/wdp/

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)




May 10 '06 #8
Thanks for your response Dan,

Actually the fixed "Debug" option in the VS 2005 SOLUTION for ASP.NET
project is just a dummy setting which won't make actual effect. That just
tell us that for ASP.NET 2.0 project, there is no concept of development
time prebuilt project assemblies. And for ASP.NET 2.0 pages and classes in
the App_Code, they will be dynamically compiled, and the debug/release
version just rely on the web.config's <compilation debug=...> setting.

Are you correctly put such case dependent code in page's codebehind for in
custom helper class's file? If in custom helper class, maybe you can
consider arrange them into a separate class library which will be more
convenient to control the debug/release output since class library project
is prebuilt at development time.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 10 '06 #9
Steven,

Thanks for the patience!

Okay, so last first... yeah, I could do that. But the code I'm altering is
really integral to the application, so I don't *really* want to seperate it
out if I can help it.

What's more worrying though, is that whether I compilation debug= to true OR
false in my web.config, I always get the debug version, which would indicate
that it doesn't seem to be making any difference?

I don't actually need the alternate functions, I could just replace before
the final build, but it's the fact that I can't seem to switch it which is
making me persevere!

Any ideas?!

"Steven Cheng[MSFT]" wrote:
Thanks for your response Dan,

Actually the fixed "Debug" option in the VS 2005 SOLUTION for ASP.NET
project is just a dummy setting which won't make actual effect. That just
tell us that for ASP.NET 2.0 project, there is no concept of development
time prebuilt project assemblies. And for ASP.NET 2.0 pages and classes in
the App_Code, they will be dynamically compiled, and the debug/release
version just rely on the web.config's <compilation debug=...> setting.

Are you correctly put such case dependent code in page's codebehind for in
custom helper class's file? If in custom helper class, maybe you can
consider arrange them into a separate class library which will be more
convenient to control the debug/release output since class library project
is prebuilt at development time.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 10 '06 #10
Thanks for your response Dan,

What's the actual behavior do you mean?

=======================
What's more worrying though, is that whether I compilation debug= to true
OR
false in my web.config, I always get the debug version, which would
indicate
that it doesn't seem to be making any difference?
=======================

Based on my local test, (in vs 2005 through file test server), the
conditional compiled block will just match the setting in the web.config's
<compilation debug=xxx> attribute. Also, I've tried set this attribute for
a particular sbu directory in the application directory and that worked(
the pages under that directory conforms to the sub web.config's compilation
setting).

Is there any particular setting or scenario in your application that could
cause the difference?

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


May 12 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dan Hartshorn | last post by:
VS.NET 2003, C#, Windows Server 2003. I have a datagrid and I want the last column to be either an EditCommandColumn or a template column, depending on a value I have. The value changes for each...
7
by: Tom | last post by:
How can I make code not execute for a debug build, but do execute for a production build? I have code which prompts for an account and password when the program starts up. It is a pain to have to...
0
by: Jeff User | last post by:
I have my datagrid running pretty much with a EditCommandColumn and some TemplateColumn columns. There are two types of appearance changes I would like to make programatically from my C# code...
11
by: Wayne Cressman | last post by:
I'm writing a function to dynamically change a form validation script depending upon the user's choices. The form onsubmit is: onsubmit="writevalidate(this.select.value);return...
45
by: Zytan | last post by:
This returns the following error: "Cannot modify the return value of 'System.Collections.Generic.List<MyStruct>.this' because it is not a variable" and I have no idea why! Do lists return copies...
2
by: pozitronic | last post by:
Hey all, I would like to do the following: I have 3 radio boxes. <input name="br" type="radio" value="first">Button1<br> <input name="br" type="radio" value="second">Button2<br> <input...
2
by: Gilbert Tordeur | last post by:
Hello, It is about a VB2008 intranet application. It uses a SQL Server database. The ConnectionString is defined in the connectionStrings section of the web.config file. This application uses...
4
by: mistral | last post by:
Does it possible change favicon icon depending on browser type: display favicon.ico for Internet Explorer browsers, and favicon.gif for the rest browsers? Problem is that ugly MSIE can display only...
25
by: Peng Yu | last post by:
Hi, It is possible to change the length of "\t" to a number other than 8. std::cout << "\t"; Thanks, Peng
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.