Process the output of msbuild - msbuild

I am writing an app in C# that will call MSbuild.exe for a given solution file.
I use System.Diagnostics.Process to start msbuild.exe and fetch the output of that exe through its standard output stream.
I want to know the results - what errors occured, in which file and line etc... Is parsing the output string of MSbuild.exe the only way? Or are there ways to get the results in objects or arrays or something?

MSBuild just outputs strings. I'm pretty you're going to have to direct the output to a file or files and parse that. At that point you can do what you like with it and load object collections or whatever.

MSBuild has a massive variety of logging options to suit your every need, from text to XML to cusotm ones. You'll also want to understand how you can subset outputs into multiple potentially overlapping files etc.
Start with msbuild /?
If you're doing anything remotely interesting, a copy of Inside MSBuild 2nd edition will pay for itself in about 20 mins though - it has samples.

Related

how do I output my code to a single file?

I need to dump all of my code for my project into a single text file. Is this possible in Visual Studio 2010? I haven't been able to find any options for this in VS. Is there a third party program that can do it? Every search I've done just turns up "how to print from VB", but does not address printing my actual code. Even if I have to do it module by module, that would be acceptable, but copying and pasting is a bit much.
Just FYI, I'm not talking about printing output from my program. I'm talking about printing the program itself.
Thanks.
This can be done outside of visual studio. Start a command prompt, cd to your project directory and:
type *.vb >filecontent.txt
If you have multiple project folders, you'll need to do this for each one as the type command doesn't have a /s subfolder type of parameter.
Alternatively, you could create a batch file that changes to each folder and performs the type command to output the file contents.

How does VS2010 compilation knows to skip un modified files

I created some msbuild scripts that build my projects using msbuild task. I pass as parameters the list of projects to build (not the solution file).
In VS2010, building the solution the second time without modifying any files will finish almost at the same time since it detect that nothing was changed.
Executing the msbuild scripts the second/third/forth time will take the same time.
Any ideas how to make the msbuild to behave the same as vs2010?
Thanks,
Eran.
Many MSBuild tasks shipped by Microsoft, uses IncrementallBuild or Filetracker in order to track which files were used to produce outputs of given file. Knowing relation between inputs and outputs MSBuild can create dependency graph.
By comparing timestamp of output file and all input files can eliminate execution on many tasks. If timestamps of all input files for given output file are "lower/before" than output file, it means none input file were modified, MSBuild can skip execution of this task.
I case of VC++ project this information is logged into *.tlog files (stored in IntermediateDirectory $(IntDir) of project).
By execution of target Rebuild you can skip using IncrementalBuild feature it because rebeuild means clean and build (so tlog files are deleted).

CDash Custom Dynamic Analysis

I'm trying to integrate custom dynamic analysis tools to CDash. Such as KWStyle, CppCheck and Visual Leak Detector.
I'v figured out that I need to generate a DynamicAnalysis.xml file and submit it to CDash, from CTest scripts.
I think I know how to run the external tool as a part of the ctest script.
Either by using these variables to change how ctest_memcheck() works
CTEST_MEMORYCHECK_COMMAND
CTEST_MEMORYCHECK_SUPPRESSIONS_FILE
CTEST_MEMORYCHECK_COMMAND_OPTIONS
or by running the tool from the execute_process() command.
But I'm a bit uncertain which one to use.
The main problem I think I have is, how can I extract errors from the output of the custom tool and include that information into the DynamicAnalysis.xml to submit?
The extreme solution i see is that i'd need to make a program that generates a valid DynamicAnalysis.xml file.
But the problem is that I don't know the syntax of the DefectList element in the XML file. I have found no answer from google and even the XML Schema for that file is unhelpful.
EDIT:
Looking at this:
http://www.cdash.org/CDash/viewDynamicAnalysis.php?buildid=987149
What draws my attention are the labels, especially the empty ones. I don't see how these would come from the DynamicAnalysis.xml file. Maybe it tracks any labels that have ever appearred? Can i create my own custom labels somehow?
Does CDash create the labels automatically, depending on the tool type? Does this block custom defect types?
I'm just guessing here, so the question is; can i create custom labels for my custom tool, just by generating a DynamicAnalysis.xml - file.
It occurred to me that the amount of different errors from CppCheck (static code analysis) is huge, compared to valgrind for instance. I'm not that certain that I should use the dynamic analysis. Maybe a custom build type (Continuous / Experimental / Nightly) thing would work better. Like this:
http://www.cdash.org/CDash/buildSummary.php?buildid=930174
I have no idea how to do this, i guess it requires meddling around with CDash code?
Which one would work better?
If you are using valgrind, you can simply set CTEST_MEMORYCHECK_COMMAND to the full path to valgrind, and ctest will generate the DynamicAnalysis.xml file for you from the valgrind output when you call ctest_memcheck.
The best way to understand the possible values that can appear in the DynamicAnalysis.xml file is to analyze the source code of CTest.
The file CMake/Source/CTest/cmCTestMemCheckHandler.cxx has the list of defect types in a variable named "cmCTestMemCheckResultLongStrings". Search through that file for references to that variable to see what the possible values are and how they are used to generate "<Defect/>" xml elements.
EDIT (for additional information):
You can also easily see what XML elements CDash is expecting by inspecting its source code. Specifically, the file "CDash/xml_handlers/dynamic_analysis_handler.php".
From what I'v learned so far, is that for a tool that runs on the tests made in the cmake script, the Dynamic Analysis is the thing.
For tools that run on the entire program, a custom Build.xml is the thing you need.
I found out that i can commit those files from the ctest_submit command by using the FILES parameter.
I also found out that you can add custom "build names" to the side of Continuous, Nightly, and others.
And that you can set the builds from certain machines to be automatically transferred under these.
The custom labels under DynamicAnalysis did come from somewhere in CDash, i can't remember where anymore.

Replace token in text file with content from another text file in MSBUILD

I have 2 MULTILINE text files, I want to combine them into a third file in an Msbuild script.
Ideally, I would have a token in one file, say %REPLACEME%, somewhere in the middle of that file, and I would want it replaced with the contents of the 2nd file (which contain multiple lines of text).
I want to do this in MSBUILD, although a Windows Shell solution would suffice, and so would the usage of some 3rd party utility (preferably small, and a single exe).
The solution is trivial if the content of the replacement text file is just one line .. but that is not the case.
Note that I want to AVOID using Powershell, I also want to avoid building my own MsBuild Tasks.
Thanks
You can use the MsBuild Community Tasks which have a RegexReplace task. I use it for my builds without any problem

How do I effectively use Batch Scripts?

I would like to create some batch scripts to move some files around. But i was wondering if there are any good resources on how to do this? Do you just use Command Line arguments?
At its simplest level, a batch script is a text file with a .bat extension, and consists of the same commands you would enter at the command line, separated by carriage returns.
Thus, the file:
md C:\HelloWorld
Is a batch script that attempts to create the directory "HelloWorld" on your C: root.
Batch scripts can be much more complex, involving variables and flow control logic, but before you travel that road, you may want to investigate powershell and WSH.
Edit Oops... fixed the link to powershell.
Basically, you just do command-line argument. But there are certain types of variables supported, and also command-line arguments to the batch file, which you can use.
http://www.computerhope.com/batch.htm