如何配置 babel.net obfuscator 仅在发布版本上运行?

发布于 2024-12-01 14:18:52 字数 903 浏览 1 评论 0原文

我能够修改项目的 *.proj 文件以包含 babel 构建目标。

<Import Project="C:\Program Files\Babel\MSBuild\Babel.Build.targets" />

这可以工作,但会为调试和发布版本执行 babel。我希望 babel 仅混淆发布版本。根据手册第 82 页,我应该包含以下代码。

<Import Project="C:\Program Files\Babel\MSBuild\Babel.Build.targets" />
<Choose>
<When Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PropertyGroup>
<EnableObfuscation>false</EnableObfuscation>
</PropertyGroup>
</When>
<When Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PropertyGroup>
<EnableObfuscation>true</EnableObfuscation>
<ILIterations>3</ILIterations>
<StringEncryption>true</StringEncryption>
</PropertyGroup>
</When>
</Choose>

但是,当将此代码包含在 *.proj 文件中时,我收到构建错误,指出“EnableObfuscation”不是有效选项。

I was able to modify *.proj file for the project to include babel build target.

<Import Project="C:\Program Files\Babel\MSBuild\Babel.Build.targets" />

This works but executes babel for both debug and release builds. I want babel to obfuscate only release builds. Per pg 82 of the manual I should include the following code.

<Import Project="C:\Program Files\Babel\MSBuild\Babel.Build.targets" />
<Choose>
<When Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PropertyGroup>
<EnableObfuscation>false</EnableObfuscation>
</PropertyGroup>
</When>
<When Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PropertyGroup>
<EnableObfuscation>true</EnableObfuscation>
<ILIterations>3</ILIterations>
<StringEncryption>true</StringEncryption>
</PropertyGroup>
</When>
</Choose>

However when including this code in the *.proj file I get build error that "EnableObfuscation" is not a valid option.

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

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

发布评论

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

评论(2

顾忌 2024-12-08 14:18:52

检查 Babel.Build.targets 的路径是否正确。然后编辑该文件并搜索 EnableObfuscation 属性以确保它存在。

我将建议的配置从文档更改为以下内容,并将其添加到我的所有项目中,并且工作正常。

<Import Project="C:\Program Files\Babel\MSBuild\Babel.Build.targets" />
  <Choose>
    <When Condition=" '$(Configuration)' == 'Debug' ">
      <PropertyGroup>
        <EnableObfuscation>false</EnableObfuscation>
      </PropertyGroup>
    </When>
    <When Condition=" '$(Configuration)' == 'Release' ">
      <PropertyGroup>
        <EnableObfuscation>true</EnableObfuscation>
        <ILIterations>3</ILIterations>
        <StringEncryption>true</StringEncryption>
      </PropertyGroup>
    </When>
  </Choose>

上面的内容适用于我的 Windows Phone 7 项目,并通过将其添加到启动项目中来使用 XAP 文件

  <Target Name="AfterBuild">
    <CreateProperty Value="@(_OutputPathItem->'%(FullPath)$(XapFilename)')">
      <Output TaskParameter="Value" PropertyName="BabelInputFile"/>
    </CreateProperty>
  </Target>

Check your path to the Babel.Build.targets is correct. Then edit that file and search for the EnableObfuscation property to make sure it exists.

I altered the suggested config from the documentation to the following and added to all my projects and it works fine.

<Import Project="C:\Program Files\Babel\MSBuild\Babel.Build.targets" />
  <Choose>
    <When Condition=" '$(Configuration)' == 'Debug' ">
      <PropertyGroup>
        <EnableObfuscation>false</EnableObfuscation>
      </PropertyGroup>
    </When>
    <When Condition=" '$(Configuration)' == 'Release' ">
      <PropertyGroup>
        <EnableObfuscation>true</EnableObfuscation>
        <ILIterations>3</ILIterations>
        <StringEncryption>true</StringEncryption>
      </PropertyGroup>
    </When>
  </Choose>

The above works in my Windows Phone 7 project and works with the XAP file by adding this in addition to the startup project

  <Target Name="AfterBuild">
    <CreateProperty Value="@(_OutputPathItem->'%(FullPath)$(XapFilename)')">
      <Output TaskParameter="Value" PropertyName="BabelInputFile"/>
    </CreateProperty>
  </Target>
倦话 2024-12-08 14:18:52

我正在使用 NuGet 包,最终在我的 csproject 中使用了 packageReference 的条件:

<ItemGroup Condition="'$(Configuration)'=='Release'">
  <PackageReference Include="Babel.Obfuscator" Version="X.X.X">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
 </PackageReference>

I was using the NuGet package and ended up using a condition for the packageReference in my csproject:

<ItemGroup Condition="'$(Configuration)'=='Release'">
  <PackageReference Include="Babel.Obfuscator" Version="X.X.X">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
 </PackageReference>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文