MSBuild: error MSB4126: The specified solution configuration "Release|AnyCPU" is invalid - c++

I am stumping my head on this. I am trying to build libconfig on Windows - an OS that I am very unfamiliary with. I have installed the MSBuild Tools. I am able to compile CMake projects by using the NMake Generator and then compiling the resulting Makefile. libconfig has a .libconfig_vs2017.sln, which seems to be a "solution" file for the version of MSBuild I have installed.
Before compiling I have ran "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Auxiliary/Build/vcvars64.bat" because otherwise none of the necessary tools appear to be in the path.
No matter which combination I try, I always keep getting an error that the specified solution configuration is invalid. I have tried the following options:
msbuild libconfig_vs2017.sln
msbuild libconfig_vs2017.sln /p:Configuration=Debug /p:Platform="Any CPU"
msbuild libconfig_vs2017.sln /p:Configuration=Release /p:Platform="Any CPU"
msbuild libconfig_vs2017.sln /p:Configuration=Debug /p:Platform="x64"
msbuild libconfig_vs2017.sln /p:Configuration=Release /p:Platform="x64"
msbuild libconfig_vs2017.sln /p:Configuration=Debug /p:Platform="x86"
msbuild libconfig_vs2017.sln /p:Configuration=Release /p:Platform="x86"
What am I missing here to get this thing to compile on Windows? I am considering installing autotools but given that there is a supposedly ready to use solution file that seems overkill (and is probably difficult on Windows in its own right).

Related

How can I import a CLion C++ project into Visual Studio?

It seems like this should be easy and I've spent hours trying to find this answer online but haven't had any luck.
I can open the CLion folder path in Visual Studio, but that option doesn't give me the usual options to build and start the project. To do that, I need to open CLion as a Project/Solution, but I can't seem to do this.
My professor requires that my C++ code be executable in Visual Studio, but I prefer CLion. So I've done all my work in CLion and want to test that it runs in Visual Studio. How can I import my CLion project?
Thanks!
The link provided describes Visual Studio's CMake integration, which (similar to CLion) will install a version of CMake that Visual Studio will use. These instructions are pretty thorough and should provide everything needed to get your CMake project working in Visual Studio.
Now, you probably have two versions of CMake installed on your machine, one that came with CLion and one that came with Visual Studio. I would recommend installing the latest version of CMake on your machine separately, and configuring both Visual Studio and CLion to use that version instead. However, this is probably getting outside the scope of your immediate problem.
As you follow the Microsoft's instructions for "CMake projects in Visual Studio", you mentioned receiving the error:
1> [CMake] CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.17/Modules/CMakeDetermineSystem.cmake:173 (file):
1> [CMake] file failed to open for writing (No such file or directory):
This looks like a permissions issue, specifically while running CMake within Visual Studio, so be sure you have read/write access to all the files in your project, and the CMake packages in your Visual Studio installation. Hopefully, this doesn't require you re-install Visual Studio in another location on your machine, or run Visual Studio with elevated privileges, but perhaps that is necessary.
If you decide to install CMake separately, the instructions would be the following:
Install the latest CMake on your machine (somewhere you have adequate permissions), and ensure it is available in your Path environment variable. You can verify this by running cmake -version from the command line to see it is the version you just installed.
Using Windows command prompt, navigate to your CMake project directory (containing the top-level CMakeLists.txt file), and run the following:
mkdir build
cd build
cmake -G "Visual Studio 16 2019" -A x64 ..
You may run -A Win32 with the cmake command instead if your project is a 32-bit build.
Open the .sln Visual Studio Solution file that was generated in the build directory. Once, the Solution is loaded in Visual Studio, you can build the project (CTRL + SHIFT + B).

How can I build all configurations with MSBuild VS2015 from the command line?

In previous versions of MSBUILD you can build all configurations in a solution using the following command line arguments:
msbuild /t:BuildAll /Configuration:"Debug;Release;ContinuousIntegration"
as shown here
However this does not work with MSBUILD VS2015 and gives the following error:
MSBUILD : error MSB1006: Property is not valid.
Switch: Release
This is a similar question to the one here however I am not using cmake just simply straight MSBUILD
For example:
C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\MSBuild.exe"Uninstaller.vcxproj /property:Configuration=Release'
Sometimes you need run this for setting environment
"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat"'

How to compile big c++ project using MsBuild.exe with x64 compiler

I have the big Visual Studio 2015 C++ project and can't compile it on the computer with 12GB RAM (fatal error C1060: compiler is out of heap space).
Command line:
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" Project.sln /t:Rebuild /p:Configuration=Release;Platform=x64
I've read this https://msdn.microsoft.com/en-us/library/x4d2c09s.aspx?f=255&MSPPError=-2147217396
and decided to use x64 compiler, but I can't figure out how it can be done using MsBuild.exe (or with another way but without generate make file - it is hard to maintain it because the project frequently changed).
I was tried to call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat" before MsBuild.exe, but it doesn't help.
Found solution here: https://msdn.microsoft.com/en-us/library/ee662426.aspx?f=255&MSPPError=-2147217396
Where is the property PreferredToolArchitecture which by default equals x86.
Set it to x64 to use the 64-bit compiler and tools to build your application.
msbuild myProject.vcxproj /p:PreferredToolArchitecture=x64

How to build a QT-project in visual studio from command line

I am trying to automate the build process for one of my QT-project. I used the following command in my batch file for non-QT projects
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" "myproject.sln" /build "Debug|x64" /projectconfig Debug
but it is not working for my QT project. Am I missing something?
Here is an example on how to do that (command by command):
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
cd <my_project_directory>
qmake
nmake
The first command sets up the environment for using Visual Studio tools.
Second command changes the current directory to one where your Qt project file is (you have to have one).
Third command runs Qt's qmake.exe utility to generate make files.
And finally nmake will build your project.
However, if you don't use Qt project files and have only VisualStudio solution, you can use MSBuild utility, like:
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
MSBuild your_solution.sln /p:Configuration=Debug
You can also set additional environment variables, such as QTDIR if it does not find your Qt installation.
If somebody finds this question looking for an answer on how to automate the build process of a QT project, and wants to do it using a BATCH file as the original question states, here is the BATCH script that I used to automate my building process:
#echo off
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86
cd %path_to_your_repo%
nmake /f Makefile.Release clean && qmake.exe %path_to_your_.pro% -spec win32-msvc "CONFIG+=qtquickcompiler"
nmake qmake_all
nmake -f Makefile.Release
It is important to call the vcvarsall.bat the first thing, as this will set the environment for all visual studio tools. Also make sure to launch it with call, if you just start the batch file as in #vahancho's answer it will stop your script after executing vcvarsall.bat.
The clean step is not necessary but it is a good practice to use it before building.
It is important to select the -spec and CONFIG (if any) during the qmake step, as this will allow you to select the compiler and required configuration if you are using some extra QT configuration.

Building Visual Studio 2008 solution from command line

I'm trying to automate the building process for a certain open source project. It will do an update on the SVN directory, use CMake to get a .sln file, and build that. I can successfully do this manually, and do svn and cmake from a batch script, but Now I need to build the solution.
A quick google search revealed:
devenv /build release /project <projname> <solutionfile>.sln
However, that uses the latest version of visual studio (Visual Studio Professional 2011), while the .sln file generated is for Visual C++ Express 2008. I have both versions installed on my computer. Is there a devenv I can use for Visual C++ Express 2008? Or is there a commandline argument to specify which version to use?
UPDATE
I tried using msbuild, but that didn't seem to like building .vcproj files directly, and I didn't want to build ALL the project files by having it build the .sln file. I ended up using this:
"C:\Program Files\Microsoft Visual Studio 9.0\VC\vcpackages\vcbuild.exe" <myproj>.vcproj "Release|Win32"
I think you are using the wrong tool to build this. Rather than trying to drive the IDE from the command line you should simply use msbuild.
msbuild.exe projectname.proj /property:Configuration=Release
In order to set your environment up for the specific version of MSVC you need to call the vcvar.bat file from that specific version. This will set up the necessary environment variables needed by the build tools.
For Visual Studio Express 2008 the IDE is called VCExpress.exe. Also you should probably specify the full path of the program when you have two versions installed:
C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\VCExpress.exe /build release /project <projname> <solutionfile>.sln