Building Visual J# applications for 64-bit platforms using MSBuild

MSBuild is a build platform for Microsoft and Visual Studio. Details about MSBuild tasks are documented here.

Microsoft Visual J# 2.0 Redistributable Package – Second Edition comes with MSBuild support enabled (including cross compilation) from the command-line. This enables you to build Visual J# projects (.vjsproj) and solution (.sln) files that are created with Visual Studio 2005 from the command-line by using MSBuild.

All Visual J# project and solution files that are created with Visual Studio 2005 default to the x86 architecture type. Modify the project and solution files to build them to a different architecture type as specified below:

  • anycpu, x64, or IA64 architecture types if using the 32-bit (or WoW) MSBuild task.
  • x86, x64, IA64 or anycpu type if using the 64-bit MSBuild task.

The reason for the above behavior is that the 32-bit or WoW MSBuild task, which is present at %SystemRoot%\Microsoft.Net\Framework\v2.0.50727, by default emits 32-bit (x86) architecture type binaries. The 64-bit MSBuild task, which is present at %SystemRoot%\Microsoft.Net\Framework64\v2.0.50727, by default emits anycpu binaries. This behavior is different from the default behavior that is expected from Visual J# project and solution files that are generated by Visual Studio 2005.

To build applications for a specific platform architecture type by using MSBuild, follow either of the following procedures:

  1. Build the *.vjsproj files with the “/property:platform=XXX” option.
  2. Build the *.sln files with the “/property:platform=XXX” option.

XXX above specifies the targeted platform type (anycpu/x86/x64/itanium).

For Option1 (building the *.vjsproj file) , add a new Property Group section to the *.vjsproj file that is generated by Visual Studio 2005 as illustrated below:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == ' YYY | XXX ' ">

<DebugSymbols>true</DebugSymbols>

<DebugType>full</DebugType>

<Optimize>false</Optimize>

<OutputPath>bin\Debug\</OutputPath>

<PlatformTarget> XXX </PlatformTarget>

<DefineConstants>DEBUG;TRACE</DefineConstants>

</PropertyGroup>

The value of YYY is the Configuration (Debug/Release), and the value of XXX is the Platform (anycpu/x86/x64/itanium). For example:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">

<DebugSymbols>true</DebugSymbols>

<DebugType>full</DebugType>

<Optimize>false</Optimize>

<OutputPath>bin\Debug\</OutputPath>

<PlatformTarget>x64</PlatformTarget>

<DefineConstants>DEBUG;TRACE</DefineConstants>

</PropertyGroup>

If you are building for the x86 platform type, ensure that x86 PlatformTarget is inserted in the existing PropertyGroup condition for x86 platform.

Values other than PlatformTarget should also be changed as desired in the Property Group section.

For Option 2 (building the *.sln file) , modify all the *.vjsproj files which are a part of the solution as explained above and modify the *.sln file as described below:

· In the GlobalSection(SolutionConfigurationPlatforms) and GlobalSection(ProjectConfigurationPlatforms) sections, add the “<Configuration>|<Platform>” preSolution and postSolution that you have included in your *.vjsproj files. For example, imagine that you had added Debug|x64 as above, and the original *.sln file resembled the following example:

GlobalSection(SolutionConfigurationPlatforms) = preSolution

Debug|x86 = Debug|x86

Release|x86 = Release|x86

EndGlobalSection

GlobalSection(ProjectConfigurationPlatforms) = postSolution

{E2D2EA3E-0E77-4C82-8AA4-D94FFC1EB7F6}.Debug|x86.ActiveCfg = Debug|x86

{E2D2EA3E-0E77-4C82-8AA4-D94FFC1EB7F6}.Debug|x86.Build.0 = Debug|x86

{E2D2EA3E-0E77-4C82-8AA4-D94FFC1EB7F6}.Release|x86.ActiveCfg = Release|x86

{E2D2EA3E-0E77-4C82-8AA4-D94FFC1EB7F6}.Release|x86.Build.0 = Release|x86

EndGlobalSection

Following is the modified result:

GlobalSection(SolutionConfigurationPlatforms) = preSolution

Debug|x86 = Debug|x86

Release|x86 = Release|x86

Debug|x64 = Debug|x64

EndGlobalSection

GlobalSection(ProjectConfigurationPlatforms) = postSolution

{E2D2EA3E-0E77-4C82-8AA4-D94FFC1EB7F6}.Debug|x86.ActiveCfg = Debug|x86

{E2D2EA3E-0E77-4C82-8AA4-D94FFC1EB7F6}.Debug|x86.Build.0 = Debug|x86

{E2D2EA3E-0E77-4C82-8AA4-D94FFC1EB7F6}.Release|x86.ActiveCfg = Release|x86

{E2D2EA3E-0E77-4C82-8AA4-D94FFC1EB7F6}.Release|x86.Build.0 = Release|x86

{E2D2EA3E-0E77-4C82-8AA4-D94FFC1EB7F6}.Debug|x64.ActiveCfg = Debug|x64

{E2D2EA3E-0E77-4C82-8AA4-D94FFC1EB7F6}.Debug|x64.Build.0 = Debug|x64

EndGlobalSection

 

 

 

 

 

 

 

Note: For Option 2 (building the *.sln file), the following points need to be addressed:

· Because adding new options at the beginning of the .sln file changes the default compile properties of the file, this is not the recommended approach.

· If a solution has multiple projects which must be compiled for different platforms, iterate through each J# project and compile them separately instead of compiling them as a single solution file.

                                                                  

Note: Visual Studio is not certified to recognize and open project and solution files that are edited manually. To use Visual Studio 2005 to open and edit the project or solution files, the recommended approach is to maintain a separate copy of the files for manual editing.