Issue with using MSBuild to build a VS2012/VS2013 Project

278 views Asked by At

I'm trying to automatically build a (currently working) Visual Studio 2013 in cygwin so that I can automatically build my project and run it. My project is compiled using the VS2012 toolset.

I currently have this bash script running in cygwin (based off of this blog post: http://anthonykosky.blogspot.com/2013/10/making-visual-studio-solutions-cmake.html):

###### FIRST -- import the Visual Studio settings
export PATH=$PATH:"/cygdrive/C/Windows/system32"

CMD=/cygdrive/c/Windows/system32/cmd
${CMD} /c "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64\vcvarsx86_amd64.bat"

# alias for MSBUILD
MSBUILD="/cygdrive/c/Program Files (x86)/MSBuild/12.0/Bin/MSBuild.exe"

# We're going to do a 64 bit release build
BUILD_CONFIG=Release
PLATFORM=x64

MSBUILD_LOG=msbuild.log

SLN_FILE=$1

"${MSBUILD}" ${SLN_FILE} /fl /property:Configuration=${BUILD_CONFIG};Platform=${PLATFORM}
msbuild_rv=$?

if [ ${msbuild_rv} != 0 ]
then
    echo "MSBuild ${SLN_FILE} exited with status '${msbuild_rv}'"
    exit 1
fi

grep -q '0 Error(s)' ${MSBUILD_LOG}
if [ $? != 0 ]
then
    echo "MSBuild ${SLN_FILE} detected errors"
    exit 1
    fi

When it compiles, I get the repeated error that:

error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1800' in {file}.obj

This seems to be a mismatch between version 1800 (VS2013, which I'm creating the solution in) and 1700 (VS2012, the toolset I need to compile with).

I'm a bit confused why MSBuild isn't doing this right, because my solution is configured correctly in VS2013. What do I need to change in my build script to ensure that it compiles?

thanks!

1

There are 1 answers

2
stijn On BEST ANSWER

Couple of things wrong here:

  • the toolset the project is built with is specified in the project itself (PlatformToolset property in the project file), not by which vcvars file called on the commandline
  • the ${CMD} /c ... command does nothing for the script, the article you linked to is simply wrong: what it does is start a new process, execute the bat file, then terminate. Any environment variables set by the batch file are local to the process only, not to the calling process.
  • it is not even needed to call vcvars before building using msbuild <solution>. vcvars sets up the PATH/INCLUDE/... variables so you can invoke the compiler manually on the commandline, but that is not what you are doing here: you are just building projects in which the PATH/INCLUDE/... is automatically determined by which PlatformToolset is used

So to summarize all of the above: just calling msbuild on your solution should be ok, you do not need to call vcvars, and I don't know exactly why you get the linker error as you don't supply enough information to figure that out but the cause is not in the script: the linker error means you are mixing object files built with different toolsets. Possibly you need to do a rebuild. Just searching for mismatch detected for '_MSC_VER': value doesn't match value gives enough search hits.