MsBuild linking libraries from command prompt - visual-studio-2010

I am able to build my VS2010 solution using MSBuild from the command prompt. I would like to write a batch file that builds a solution when executed. The only change would be the static library that is linked to the project. I cannot use dynamic libraries here. I tried the following:
msbuild test.sln /p:AdditionalDependencies=test.lib
It resulted in errors because of the library not being linked to the solution. Is there a way to link libraries from the command prompt?

Related

How to build icu data dll in windows?

I have tried numerous resources and I haven't really seen a proper command or way to build the icu data dll in windows.
So I have tried -
msbuild source\allinone\allinone.sln /p:Configuration=Release /p:Platform=x64
It builds the icudt62.dll but it had reduced data set.
I tried pkgdata with dll mode and runConfigureICU with --with-data-packaging=library and none of them seem to want to work properly in building the icudt.dll file (as in the command fails miserably with lot of errors).
I tried building from Visual studio and also in command line like this -
msbuild source\allinone\allinone.sln /p:Configuration=Release /p:Platform=x64 /t:MakeData
These two work and it builds the icudata dll fully but I am not sure this is the right approach since it seems to build tests also.
Has someone tried building/packaging the entire icu data (mainly dates and timezone mappings) from windows in command line? How do we build the icu data into a dll?
TIA.

Is there any way to extract compile_commands.json from MSBuild?

is there a way to extract the compilation database as compile_commands.json file with MSBuild on Windows?
Cmake based project allow you calling by:
CMAKE_EXPORT_COMPILE_COMMANDS=ON
How to solve or produce with MSBuild?
The way I have found--> Visual Studio allows you to perform via a plugin called Sourcetrail. It can be installed as extensions.

CMake run shell command after building error

I have a Visual Studio 2019 CMake project and i need to run a postbuild script which copys a file (The file is not generated by the build process). What i did so far is add a custom command in CMake with
add_custom_command(TARGET testExec POST_BUILD COMMAND "../postbuild.bat")
The postbuild.bat would copy the file. This works great most of the time but when my build fails due to some compile error, the postbuild script won't be executed.
How can i run the postbuild script even if the build fails ? I know there is a similar question here but sadly no proper solution. If there is a way to configure a postbuild event directly inside a Visual Studio CMake project this would also be suitable, but it seems like this is not possible (because in a cmake project i don't have a project file).
Since The copied file is not generated by the build you can use PRE_BUILD. On Visual Studio Generators, it runs before any other rules are executed within the target.(https://cmake.org/cmake/help/latest/command/add_custom_command.html).
The other solution could be to use add_custom_command(OUTPUT as the file seems independent of the build.

Compiling C++ files during runtime using Visual Studio compiler

I'm trying figure out how to compile C++ code from an executable during runtime using Visual Studio compiler under Windows.
I'll be using Visual Studio IDE to build main project into an executable and use CreateProcess to compile other C++ files and create a DLL to later load/use/unload this DLL.
I understand that one way of doing this requires setting environment variables(mainly PATH, INCLUDE and LIB) and there's a .bat file called "vcvarsall.bat" which does this.
The part I'm stuck with is the argument(s) passed to this batch file. I see that first argument is the platform with some of the options being x86, amd64, arm, etc. But how do I programmatically figure out which one of these arguments I should be using considering main executable could've been built with any one of these?
You can prepare a regular solutionfor this purpose, containing one project with a single file, and use it to compile your file easily.
Now, all you need is to reame your file to the file name in the project and compile a solution with command line. Alternatively, you can also edit the project and replace the existing filename with your file name.
To do so you need to resolve the environment variable %DevEnvDir% and run the folowing command with the platform name (x64, win32 etc.) and configuration name(Release or Debug)
like this:
%DevEnvDir%\devenv.com \path\to\yoursolution.sln /ReBuild "Release|x64"

How to use Clang compiler with MSBuild?

I'm trying to take a couple of projects normally compiled on Windows with Microsoft C++ and compile them with clang instead.
On the upside, there exists clang-cl.exe which is designed to be a drop-in replacement for cl.exe. However, even when I copy clang-cl.exe into the current directory as cl.exe, msbuild still in some cases calls Microsoft's cl.exe.
Is there a way to tell msbuild 'here, when executing Task CL, use this cl.exe instead of the usual one'? msbuild's command line options don't contain anything obvious in that direction.
Also, is there a way to tell it to supply or override command line parameters for cl without changing the project file?
This is easy to do from either command line or project file. The properties you need to configure are $(CLToolExe) and $(CLToolPath).
From the command line:
msbuild MyProj.vcxproj /p:CLToolExe=clang-cl.exe /p:CLToolPath=c:\whatever\path\to\the\tool
Alternatively, inside your .vcxproj file:
<PropertyGroup>
<CLToolExe>clang-cl.exe</CLToolExe>
<CLToolPath>c:\whatever\path\to\the\tool</CLToolPath>
</PropertyGroup>
If you are calling task CL directly inside your .vcxproj file, as opposed to just relying on common targets, just set corresponding parameters ToolExe and ToolPath of the CL task.
Since Visual Studio 2019 16.2, Microsoft provide an integration of MSbuild and ClangCl. So this can be achieved by:
Installing the “C++ Clang Tools for Windows” component
Choosing the "LLVM (clang-cl)” toolset in the IDE
Microsoft's blog post has more information on this: https://devblogs.microsoft.com/cppblog/clang-llvm-support-for-msbuild-projects/
I were using #seva solution for sometime, though in Visual studio version Version 16.10.1 it works for me only if the 'CL' prefix is omitted from the command line parameters. i.e.:
msbuild MyProj.vcxproj /p:ToolExe=clang-cl.exe /p:ToolPath=c:\whatever\path\to\the\tool

Resources