开发者

Changing EXE name based on compilation constant

I have a project in VB开发者_StackOverflow社区.NET 2010 (compiling to x86, .NET 2.0 runtime) that I want to compile into two separate EXEs - a "lite" version and a "full" version.

Unfortunately I cannot make two separate projects as it uses the Adobe Reader COM control - and sharing a form using that control between two projects seems to confuse the IDE (something to do with COM Interop, I assume - if someone knows how to share a form hosting the adobe reader control, that would solve my problem too).

I have found this thread: Change name of exe depending on conditional compilation symbol however I don't have any MSBuild experience so I need more explicit instructions.

On the "My Project>Compile" tab there is a "Build Events..." button. I was wondering if anyone knows how to set a conditional compilation constant and use that to determine the EXE name (or change it after build).

If all else fails I can rename the EXE manually I suppose, but I'd prefer it to be automated.


If having two separate projects within your solution isn't acceptable, you'll want to look into creating your own MSBuild script.

Here is an example of a custom MSBuild script that will allow you to define your custom compilation constants at build time, and then build your two versions of your application ("Full" and "Lite"):

<Project DefaultTargets="BuildAll" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <BuildVersionFull>FULL</BuildVersionFull>
    <BuildVersionLite>LITE</BuildVersionLite>
  </PropertyGroup>
  <ItemGroup>
    <Projects Include="$(MSBuildProjectDirectory)\MyApp.vbproj" />
  </ItemGroup>
  <Target Name="BuildAll" DependsOnTargets="BuildFull;BuildLite" />
  <Target Name="BuildFull">
    <MSBuild Projects="@(Projects)" Properties="DefineConstants=$(BuildVersionFull);OutputPath=binFull\;BaseIntermediateOutputPath=objFull\;AssemblyName=MyApp_Full" />
  </Target>
  <Target Name="BuildLite">
    <MSBuild Projects="@(Projects)"  Properties="DefineConstants=$(BuildVersionLite);OutputPath=binLite\;BaseIntermediateOutputPath=objLite\;AssemblyName=MyApp_Lite" />
  </Target>
</Project>

What you'll need to do:

  1. Create a new file and save it the same directory as your application's project file as "MyBuild.xml".
  2. Change to reflect the name of your application's project file.
  3. Open the Visual Studio Command Prompt and run "msbuild ".

Within your project, you can use the "FULL" and "LITE" conditional compilation constants to determine whether to compile certain statements:

#If FULL Then
    ' Compile code for the "Full" version.
#End If
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜