【问题标题】:How can I implement Dotfuscator on a .NET Standard 2.0 project?如何在 .NET Standard 2.0 项目上实现 Dotfuscator?
【发布时间】:2019-01-26 12:58:30
【问题描述】:

我正在将现有 Xamarin 应用程序从 PCL 升级到 .NET Standard 2.0。 我有几个子项目,例如业务、数据、BDO 等,它们都是 PCL,我已经能够使用 this tutorial 将它们更新到 .NET Standard 2.0。

但是,我使用 this Xamarin Blog 实现在我的所有 PCL 项目上实现了 Dotufscator,但它似乎不能作为 .NET Standard 2.0 项目的指令。 DLL 未经过混淆处理,并且“正在运行 Dotfuscator”消息不会显示在构建输出中。

我目前将 Dotucfator 添加到 .NET Standard 2.0 proj 文件的尝试如下:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <DotfuscatorXamarinCliPath>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\PreEmptiveSolutions\DotfuscatorCE\dotfuscatorCLI.exe</DotfuscatorXamarinCliPath>
    <DotfuscatorXamarinConfigFileName>DotfuscatorConfig.xml</DotfuscatorXamarinConfigFileName>
    <DotfuscatorXamarinGenerateNewConfigFile>true</DotfuscatorXamarinGenerateNewConfigFile>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <OutputPath>bin\Debug\</OutputPath>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DotfuscatorXamarinEnabled>true</DotfuscatorXamarinEnabled>
    <OutputPath>bin\Release\</OutputPath>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
  </ItemGroup>
  <ItemGroup>
    <None Include="DotfuscatorConfig.xml" />
  </ItemGroup>

  <Import Project="..\PreEmptive.Dotfuscator.Xamarin.targets" />
</Project>

有人可以帮忙吗? 谢谢

【问题讨论】:

    标签: c# xamarin obfuscation .net-standard-2.0 dotfuscator


    【解决方案1】:

    作为免责声明,我应该提到,我作为 Dotfuscator 团队的开发人员和技术作家工作的一部分来回答这篇文章。 我还写了the blog post you linked to,所以我很高兴你发现它对保护你的 Xamarin 应用程序很有价值。

    首先,我应该澄清一下博客文章中的歧义。 此处显示的 Dotfuscator-Xamarin MSBuild 集成仅旨在集成到特定于平台的 Xamarin 项目中,这些项目构建为打包格式,例如构建 APK 的 Android 项目。 不支持直接集成到可移植类库 (PCL) 或 .NET 标准库等库项目中。

    请注意,将 Dotfuscator 集成到 Xamarin 项目中将保护源自您的解决方案的所有打包程序集,因此您的库代码仍将受到保护。 例如,如果您将 Dotfuscator 集成到 MyApp.Android.csproj(引用 A.csprojB.csprojC.csproj)中,则 Dotfuscator 将在将所有四个项目的程序集打包到 APK 时保护它们。 这种方法可以提供更强大的保护,并且不需要您为每个库单独运行 Dotfuscator,从而节省您的构建和配置时间。

    如果您使用的是商业许可的 Dotfuscator 专业版,版本 4.37.0 包括 a new MSBuild integration。 新的集成更易于设置,修复了一些已知问题,并且将成为我们推荐使用 Dotfuscator 的主要方式,用于各种项目,而不仅仅是 Xamarin。 我建议将 Dotfuscator 升级到此版本,并从您的 .NET Standard 项目中删除 Dotfuscator-Xamarin MSBuild 集成。 然后,将新的 MSBuild 集成添加到特定于平台的 Xamarin 项目;有关详细信息,请参阅我们用户指南的Xamarin Getting Started page

    如果您使用的是 Dotfuscator 社区版(包含在所有 Visual Studio 版本中)或更早的专业版,请继续使用博文中提到的the Dotfuscator-Xamarin MSBuild integration。 我建议你从 .NET 标准库中删除集成,并将其添加到引用它们的特定于平台的 Xamarin 项目中。 请注意,当集成到引用 .NET Standard 库的 Xamarin 项目时,存在一个已知问题,即第一次构建将失败(因为集成不了解 .NET Standard 使用的最小项目格式);有关解决方法,请参阅this answer。 后续构建将正常进行,无需解决方法。

    【讨论】:

    • 很抱歉回复延迟非常大,我被拉到另一个项目,忘记检查了。这非常有用,应该可以完全解决我的问题,感谢您的详细回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-20
    相关资源
    最近更新 更多