I have a simple program to look for pre-compiler constants:
#if TEST1
MessageBox.Show("TEST1");
#endif
Now if I build the following through the CLI, things are as expected. The messagebox shows "TEST1".
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild" "C:\tests\TestBuildConstants\TestBuildConstants.sln" /p:OutDir="C:\tests\TestBuildConstants" /p:DefineConstants="TEST1" /t:Rebuild
However, if I go to Project properties -> Debug -> Command line arguments, and enter this: /p:DefineConstants="TEST1" /t:Rebuild, it refuses to pass through the constant once I run the program.
The reason I want to go through the VS GUI like this is because I want to quickly be able to test and switch between various builds as I'm coding.
What have I missed?
The Project properties > Debug > Command line arguments are for the parameters to pass to application after it has been built when it is run by VS. They are not arguments for MSBuild. You need to go to the Project properties > Build page and change "Conditional compilation symbols" to include TEST1.
Related
I have a solution with two winforms project. Project A is used to launch multiple copies of project B, each with different args.
It works fine if I build project B and launch the exe from project A. Problem is I want to be able to step through project B once it has been launched by project A so that I can debug issues with the args being passed.
How do I set up the projects so that I can pass in the args and step through from project A to project B?
You can use Debugger.Launch() method. Write this to Project B's entry point and run Project A.
Debugger.Launch Method ()
Launches and attaches a debugger to the process.
Visual Studio lets you to set startup options like command-line arguments for application debugging.
As an option you can set the project you want to debug as startup project and then using Properties > Debug > Command line arguments set desired command-line arguments and press F5 to debug as usual.
The Command line arguments property specifies command-line arguments
to be called when launching the application.
For more information, take a look at:
How to: Set Start Options for Application Debugging
We are setting up our automated build, it's our first 64 bit C# autobuild.
Long ago I thought I remembered seeing the commandline of the build in the build output, but I don't see it now. I kind of remember the compiler in VS being different than MSBuild...
Is there some way to see what the command line equivalent of the current options in VS are? I want to compile it just like VS2013 does now.
Set the following settings to Diagnostic and then inspect the logs that are available in the Output window when you build your solution/projects in Visual Studio.
MSBuild project build output verbosity
MSBuild project build log file verbosity
Is there a way to see what the CSC (or VBC) parameters are, when building an application using the Visual Studio?
Visual Studio calls CSC.exe/VBC.exe behind the scenes. I want to know if there is a way to see that call.
I need this info to replicate the equivalent Build script using the command line.
I set the different levels of verbosity for the build, still I do not see any CSC.EXE call in the output window.
I'm really surprised why Microsoft did not put an easy way to see the underlying CSC command.
AJ if I go through your steps I get:
I do not see any reference to CSC
OK here is how I resolved this:
First I went to tools and options and set the verbosity to detail. (After this point still build output was empty).
Then I got Service pack for VS2010.
I also had similar issue for Visual Studio 2012 I had to get "update 4" to see the logs and CSC.EXE ion the output.
I think what you're looking for can be set up in your VS environment options. Under the Tools menu, select "Options," then "Projects and Solutions." Make sure "Show Output window when build starts" is checked.
Then, under "Projects and Solutions," select "Build and Run" and change the level of "MSBuild project build output verbosity." I changed it to "Detailed" as an experiment, but you can fiddle with the levels to get what you want.
Then, when you build/rebuild your solution, the easiest thing to do is to place your cursor in the build output window and search for "csc" (or "vbc" for VB). You should be able to see the entire command line call to the compiler.
EDIT
To answer your comment, change the "Show output from" drop-down option at the top of the output window from "Debug" to "Build" and do a build/rebuild without running the application in debug mode.
I have written this code in my console application:
#if DEBUG
args = new[] {"4478676e34432432434"};
#endif
if (args == null)
{
Console.WriteLine("Please enter IP for single testing for now.");
}
When the tester person wants to test my app and forgets to enter the argument to run the app with I still want him to see that message. But now it does not do that. Does it mean should I put the build also on "Release"? Does this "DEBUG" mean if we are in VS IDE or does it mean if we are in Debug/Release build?
You can give them a release build, instead. This is probably best, for reasons that #JoeEnos pointed out in his comment on your question.
Either way, it might be better to specify the command line arguments in the project properties, instead of in a conditional #if DEBUG. However, Visual Studio adds them to the local project properties, so it won't be checked in with the project, meaning that other developers won't have the command line arguments you used. In my experience, I've found this to be a good thing.
For information in adding command-line arguments for debugging, look at this MSDN entry
To specify command-line arguments for debugging
With a project selected in Solution Explorer, on the Project menu, click Properties.
Click the Debug tab.
In the Command line arguments field, enter the command-line arguments you wish to use.
Does this "DEBUG" mean if we are in VS IDE or does it mean if we are
in Debug/Release build?
It means the application has been built with the Debug configuration. By default the DEBUG symbol is defined only for this configuration (although you can change this in the project's build settings).
If you want the tester to see the message then provide him/her with a Release build. Use the debug version for your own development tests/purposes.
Visual Studio shows the exact command line use to compiler and link a C++ project under Project Properties -> C/C++ -> Command Line and Linker ->Command Line, but, I was not able to find similar property page for C# projects.
Does any know what's the best way to find out the csc.exe command line arguments used to compile a C# project
Instead of using csc.exe directly, I would recommend looking at msbuild instead. With msbuild, you just have to run msbuild yourProject.csproj to compile it.
Also, per this MSDN blog, the csc.exe command line you see in the output window isn't really being used.
In Visual Studio, go to Debug->Windows->Output. When you compile your project this window will show you the commands it is using to compile your code, including the CSC command(s).
Be sure chose the "Show output from: Build" in the option dropdown in the Output window.
See MSDN: Command-line Building With csc.exe
In Visual Studio 2010 go to
Tools->Options->Project and Solutions->Build and Run
change "MSBuild project build output verbosity" to something less filtering than Minimal (for example "Normal"). There will be a lot more talk in the Build Output window after this and you should be able to see the actual command line of how CSC was invoked.