Search code examples
c++visual-studioplatform

Custom platforms for Visual Studio makefile project


I have a makefile-based project and I wrote a utility to generate VS 2015 project files and hook them up to makefile commands so that I can have the best of both worlds.

Unfortunately I've run into an issue where Visual Studio doesn't seem to allow for custom Platform names. For example, if my makefiles define two platforms, "Win32" and "Win64", upon trying to build the project in VS (which is simply making command-line calls) I get the following error:

Error MSB8006 The Platform for project 'codegen.vcxproj' is invalid. Platform='win64'. This error may also appear if some other project is trying to follow a project-to-project reference to this project, this project has been unloaded or is not included in the solution, and the referencing project does not build using the same or an equivalent Platform.

If I rename win64 to x64 then it works fine, because that's a platform Visual Studio recognizes, but that doesn't solve the underlying problem which is that I don't want to be restricted to just the platforms Visual Studio is aware of. I don't understand why this would even be an issue for makefile projects since I'm not calling the compiler within Visual Studio. Does anyone know of a way to trick Visual Studio into accepting unrecognized platforms for makefile projects?

EDIT: I can work around it by making all my configurations take the form _ and just using a placeholder like x64 for the actual platform field, but I'd still be interested in hearing if there is a real solution.


Solution

  • Add this property near the top of the project file, before the import of Microsoft.Cpp.props:

    <SkipInvalidConfigurations>True</SkipInvalidConfigurations>
    

    update the above works for VS2013 but not for VS2015. For the latter there doesn't seem to be a proper built-in way to skip the platform check. If you really want you can hack around and force the platform check to be skipped by adding a property like

    <PlatformTargetsFound>True</PlatformTargetsFound>
    

    but I wouldn't recommend it. As mentioned in the comments: if you want the IDE you unfortunately have to follow it's rules which practically means that if you tell the IDE 'look I have a C++ project using nmake' then there has to be a directory for the platform you want in Program Files\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms.

    The ultimate solution would be to create a custom project type which just serves as a container for files and has Build/Clean/Rebuild targets. I don't know how to do that properly and it's out of scope for this question, but a good start is getting rid of the lines and in the prject file and adding a target named 'Build'.