I am running this msbuild scriplet from command line (other details ommited)
<MSBuild Projects ="#(ProjectsToBuild)"
ContinueOnError ="false"
Properties="Configuration=$(Configuration)">
How can I hide its output if I don't have any errors on compile ?
There are no parameters that you can add to a specific target in msbuild to get it to build without any command output. But you could wrap the call in a second target, then call the target by executing msbuild and using the /noconsolelogger flag:
<Exec Command="MSBuild $(MSBuildProjectDirectory)\$(MsBuildThisFile) /t:TargetToExecute /nologo /noconsolelogger"/>
msbuild output (mostly) comes from Logger objects. These objects are extensible; you can supply your own implementation, or you can use any of the built-in loggers.
If you're seeing console output from msbuild, you're seeing output from the built-in console logger. You can turn off the console logger using the /noconsolelogger command-line option.
Even with that option set, you'll still see a couple of lines of output: the startup message that includes the program name and the copyright message. You can suppress that output with the /nologo option.
Related
I am migrating a few solutions into azure devops and want to use the MSBuild Task to build them.
The are currently build using devenv with the following commands:
devenv.com file.vcxproj /rebuild "unittest debug" /project project_name
I thought I would try with
msbuild.exe file.vcxproj /p:Project=project_name /p:configuration="unittest debug"
But I am getting the error that the project does not contains the "unittest debug"
I would appreaciate any help I could get.
Thanks for reading,
The devenv command line you are using doesn't make complete sense.
file.vcxproj is a C++ project. If it were a solution, e.g. somesolution.sln, then the /project switch would make sense, e.g. if somesolution.sln included file.vcxproj then the following command would build file.vcxproj.
devenv.com somesolution.sln /project file
Solutions and projects have a 'configuration' and a 'platform'. "unittest debug" looks like an attempt to specify this information but the syntax is not correct. The correct syntax is
<configuration>|<platform>
The default configuratuion values are Debug and Release.
I suspect that
"unittest debug"
should be
"debug|unittest".
The original devenv command line can probably be rewritten as
devenv.com file.vcxproj /rebuild "debug|unittest"
The MSBuild equivalent is
msbuild.exe file.vcxproj /t:rebuild /p:configuration=debug;platform=unittest
The /build, /clean, and /rebuild switches on devenv map to MSBuild targets in the C++ project. The C++ project also expects configuration and platform as separate properties.
I have a huge C# project/solution with 30+ .csproj files/modules. When I try to do MSBuild FxCop warnings are thrown as errors. How do I disable warnings as error setting by modifying .sln file or as a MSBuild flag.
FYI: I'm Trying to import FxCop rules into SonarQube
Found a way to disable this via a compiler flag /p:CodeAnalysisTreatWarningsAsErrors=false passed to MSBuild
Final command that parallel rebuilds ResolverService with FxCop errors processed as warnings:
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /t:Rebuild ResolverService.sln /m /p:CodeAnalysisTreatWarningsAsErrors=false
This solution is preferable than going to each and every .csproj file and editing the <CodeAnalysisTreatWarningsAsErrors> tag to false.
I would like to work with 'Debug', 'Release', 'Debug_Unicode' and 'Release_Unicode'
I have been able to use the DEBUG_CONFIGURATIONS variable so that the 'Debug Unicode' configuration correctly gets used as debug
This is what I tried to do in the CmakeLists.txt file:
target_link_libraries(tests
optimized ${CMAKE_BINARY_DIR}/src/${CMAKE_BUILD_TYPE}/foo.lib
debug ${CMAKE_BINARY_DIR}/src/${CMAKE_BUILD_TYPE}/foo.lib
)
Clearly CMake is able to make a choice between debug and release at this point, as it has to choose the 'optimized' or 'debug' library.
However, CMAKE_BUILD_TYPE is an empty string.
The best that I have been able to come up with is to work with a separate solution file for each of the configurations,
passing in CMAKE_BUILD_TYPE myself:
cmake -G Visual Studio 11 2012 Win64 -DCMAKE_BUILD_TYPE=Debug_Unicode C:\foo
As Antonio was mentioning
target_link_libraries(tests foo)
or just
add_dependencies(tests foo)
would be sufficient to link the correct library from the same configuration.
If you want to do more advanced stuff, take a look at the generator expressions. They are configuration sensitive incl. in Visual Studio's multi-configuration environment and they would work also for the target_link_libraries() command.
So your example would look like:
target_link_libraries(tests ${CMAKE_BINARY_DIR}/src/$<CONFIG>/foo.lib)
I have used generator expression e.g. in custom commands that need to be aware of the output path of my DLL (if foo would be generating an MSTest DLL):
add_test(
NAME RunFooTest
WORKING_DIRECTORY $<TARGET_FILE_DIR:foo>
COMMAND vstest.console.exe /InIsolation /Platform:x86 $<TARGET_FILE:$foo>
)
And - just because you mentioned different solutions - you can use CMake to build a certain configuration from the command line. This would in your case look like e.g.
cmake --build C:\foo --target ALL_BUILD --config Debug_Unicode
I'm not sure how to do this. I have a batch script file I am using to do multiple msbuild calls. I don't want the msbuild output to pollute my command window, but instead I want it to dump into a log file. I'm not sure how to do this, but here's my script so far:
#ECHO Building shared libraries ...
msbuild "SharedLibraries.sln"
:: Not sure how to catch an unsuccessful build here for my GOTO ERROR?
:: Copy dll files to specific location
#ECHO Building primary application...
msbuild "Myapp.sln"
:: Not sure how to catch an unsuccessful build here for my GOTO ERROR?
:ERROR
So, how do I:
Dump the msbuild output to a log file?
Catch unsuccessful builds and go to the error label?
Adding the /fileLogger command line switch causes MSBuild to write the build output to file msbuild.log in the current directory, while the /noconsolelogger switch causes MSBuild to no longer write to standard output. The filename can be set using the /flpswitch as in the following example:
msbuild "SharedLibraries.sln" /nologo /noconsolelogger /fileLogger /flp:logfile=buildlog.txt
See MSBuild Command Line Reference for details.
Regarding your second question; MSBuild returns a non-zero exit code if the build failed, which can be processed as usual:
msbuild "SharedLibraries.sln" /nologo /noconsolelogger /fileLogger /flp:logfile=SharedLibraries.log
if not errorlevel 0 goto ERROR
msbuild "Myapp.sln" /nologo /noconsolelogger /fileLogger /flp:logfile=Myapp.txt
if not errorlevel 0 goto ERROR
:ERROR
I have a MSBuild .proj file that is compiling a mixture of C# and C++ projects.
The C# projects compile output (.exe/.dlls) to the OutputPath I specify, but when I specify OutputPath for the C++ projects (which calls vcbuild.exe), the OutputPath is ignored and instead goes into the directory specified in the Property Pages for the .vcproj.
Here's my MSBuild task:
<MSBuild Projects="$(SourceFolder)\$(NativeSolutionName)"
Targets="$(BuildTargets)"
Properties="Configuration=$(Configuration);PlatformName=Win32;OutputPath=$(ToolsOutputDir)">
</MSBuild>
How can I specify that the C++ output files should go to the same directory as the C# output files $(ToolsOutputDir)?
I was able to make this work by doing the following:
1) Installing the Microsoft SDC MSBuild Tasks Library
2) In the property pages for the C++ projects, setting the output directory to $(OutputPath).
3) Adding a SDC task to set the environment variable OutputPath before building the C++ projects via VCBuild:
<Microsoft.Sdc.Tasks.SetEnvironmentVariable Variable="OutputPath" Value="$(ToolsOutputDir)" Target="Process"/>
<!-- Build any CPP code x86 -->
<MSBuild Projects="$(SourceFolder)\$(NativeSolutionName)"
Targets="$(BuildTargets)"
Properties="Configuration=$(Configuration);PlatformName=Win32;OutputPath=$(ToolsOutputDir)">
</MSBuild>