MSbuild and project optimization - msbuild

I'm using MSbuild class for compile visual studio 2010 projects from module of my programm.
But I can't find how to tell compiler which optimization flags it must use.
There is only Optimize property on MSBuild and only tag at .vcxproj file. But I want to play with such compiler switch like /Os /Ot /Oi etc. How to do that?

There is standard CL Task in MSBuild, which is represented by
<ClCompile>
tag in .vcxproj file. So it's possible to playing with compiler switches via Parameters of this task

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.

Changing the compiler executable in a custom MSBuild toolset

I'm writing a VS integration for a custom C++ toolchain (.props, .targets, .xml files). Where can I specify the path to the compiler executable? If I set the value of <ExecutablePath> then it will search for cl.exe in that folder, but what if my program is not called cl.exe? Is there any way to handle this?

How to use Nemerle in msbuild/MonoDelevep project files

I have a project which (for reasons beyond my control) uses MonoDevelop's build system. I'm unfamiliar with its build system, but I understand it IS the msbuild project format.
I can include Nemerle sources by invoking the Nemerle compiler as a separate pre-build step, but that means I have to manually keep all compiler settings/switches/defines/etc in sync between both the msbuild project files and the Nemerle compiler command line. Obviously, that's problematic.
How can I set up my project's msbuild project files to include Nemerle sources and correctly invoke the Nemerle compiler?

MSBuild: Problems specifying platform for child builds

Is it possible to specify the target platform (x64, x86) when building a project?
I have a build task that looks as follows:
<MSBuild Projects="%(AgentProjectFiles.FullPath)" Properties="Architecture=x86;Configuration=$(Configuration);Optimize=$(Optimize);Platform=$(Platform);OutputPath=$(OutputDirectory)\Agent\;ReferencePath=$(ReferencePath);DebugSymbols=$(DebugSymbols);DebugType=none;" />
As you can probably tell, I've thrown everything possible I have seen online into the Properties attribute in the hope that it will work. You will notice that for the Architecture property I've set it to be x86 explicitly. the $(Platform) is also set to x86. I've tried a number of permutations, without success.
Unfortunately, it seems that no matter what gets put into these properties, my class libraries are x86, but my executables are x64.
I thought perhaps the problem could be that the build properties specified in the project file itself were causing MSBuild to ignore the ones I pass through from MSBuild, but after changing these to x86, I still have the same problem.
Any ideas?
In the declaration of the AgentProjectFiles item are you defining the Properties metadata. So does it look like:
<ItemGroup>
<AgentProjectFiles Include="something.proj">
<Properties>SOME VALUES HERE</Properties>
</AgentProjectFiles>
</ItemGroup>
If you have defined that then the properties passed into the Properties attribute of the MSBuild task are ignored. I've bloged about this MSBuild: Properties and AdditionalProperties Known Metadata.
Sayed Ibrahim Hashimi
My Book: Inside the Microsoft Build Engine : Using MSBuild and Team Foundation Build