How to compile C++ Projects from Command Line - visual-c++

I have to compile a Visual C++ solution from command line. I can't do it with devenv.exe but can install .Net Framework SDK. Can I use the solution and project files to compile from the command line? If so how?

If the .net framework SDK comes with msbuild, then just invoke:
msbuild mysolution.sln
That will cause a msbuild project to be generated from the solution, and the msbuild project will in turn instigate a call-out to vcbuild. All solution level and project level dependencies will then be resolved and built in-order as needed.

Related

Msbuild fails to package a Service Fabric project with a c++ dependency

I have a Service Fabric project with this structure:
MyServiceFabric.sfproj
MyService.cspro
MyCommonCppMixedDll.vcxproj
If I compile from VS and from the command line:
msbuild MyServiceFabric.sfproj /p:Configuration="Release" /p:Platform="x64"
everything compiles as expected. When I try to Publish the project from VS, it works, but from the command line it fails. This is the command line I'm using:
msbuild MyServiceFabric.sfproj /p:Configuration="Release" /p:Platform="x64" /t:Package
the errors I'm getting, are related to the c++ project, that it fails to compile the platform Win32. If I remove the platform win32 from the c++ project, I receive the error:
This project t doesn't contain the Configuration and Platform combination of Release|Win32.
Obviously I don't want to compile half of the project in x64 and the c++ project in win32. For some strange reasons msbuild doesn't forward the platform to the c++ project.
I've seen in Microsoft.Cpp.Default.pros line #88 that if the platform is not specified, it default fall in Win32.
Any Ideas ?

MSBuild using the wrong cl.exe when building with the 2015 C++ v140 Platform Toolkit

We're currently making a build environment for some of our projects.
In particular we're using VC++ 6.0 and VS2019 to build some of these projects.
When building our C++ project in VS2019 with the Platform Toolkit set to C++ 2015 v140, MSBuild attempts to use the VC++ 6.0 compiler to build the project. If I switch the Toolkit to any other version it builds with the correct cl.exe.
If I remove the VC98 folder that contains cl.exe from the path environment variable I get a cl.exe can't be found error in VS2019.
So I think there's something hardcoding the 2015 toolkit against the VC6.0 cl.exe.
I've tried installing and reinstalling the additional components in the VS Installer but no luck.
Repair of VS2019 didn't fix it either.
I've tried all versions of Visual Studio back to 2013 same issue.
This looks like an MSBuild issue, it's in the wrong location.
Is there any place where I can view the mapping for the toolkits in MSBuild? I couldn't see much in the registry.
The output when I build shows the following, the version is clearly a very old compiler (the VC6.0 one):
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86

MSBuild on Centos returns "The imported project "/Microsoft.Cpp.Default.props" was not found"

I'm trying to build a VS project in CentOS. I installed dotnet-sdk-2.2 via yum install dotnet-sdk-2.2.
When executing dotnet msbuild myproj.vcxproj I get:
Microsoft (R) Build Engine version 16.1.76+g14b0a930a7 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
mtproj.vcxproj(19,3): error MSB4019: The imported project "/Microsoft.Cpp.Default.props"
was not found. Confirm that the path in the <Import> declaration is correct, and that the
file exists on disk.
Googling results with many solutions but for Windows. what can I do to resolve this over Linux/CentOS?
According to your error message it's a C++ project.
Please check this document,the dotnet CLI only supports .NET / .NET Core / .NET Standard projects.
C++ projects are part of the visual studio tooling (c++ workload). The dotnet CLI doesn't contain the visual c++ compiler or the necessary windows SDKs. So it's not supported to build C++ projects directly using dotnet msbuild in Windows, not to speak of CentOS.
To build C++ projects in linux, you can try g++ compiler, you can find many related info about how to use it online.
Also, maybe you can try using GCCBuild to build vcxproj files in Linux. It simple uses same structure of vcxproj but uses GCC to compile and build. Thanks to Roozbeh.

How to install MSVCR90D.DLL

How do I install MSVCR90D.DLL? I have a small test DLL(debug mode) that I created a setup project. In my setup project, I included merge modules & policy for vc90_debugcrt_x86.msm, etc. When I install the DLL on my VM, dependency walker still reports that MSVCR90D.DLL cannot be found?
Thanks in advance.
See here.
Preparing a Test Machine To Run a
Debug Executable
Microsoft does not officially support deploying debug runtimes outside of dev/test environments but you can make it work if you need to. Sounds like this is a vanilla test environment installation, though.
Just copy the MSVCR90D.DLL file into the same directory as your own dll. Then both your dll and dependency walker will find the MSVCR90D.DLL file.
You may need a couple of other files like msvcp90d.dll or msvcm90d.dll but dependency walker knows if you need them for your purposes.
MSVCR90D.DLL is the debug version of the Visual Studio Runtime Libraries. Normally, if you're deploying that code, you would build it in Release mode and also provide/install the Visual Studio Runtime Redistributable. As far as I know, the only way to obtain the debug dlls are through a Visual Studio install.
The py2exe utility that converts Python scripts into executable Windows programs seems to have a similar problem here. Maybe the section "Bundling the C runtime DLL" helps you to find the solution.

how to build a vc++ file in commandline

How to build a Project developed in VC++ in command line i am not visual studio(2003or 2005 or 2008)
I might not have understood your question fully, but using the /build param to devenv.exe will enable you to build a solution from the command line.

Resources