根据编译常量更改 EXE 名称

发布于 12-05 15:17 字数 567 浏览 0 评论 0原文

我有一个 VB.NET 2010 项目(编译为 x86、.NET 2.0 运行时),我想将其编译为两个单独的 EXE - 一个“精简”版本和一个“完整”版本。

不幸的是,我无法创建两个单独的项目,因为它使用 Adob​​e Reader COM 控件 - 并且在两个项目之间使用该控件共享表单似乎会混淆 IDE(我认为与 COM Interop 有关 - 如果有人知道如何共享表单)托管 adobe reader 控件,这也可以解决我的问题)。

我找到了这个线程: 根据条件编译更改 exe 的名称符号 但是我没有任何 MSBuild 经验,因此我需要更明确的说明。

在“我的项目>编译”选项卡上有一个“构建事件...”按钮。我想知道是否有人知道如何设置条件编译常量并使用它来确定 EXE 名称(或在构建后更改它)。

如果一切都失败了,我想我可以手动重命名 EXE,但我更希望它是自动化的。

I have a project in VB.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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔戏命师2024-12-12 15:17:04

如果您的解决方案中存在两个单独的项目是不可接受的,您将需要考虑创建自己的 MSBuild 脚本。

以下是自定义 MSBuild 脚本的示例,该脚本允许您在生成时定义自定义编译常量,然后生成应用程序的两个版本(“完整”和“精简版”):

<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>

您需要执行的操作:

  1. 创建一个新文件并将其保存在与应用程序的项目文件相同的目录中,名称为“MyBuild.xml”。
  2. 更改以反映应用程序的项目文件的名称。
  3. 打开 Visual Studio 命令提示符并运行“msbuild”。

在您的项目中,您可以使用“FULL”和“LITE”条件编译常量来确定是否编译某些语句:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文