convert devenv parameters to msbuild parameters - msbuild

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.

Related

How to use MsBuild.exe to build a fortran/c mixed project?

1. Background
I have a project which is managed by cmake, I then generate the solution files by Visual Studio 2019 geneartor. The folder strucutre looks like:
- main.sln
- fotran_proj.vfproj (output a static lib libfortran.lib)
- C_proj.vcxproj (dependent on libfortran.lib)
- ALL_BUILD.vcxproj
It contains both fortran and c projects, and c project is dependent on fortran project.
I want to build the whole solution from commandline by msbuild.exe.
2. Environment
I use VS2019 with Intel Fortran Compiler on win10.
3. Question
When I try to use msbuild.exe to build it:
MSBuild.exe /t:build ALL_BUILD
It simply build the vcxproj part and ignore the vfproj parts. Why? How can I achieve this?
To the best of my knowledge, you can't do this. Intel Fortran's build system isn't recognized by msbuild, though that integration might happen sometime in the future.
What you can do is use devenv from the command line to build your mixed-language solution. From an Intel Fortran command prompt window (or one where you have established the Intel environment), type devenv /? to see the usage and options. For example, I built a mixed-language solution as follows:
devenv C_calls_F.sln /build "Debug|Win32"

Is it possible to build cmake projects directly using MSBuildTools

Currently we are planning to use VS2017 with a cmake project. Inside Visual Studio this works quite like a charm.
Now want to run our builds as part of CI on a dedicated build master running MSBuildTools.
Is it possible to directly run the build using the msbuild command, without creating solution files with cmake? Optimally, I would even use the CMakeSettings.json used from VS2017.
Use the build-tool-mode of CMake for this. It uses the underlying default build tool which is MSBuild for Visual Studio Generators.
From the build directory call:
cmake --build . --target ALL_BUILD --config Release -- /nologo /verbosity:minimal /maxcpucount
and you get a fast, nearly quiet build. To install use INSTALL target, for running your tests if configured use RUN_TESTS target.
Is it possible to directly run the build using the msbuild command, without creating solution files with cmake?
Is it possible to directly run the build using the msbuild command, without creating solution files with cmake?
As far as I know, CMake produces Visual Studio Projects and Solutions seamlessly. So you can produce projects/solutions.
The only tricky part is to remember to make any changes in the cmake files, rather than from within Visual Studio.
In particular, each CMake project will create a Visual Studio solution (.sln file), while all of the CMake targets belonging to that CMake project will appear as Visual Studio projects within the corresponding solution.
CMake Visual Studio
project <-> Solution (.sln)
Target <-> Project (.vcxproj)
You can check cmake-and-visual-studio for more details.
Since MSbuild can build both solution files and project files, so you could also call msbuild INSTALL.vcxproj
Is it possible to even use the CMakeSettings.json used in VS2017?
The answer is yes, check the blog for details.
If your CMake project requires additional settings to configure the
CMake cache correctly, you can customize these settings by creating a
CMakeSettings.json file in the same folder with the root
CMakeLists.txt. In this file you can specify as many CMake
configurations as you need – you will be able to switch between them
at any time.
You can create the CMakeSettings.json file by selecting the Project >
Edit Settings > path-to-CMakeLists (configuration-name) menu entry.

Is it possible too use Opencover with CTest?

I am new using Opencover and I would like to know if it is possible to use it with CMake tests because my project is already using it.
mkdir build
cd build
cmake ..
cmake --build . --config Debug
..\tools\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"C:\Program Files (x86)\CMake\bin\cmake.exe" -targetargs:"--build . --target RUN_TESTS --config Debug"
And the corresponding error:
Committing...
No results, this could be for a number of reasons. The most common reasons are:
1) missing PDBs for the assemblies that match the filter please review the
output file and refer to the Usage guide (Usage.rtf) about filters.
2) the profiler may not be registered correctly, please refer to the Usage
guide and the -register switch.
I tried to add the switches targetdir and/or searchdirs to bin\Debug and also register but with the same result.
Do you have any idea on solving this?
Thanks for your help!
OpenCover only works for .net project running on the windows .net runtime.

How to set the `OutDir` in the command link with Mono's xbuild.exe?

I'm trying to build a c# solution in msysgit (Windows) using the same build command that I would with msbuild:
"C:/Windows/Microsoft.NET/Framework/v4.0.30319/msbuild.exe" /p:Configuration=Debug /p:OutDir="c:\projects\proudly\build" "src/Proudly.Identity.sln"
With msbuild, the output of the build goes into my /build folder and all is well. Now, when I run the same command with Mono's xbuild, like this:
"C:/Program Files (x86)/Mono/lib/mono/xbuild/12.0/bin/xbuild.exe" /p:Configuration=Debug /p:OutDir="c:\projects\proudly\build" "src/Proudly.Identity.sln"
...and my the build output goes into the /bin/Debug folder of each project instead of my build folder.
I was under the impression that xbuild can be using just like msbuild. Any clue what I'm doing wrong?

Is there a workaround that I can use so that I can test the build type when using CMake in combination with Visual Studio and multiple configurations?

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