0
votes

I install on my Windows 10 machine (is a x64 machine) an old VS2013 Professional/VS2015 Professional. I have a Visual C++ solution/project for native x86 Platform and I'm trying to compile it with MSBuild.

First of all: which MSBuild should I select?

I tried to select the one from registry key: HKLM\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0

But perhaps this is not the right tools (there's an indication in this site about this), because it points to: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\

Which is the Msbuild tool for C#/Vb.net projects and not for native x86 platform. Perhaps there a recent change in a windows update about this, that change the registry value. Then I tried to change it to: VS 2013: C:\Program Files (x86)\MSBuild\12.0\Bin\

VS 2015: C:\Program Files (x86)\MSBuild\14.0\Bin\

Then I set the environment to:

VS 2013: VCTargetPath = c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120

VS 2015: VCTargetPath = c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140

I open a "native x86 command prompt" (with "Run as Administrator") from VS2013/2015 and then I run the following:

VS2013:

set VCTargetPath = \MSBuild.exe project.vcxproj /nologo /p:PlatformToolset=v120;Configuration=Debug /v:detailed

VS2015:

set VCTargetPath = \MSBuild.exe project.vcxproj /nologo /p:PlatformToolset=v140;Configuration=Debug /v:detailed

I obtain always the error: LNK 1158 - cannot run \cvtres.exe

Project file project.vcxproj indicates correctly Platform=Win32 and PlatformToolset (one of the above specific for VS 2013/2015). Path of the cvtres.exe file seems correct: using sysInternals ProcessMonitor utility i see that the file cvtres.exe is correctly found. But, when executing with msbuild, it first load the cvtres.exe copy that is in directory: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\

and then it try to load and execute the one in:

VS 2013: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/BIN/cvtres.exe

VS 2015: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/BIN/cvtres.exe

Even executing the link command, out of MSBuild chain, that loads only the specific cvtres.exe file (not the copy), is correcly executed.

There's probably something of inconsistent in the msbuild tool chain or some IT policy in my PC domain that blocks cvtres.exe execution when it flows through the copy in: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\

Do you have any suggestion about it on how to find where is the problem?

1
Hi, andrea, have you tried to build the project in VS IDE, what's the result? Maybe some different? And with the "IT policy in my PC domain", can you make sure you've got the full administrator rights and please check whether there has any antivirus software on your machine, which change some settings on your machine when scanning your machine.LoLance
I tried to build with VS IDE and compilation is successfull. Compilation is also good when I use the VS IDE executable (devenv.exe) and build from command line (/build option): in this case there's no need for full administration rights. I asked to my IT Department to have full administration rights and no antivirus interference: I need some time to have both. When they will be available I will try again and probably compilation with MSBuild will be successfull.andrea l
Any update feel free to share here:)LoLance

1 Answers

0
votes

First of all: which MSBuild should I select?

It depends. If the native X86 project comes from an earlier vs version than VS2013 and VS2015, then you can use the both two tools under C:\Program Files (x86)\MSBuild\14.0\Bin\ and C:\Program Files (x86)\MSBuild\12.0\Bin\.

Anyway, I suggest you use developer command prompt for vs to run the msbuild command.

Open the command prompt, type 'where msbuild' you will find two msbuild paths occurs.I find the command prompt will call the msbuild under C:\Program Files (x86)\MSBuild\vs-version\Bin\ in most time.(But I can't make sure it won't call the msbuild under Framework64\v4.0.30319\ under some certain circumstances.)

So using the command prompt is the most suitable way since it will call the corresponding msbuild tool for us.

Then I set the environment to:

Do you mean you set windows environment variable? Please avoid such action.Setting environment variables may mess the settings and sometimes the variables may be overwrited by project properties. Instead, you can set the variable in project file and I think set it in command-line is better.

You can find some info here.The properties has their scope. And a property in msbuild command has the highest priority which overwrites the value defined in anywhere else.

e.g: Like what you use in Configuration, use the command like: msbuild xxx.vcxproj /p:Configuration=Debug;VCTargetsPath=C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140 ...

One command for one build, don't separate the command into two parts:one for set values and the other for build.

And then it try to load and execute the one in: v12.0...

I think it's because you don't set the correct VCTargetsPath, the VCTargetPath you use is not recognized by msbuild engine so it doesn't work. And form the issue I provide above from Apparao, you'll find the PlatFormToolset property can't work with the VCTargetsPath not set.

So you can try opening developer command prompt as admin, then use the command like:

msbuild xxx\xxx\xxx.vcxproj /nologo /p:Platform=Win32;Configuration=Debug;VCTargetsPath="xxx\xxx" /v:detailed

Hope it helps. And any update or other error message you can update it in your question if it persists.