How to conditionally include MASM .asm files depending on platform/configuration (32/64-bit)

StackOverflow https://stackoverflow.com/questions/21504884

  •  05-10-2022
  •  | 
  •  

Question

I'm using Visual Studio 2010. I have two different MASM assembly files, one for 32-bit builds and one for 64-bit. The relevant part of my .vcxproj looks like this:

  <ItemGroup>
    <MASM Include="asmcode32.asm" Condition="'$(Platform)'=='Win32'" />
    <MASM Include="asmcode64.asm" Condition="'$(Platform)'=='x64'" />
  </ItemGroup>

My problem is this: The only file shown in Solution Explorer is the one for whichever configuration (Win32 / x64) is selected when Visual Studio is opened. Even unloading and reloading the project is insufficient - I must close and re-open visual studio for the other file to be shown.

I would prefer that both files be shown all the time, regardless of which configuration is selected. I could live with the visible item changing, depending on which solution is selected.


Example:

Visual Studio is opened with the x64 configuration selected. Only asmcode64.asm is shown:

asmcode64.asm is shown

When I change to the Win32 configuration (via the "Solution Platforms" drop-down), asmcode32.asm is still not visible. Again, even unload + reload does not make it visible.

With Win32 still selected, I can close Visual Studio and re-open it. Only now is asmcode32.asm visible:

enter image description here


Is there something else I can do with my .vcxproj file to show both files?

Perhaps adding the Condition= to the <MASM items was not the correct solution. If this is indeed the case, how can I configure the project to compile as I intend it?

This only applies to MASM .asm files. The equivalent operation for C/C++ files is to use the "Excluded From Build" option in the file's properties (this option doesn't exist for MASM files):

"Excluded From Build" option in C file property pages

Était-ce utile?

La solution

You're1 doing it wrong.

The Conditional= solution works, but using it causes the behavior you're1 seeing. Visual Studio appears to only evaluate which files will be shown in the Solution Explorer once. Basically this makes Visual Studio think that the file isn't even a part of the project.

The real solution is to use the same <ExcludedFromBuild> tags that the C files use (which are added when you select the "Excluded From Build" option in the file's properties pages.

  <ItemGroup>
    <!-- This causes the items to not be shown in Solution Explorer -->
    <!--
    <MASM Include="asmcode32.asm" Condition="'$(Platform)'=='Win32'" />
    <MASM Include="asmcode64.asm" Condition="'$(Platform)'=='x64'" />
    -->

    <!-- This is the right solution. -->
    <MASM Include="asmcode32.asm">
      <ExcludedFromBuild Condition="'$(Platform)'=='x64'">true</ExcludedFromBuild>
    </MASM>
    <MASM Include="asmcode64.asm">
      <ExcludedFromBuild Condition="'$(Platform)'=='Win32'">true</ExcludedFromBuild>
    </MASM>
  </ItemGroup>

It's a shame that this option is not exposed via the GUI, like it is for C files.

1 - "I'm"

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top