Search code examples
c#c++msbuildvisual-studio-2017

MSBUILD cannot build solution with Mixed Platforms?


I am upgrading batch file that needs to now restore nuget and build a solution that contains both c# x86 and c++ Wind32 projects - it used to use devenv just fine before the nuget additions. The solution is 'Mixed Platforms'. How do i do this with MSBuild? I can't specify x86, as the Win32 c++ projects then don't get built.

This works for x64,

@ECHO OFF
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" amd64
ECHO Bulding for x64!!!

ECHO Building Theo.sln...
msbuild Theo.sln /t:restore /t:build /p:Configuration=Debug /p:Platform=x64 /verbosity:quiet

but since this is Mixed Platforms, this does NOT work!

call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x86
ECHO Bulding for x86!!!

ECHO Building Theo.sln...
msbuild Theo.sln /t:restore /t:build /p:Configuration=Debug /p:Platform="Mixed Platforms" /verbosity:quiet

I get an error MSB4126: The specified solution configuration "Debug|MixedPlatforms" is invalid.


Solution

  • MSBUILD cannot build solution with Mixed Platforms?

    I think you should check your Mixed Platforms which you created carefully.

    I suggest you could create Mixed Platforms in this way. If you already used this way, you should check every step carefully.

    Solution

    First of all, remove or delete the previous Platform Mixed Platforms.

    1) open menu Build-->Configuration Manager-->Solution Platform which will act on the whole solution.

    Also, make sure the names are consistent and there are no spelling mistakes.

    enter image description here

    2) Create like this and remember to select x86 platform.

    enter image description here

    Then use the x86 bat file to build the project and in my side, it works well as expected.

    ============================

    Update 1

    Actually, when you use my solution platform which set to x86 and then enable it, it will change win32 c++ project to use win32 platform as you expected. Rather than x86. You should note that.

    C++ projects use Win32 as platform rather than x86. When you use my solution platform, it will change the win32 c++ projects to use Win32 platform.

    Or you can try to build the win32 project separately with win32 platfrom and test whether it could be built successfully.

    Please check whether you have do any changes to xxx.vcxproj file and you should check it carefully.

    enter image description here

    Besides, I found that the error message Debug|MixedPlatforms and it uses MixedPlatforms rather than Mixed Platforms while your batch file uses /p:Platform="Mixed Platforms". It is quite strange. I think you have defined the wrong name of it in your solution and you should check it carefully.

    In addition, you can try to call C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe to test your solution.

    call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe" x86
    ECHO Bulding for x86!!!
    
    ECHO Building test1.sln...
    msbuild C:\Users\Administrator\source\repos\test1\test1.sln /t:restore /t:build /p:Configuration=Debug /p:Platform="Mixed Platforms"