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.
Related
I am developing a c# Excel DLL addin in VS Code Ver 1.42.1. I quickly got an initial C#-only test version working using the VS code editor with only manual Command Line (CL) compiler commands below:
csc -t:library -debug -out:Eandin.dll -r:system.dll[....more...] Eaddin.cs
csc -t:exe -debug -r:Eaddin.dll -r:system.dll[...more...] Test_Eadin.cs
I am able to successfully manually CL compile this with above commands and then run. But I now need the debugger to debug, test, and validate my app and code. In VS Code, I have created numerous variation of tasks.json and launch.json to automate my manual commands. My *.json files work to build and launch (^shiftB & F5) in VS code. The code runs and produces output, but the debugger does not work.
I think my problem is not sufficiently understanding dotnet c# compilation. Or what?
Can someone please provide guidance on how to accomplish this?
Thank you.
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.
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 an Visual Studio 2012 Solution that includes both C# and C++ projects.
I want to create a postbuild step and I notice that the C++ projects have much more macros than the C# projects. I need to get the WindowsSDKDir which is available in the C++ macros but not in the C# macros.
C++ Macros
C# Macros
Can I see all the Macros that are available to the C++ projects in the C# projects??
I can think about the following workaround. Write this post-build command:
$(ProjectDir)post_build.bat
Create post_build.bat file in the project directory and fill it by this way:
echo %WindowsSdkDir%
echo %WinDir%
Build the project, it prints:
ECHO is on.
C:\Windows
So, C# is not smart enough to see Visual Studio build environment variables (%WindowsSdkDir% is expanded to nothing), but at least general environment variable like WinDir is expanded. So, you can create your own environment variable with the same value as WindowsSDKDir and use it in batch file called from Post-Build step.
To make something more useful then echo, create batch file with parameters (%1%, %2% etc.) and call it from post-build step, passing required parameters. For example:
$(ProjectDir)post_build.bat $(TargetPath)
In the batch file %1% will be expanded as output file name.
Simply call the batch file that sets up environment variables for a Visual Studio command prompt as the first line of your build event. This will set up all the environment variables for use in later lines of your build event. For example...
call "$(DevEnvDir)..\..\VC\vcvarsall.bat"
"%WindowsSdkDir%bin\x86\rc.exe" <parameters>
Note that the environment variables are Windows environment variables and need to be accessed via the %VAR_NAME% syntax rather than the $(VAR_NAME) syntax.
The location of the vcvarsall.bat file is consistent over at least VS2012, 2013 and 2015, meaning that this solution is generic and doesn't need tweaking for different VS versions.
If you use msbuild you will find that $(DevEnvDir) is not set correctly when building in msbuild. In that case, this alternative should work for both msbuild and visual studio build providing you have not customized the visual studio install location.
call "%ProgramFiles(x86)%\Microsoft Visual Studio $(VisualStudioVersion)\VC\vcvarsall.bat"