views:

2781

answers:

4

I'm using MSBuild (via NAnt) to compile a bunch of VB.Net assemblies. Because these assemblies depend on COM Interop, I need to guarantee that they run in 32 bit mode on 64 bit OS's. I can get the executable assemblies to compile to 32 bit by changing the project in Visual Studio, but I'd really like to be able to force all of the executables to be compiled to 32 bit mode on the build server.

I've tried a number of command-line parameters to MSBuild with no luck:

  • /p:Platform=win32
  • /p:Platform=x86
  • /p:ProcessorArchitecture=x86

What I'm I doing wrong? Is there some reference to the properties that MSBuild uses when compiling VB projects?

Thanks!

+4  A: 

If the assemblies themselves are always going to be 32 bit, why not add the setting to the .vbproj file? That will take MSBuild out of the equation.

Just add the following line to the initial PropertyGroup in the .vbproj file

<PlatformTarget>x86</PlatformTarget>
JaredPar
Not the answer I was looking for but ended up being the simplest/safest.
Eric Nicholson
+2  A: 

According to MSDN, you're doing the right thing.

Looks like /p:Platform=x86

Edit: actually, maybe its /p:PlatformTarget=x86

Have you tried just invoking msbuild directly with that parameter (make sure its not an issue with your NAnt file? Are you looking at the build output for the right build configuration (Debug/Release)?

Nader Shirazie
+1  A: 

In Solution Explorer, right click the root node -> Configuration Manager. You need to define a solution-wide configuration that instructs each project within to build as 32-bit. (note: you probably already have one if you've ever set at least 1 project to build as 32-bit) For a step-by-step walkthrough, see here.

Then, you specify the desired "platform" and "flavor" in your Team Build .proj / .targets files. For example:

<ConfigurationToBuild Include="Release|x86">
  <FlavorToBuild>Release</FlavorToBuild>
  <PlatformToBuild>x86</PlatformToBuild>
</ConfigurationToBuild>

You can specify >1 of these property sections to have several combinations built. I would copy/paste the "Release|x86" string (or whatever it looks like) directly from your .sln file to ensure it matches exactly -- you can't get it directly from Solution Explorer.

edit: I will answer your comment here since it will take more than 500 characters...

MSBuild property evaluation is pretty complex since it mixes declarative and imperative styles. See this article for details. I myself prefer not to rely on its subtleties.

It's true that properties specified on the command line should override everything else, but Team Build has another layer of complexity. The ComputeConfigurationList task is called repeatedly via a recursive MSBuild invokation, not as an ordinary task. The way it pulls this off is to take the ordinary properties like PlatformToBuild and wrap them in a set of global properties called ConfigurationToBuild.PlatformToBuild (etc) which are generated on the fly, once for each configuration. This makes the Team Build engine much more flexible internally, but it also makes hacking the command line behavior you want harder.

You could try setting ConfigurationToBuild.PlatformToBuild on the command line directly -- it might work, I'm not sure. But it will definitely prevent you from ever building >1 configuration in a single build definition. For this reason I'm sticking with my advice above.

Richard Berg
So what I'm getting is that there is not a way to force a specific platform from the command line unless the developer sets up the project to have a x86 platform?I'd really like to avoid that step if possible (since I don't have control over new projects when they get created).
Eric Nicholson
Yes and no. I've edited my answer to provide more details. If you really want to know how this stuff works, read (but don't touch!) the Microsoft.TeamFoundation.Build.targets file found in %ProgramFiles%\MSBuild
Richard Berg
+1  A: 

After experiencing the exact same issue, I switched from using the version of msbuild at c:\windows\Microsoft.net\Framework64... to the version at c:\windows\Microsoft.net\Framework (no 64) and things compiled just fine.

Jeb
The components were actually being compiled successfully on a 32bit OS (no 64bit framework installed) and then failing at run time on a 64 bit OS. But I suspect you couldn't even compile certain components on the 64 bit framework, so it's a good tip.
Eric Nicholson