Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one build a .csproj from command line having a log written to a specified location?

While the 'no-log' build seems to work smoothly with something like

"c:\Program Files\Microsoft Visual Studio 9.0\Common7\ide\VCSExpress" Project1.csproj /build

the following fails:

"c:\Program Files\Microsoft Visual Studio 9.0\Common7\ide\VCSExpress" Project1.csproj /build /Log=log.txt

showing a window with this text:

Missing switch argument. Configuration name required for /build switch.

Use: vcsexpress [solutionfile | projectfile | anyfile.ext] [switches]

The first argument for vcsexpress is usually a solution file or project file. You can also use any other file as the first argument if you want to have the file open automatically in an editor. When you enter a project file, the IDE looks for an .sln file with the same base name as the project file in the parent directory for the project file. If no such .sln file exists, then the IDE looks for a single .sln file that references the project. If no such single .sln file exists, then the IDE creates an unsaved solution with a default .sln file name that has the same base name as the project file.

Command line builds: vcsexpress solutionfile.sln /build [ solutionconfig ] [ /project projectnameorfile [ /projectconfig name ] ] Available command line switches:

/Log Logs IDE activity to the specified file for troubleshooting. /ResetSettings Restores the IDE's default settings, optionally resets to the specified VSSettings file. /SafeMode Launches the IDE in safe mode loading minimal windows.

Product-specific switches:

To attach the debugger from the command line, use: VsJITDebugger.exe -p

[I am using Visual Studio 2008 Express]

So, the questions are:

  • Is there a way to ensure that the log file is written somewhere?

  • Or is the /Log switch only supposed to be used when the IDE is run in GUI mode? If so, are there workarounds?

like image 290
mlvljr Avatar asked Mar 02 '11 23:03

mlvljr


2 Answers

Under the hood, Visual Studio uses msbuild for all it's build magic. As far as I know, this applies to the Express editions as well.

If you don't have it already, MSBuild is a part of the .NET SDK.

Calling MSBuild has the advantage of doing the build directly - calling VCSExpress will just introduce overhead.

Here's the MSBuild commandline that I've used:

msbuild.exe <solution> 
    /t:rebuild 
    /verbosity:quiet 
    /logger:FileLogger,Microsoft.Build.Engine;logfile=<filePath>

Should work the same with <project> instead of <solution>.

like image 171
Bevan Avatar answered Sep 19 '22 03:09

Bevan


You have to specify the configuration after the /build option. Also, the log file must already exist, it doesn't create one from scratch. Thus:

copy con > log.txt
^Z      // Type Ctrl+Z
"c:\Program Files\Microsoft Visual Studio 9.0\Common7\ide\VCSExpress" Project1.csproj /build debug /log log.txt
like image 44
Hans Passant Avatar answered Sep 17 '22 03:09

Hans Passant