.NET混淆器 Dotfuscator使用教程二:保护你的应用之集成到Visual Studio项目中

Dotfuscator是一款.NET混淆器和压缩器,防止你的应用程序被反编译。html

保护你的应用

保护整个应用程序就像在应用程序的Visual Studio项目文件中添加几行代码同样简单(例如,MyExecutable.csproj)。集成后,Dotfuscator Professional将自动保护您的全部程序集 - 不管是来自应用程序的项目仍是解决方案中的其余项目。 每次的版本发布也会自动保护。bash

本次《Dotfuscator教程:保护你的应用》包括如下内容:app

  • 集成到Visual Studio项目中
  • 检查受保护的程序集
  • 存档报告文件
  • 增强保护
  • 替代方法

本篇文章主要介绍如何将Dotfuscator集成到Visual Studio项目中。ide

集成到Visual Studio项目中

要将Dotfuscator集成到项目中,请在Visual Studio中编辑项目文件(.csproj)并进行以下所示的更改。ui

.NET Frameworkthis

要保护.NET Framework项目,请复制下面显示的新XML元素(<PropertyGroup>等),并在结束标签</Project>以前将它们粘贴到项目文件中。请注意,元素的顺序很重要。spa

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">

  <!-- ...existing tags... -->

  <!-- Set build properties for Dotfuscator -->
  <PropertyGroup>

    <!-- Generate a default Dotfuscator config file (DotfuscatorConfig.xml) -->
    <!-- TODO: Set this to false after the file is generated by the first local build -->
    <DotfuscatorGenerateConfigFileIfMissing>true</DotfuscatorGenerateConfigFileIfMissing>

    <!-- Enable Dotfuscator for Release builds -->
    <DotfuscatorEnabled Condition="'$(Configuration)' == 'Release'">true</DotfuscatorEnabled>

  </PropertyGroup>

  <!-- Import the Dotfuscator MSBuild targets last -->
  <Import Project="$(MSBuildExtensionsPath)\PreEmptive\Dotfuscator\4\PreEmptive.Dotfuscator.Common.targets"/>

</Project>复制代码

.NET Core or .NET Standard版本控制

要保护.NET Core或.NET Standard项目,请首先从项目的根<Project>标记中删除Sdk属性。而后,将下面显示的新元素复制到项目文件中的相应位置。code

<Project>
<!-- ORIGINALLY WAS: <Project Sdk="Microsoft.NET.Sdk">
     The Sdk attribute has been replaced with explicit <Import> tags
     to ensure Dotfuscator's targets are imported after "Sdk.targets" --> <!-- Import SDK properties --> <!-- (before any existing tags) --> <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" /> <!-- ...existing tags... --> <!-- Import SDK targets --> <!-- (after any existing tags but before Dotfuscator targets) --> <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" /> <!-- Set build properties for Dotfuscator --> <PropertyGroup> <!-- Generate a default Dotfuscator config file (DotfuscatorConfig.xml) --> <!-- TODO: Set this to false after the file is generated by the first local build --> <DotfuscatorGenerateConfigFileIfMissing>true</DotfuscatorGenerateConfigFileIfMissing> <!-- Enable Dotfuscator for Release builds --> <DotfuscatorEnabled Condition="'$(Configuration)' == 'Release'">true</DotfuscatorEnabled> </PropertyGroup> <!-- Import the Dotfuscator MSBuild targets last --> <Import Project="$(MSBuildExtensionsPath)\PreEmptive\Dotfuscator\4\PreEmptive.Dotfuscator.Common.targets"/> </Project>复制代码

Xamarincdn

Dotfuscator与Xamarin应用程序集成是Xamarin构建过程的一部分,可以使用与其余.NET平台相同的方法。可是,在开始以前,你应该了解Xamarin集成的一些特别的方面。

要保护你的Xamarin应用程序,你必须将Dotfuscator集成到每一个输出项目(Android,iOS和UWP)中。Dotfuscator将保护项目输出目录中源自项目解决方案的全部程序集。

为了保护Xamarin项目(咱们建议从Android开始),请在结束标记</Project>以前将下面显示的新元素复制到项目文件中的相应位置。

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <!-- ...existing tags... -->

  <!-- Set build properties for Dotfuscator -->
  <PropertyGroup>

    <!-- Generate a default Dotfuscator config file (DotfuscatorConfig.xml) -->
    <!-- TODO: Set this to false after the file is generated by the first local build -->
    <DotfuscatorGenerateConfigFileIfMissing>true</DotfuscatorGenerateConfigFileIfMissing>

    <!-- Enable Dotfuscator for Release -->
    <DotfuscatorEnabled Condition="'$(Configuration)' == 'Release'">true</DotfuscatorEnabled>

    <!-- Enable Dotfuscator for Ad-Hoc (only needed for iOS) -->
    <DotfuscatorEnabled Condition="'$(Configuration)' == 'Ad-Hoc'">true</DotfuscatorEnabled>

    <!-- Enable Dotfuscator for AppStore (only needed for iOS) -->
    <DotfuscatorEnabled Condition="'$(Configuration)' == 'AppStore'">true</DotfuscatorEnabled>

    <!-- Only needed when using Tamper Checks for Android -->
    <!-- TODO: If using Tamper Checks for Android, set this to the SHA-1 fingerprint of the certificate used to sign the app -->
    <DotfuscatorAndroidSigningCertFingerprint></DotfuscatorAndroidSigningCertFingerprint>

  </PropertyGroup>

  <!-- Import the Dotfuscator MSBuild targets last -->
  <Import Project="$(MSBuildExtensionsPath)\PreEmptive\Dotfuscator\4\PreEmptive.Dotfuscator.Common.targets"/>

</Project>复制代码

Unity

将Dotfuscator集成到Unity项目中须要特殊配置,本次教程不包含这些配置。后续会整理的。

创建项目

在Visual Studio中,将更改保存到项目文件,关闭选项卡,而后从新加载项目。要得到受保护的应用程序,请按照正常状况在发布配置中构建项目。

getting started-build-initial

做为初始构建的一部分,Dotfuscator将生成一个配置文件,DotfuscatorConfig.xml,它具备默认保护设置。构建将发出警告(见上面的屏幕截图),在第一次构建中你能够忽略。将生成的文件加入版本控制。

而后,构建将调用Dotfuscator来保护项目输出目录中的解决方案程序集(.exe.dll文件)(例如,bin\Release)。Dotfuscator还将在新的DotfuscatorReports目录中生成报告文件;你应该从版本控制中排除此目录。

一旦构建完成,您的应用程序如今就受Dotfuscator保护了。

注意:有关诊断构建或运行时问题的帮助,请参阅疑难解答

禁用配置文件生成

在第一次构建期间,Dotfuscator生成了一个具备默认保护设置的配置文件DotfuscatorConfig.xml。此功能在设置时颇有用,可是一旦文件存在(并由版本控制跟踪),你应该禁用此功能,由于它能够屏蔽某种构建错误。

要禁用配置文件生成,请再次编辑项目文件(.csproj)并替换如下行:

<!-- Generate a default Dotfuscator config file (DotfuscatorConfig.xml) -->
    <!-- TODO: Set this to false after this file is generated by the first local build -->
    <DotfuscatorGenerateConfigFileIfMissing>true</DotfuscatorGenerateConfigFileIfMissing>复制代码

替换为

<!-- Error if the Dotfuscator config file (DotfuscatorConfig.xml) is missing -->
    <DotfuscatorGenerateConfigFileIfMissing>false</DotfuscatorGenerateConfigFileIfMissing>复制代码

                                                        【下载Dotfuscator最新试用版
相关文章
相关标签/搜索