I need a batch file that will conditionally compile my c# solution, I tried finding but nothing relevant retrieved.
Asked
Active
Viewed 218 times
0
-
2What kind of condition do you mean? Could you give an example? – Emond Nov 28 '13 at 06:59
-
By condition I meant #define regions with in the source code, what I want is I could just give the name of the region as input in my batch script and build it accordingly – user3044705 Nov 28 '13 at 07:02
-
possible duplicate of [msbuild, defining Conditional Compilation Symbols](http://stackoverflow.com/questions/479979/msbuild-defining-conditional-compilation-symbols) – Alexei Levenkov Nov 28 '13 at 07:05
-
The link @AlexeiLevenkov mentions points to MSBUILD documentation. In my answer I assumed you were looking for the C# compiler command line options. – Emond Nov 28 '13 at 07:07
-
I need an external batch file urgently, help me out with that – user3044705 Nov 28 '13 at 07:21
1 Answers
3
csc /define:DEBUG /optimize /out:File2.exe *.cs
and
void Foo()
{
#if DEBUG
PrintDebugInfo();
#endif
Bar();
}
This defines the constant DEBUG so File2.exe will contain the call to PrintDebugInfo.
See the MSDN csc.exe commandline options for more details.

Emond
- 50,210
- 11
- 84
- 115
-
+0: Note that you answered slightly different question - "how to compile single CS file with define", not whole solution. – Alexei Levenkov Nov 28 '13 at 07:06
-
@AlexeiLevenkov - correct. user3044705 will decide what the correct answer is/what he needs. I am happy to delete my answer if it doesn't answer the question and was answered in the duplicate you mentioned. – Emond Nov 28 '13 at 07:11
-
when I use the above code in my batch file(which I want it to be an external batch file) csc is not recognized as a command – user3044705 Nov 28 '13 at 07:18
-
@user3044705 - Make sure you use the Visual Studio Command prompt/environment. See http://msdn.microsoft.com/en-us/library/ms229859(v=vs.110).aspx – Emond Nov 28 '13 at 07:45
-
-
-
No, for an external batch file say at my dekstop, how do I navigate to my solution directory which I want to compile as per your given solution using csc – user3044705 Nov 28 '13 at 08:49
-
Either set all the environment variables in the batch file similar to the VS environment or pass the correct path to each file. Note that csc will NOT let you build a solution (sln) see the link provided by Alexei for that. – Emond Nov 28 '13 at 09:38