翻譯|使用教程|編輯:黃竹雯|2019-03-01 14:44:52.000|閱讀 913 次
概述:本篇文章主要介紹如何將Dotfuscator集成到Visual Studio項(xiàng)目中。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Dotfuscator是一款.NET混淆器和壓縮器,防止你的應(yīng)用程序被反編譯。
保護(hù)整個應(yīng)用程序就像在應(yīng)用程序的Visual Studio項(xiàng)目文件中添加幾行代碼一樣簡單(例如,MyExecutable.csproj)。集成后,Dotfuscator Professional將自動保護(hù)您的所有程序集 - 無論是來自應(yīng)用程序的項(xiàng)目還是解決方案中的其他項(xiàng)目。 每次的版本發(fā)布也會自動保護(hù)。
本次《Dotfuscator教程:保護(hù)你的應(yīng)用》包括以下內(nèi)容:
本篇文章主要介紹如何將Dotfuscator集成到Visual Studio項(xiàng)目中。
要將Dotfuscator集成到項(xiàng)目中,請?jiān)赩isual Studio中編輯項(xiàng)目文件(.csproj)并進(jìn)行如下所示的更改。
.NET Framework
要保護(hù).NET Framework項(xiàng)目,請復(fù)制下面顯示的新XML元素(PropertyGroup等),并在結(jié)束標(biāo)簽/Project之前將它們粘貼到項(xiàng)目文件中。請注意,元素的順序很重要。
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="//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
要保護(hù).NET Core或.NET Standard項(xiàng)目,請首先從項(xiàng)目的根Project標(biāo)記中刪除Sdk屬性。然后,將下面顯示的新元素復(fù)制到項(xiàng)目文件中的相應(yīng)位置。
<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>
Xamarin
Dotfuscator與Xamarin應(yīng)用程序集成是Xamarin構(gòu)建過程的一部分,可使用與其他.NET平臺相同的方法。但是,在開始之前,你應(yīng)該了解Xamarin集成的一些特別的方面。
要保護(hù)你的Xamarin應(yīng)用程序,你必須將Dotfuscator集成到每個輸出項(xiàng)目(Android,iOS和UWP)中。Dotfuscator將保護(hù)項(xiàng)目輸出目錄中源自項(xiàng)目解決方案的所有程序集。為了保護(hù)Xamarin項(xiàng)目(我們建議從Android開始),請?jiān)诮Y(jié)束標(biāo)簽/Project之前將下面顯示的新元素復(fù)制到項(xiàng)目文件中的相應(yīng)位置。
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="//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項(xiàng)目中需要特殊配置,本次教程不包含這些配置。后續(xù)會整理的。
在Visual Studio中,將更改保存到項(xiàng)目文件,關(guān)閉選項(xiàng)卡,然后重新加載項(xiàng)目。要獲得受保護(hù)的應(yīng)用程序,請按照正常情況在發(fā)布配置中構(gòu)建項(xiàng)目。

作為初始構(gòu)建的一部分,Dotfuscator將生成一個配置文件,DotfuscatorConfig.xml,它具有默認(rèn)保護(hù)設(shè)置。構(gòu)建將發(fā)出警告(見上面的屏幕截圖),在第一次構(gòu)建中你可以忽略。將生成的文件加入版本控制。
然后,構(gòu)建將調(diào)用Dotfuscator來保護(hù)項(xiàng)目輸出目錄中的解決方案程序集(.exe和.dll文件)(例如,bin\Release)。Dotfuscator還將在新的DotfuscatorReports目錄中生成報(bào)告文件;你應(yīng)該從版本控制中排除此目錄。
一旦構(gòu)建完成,您的應(yīng)用程序現(xiàn)在就受Dotfuscator保護(hù)了。注意:有關(guān)診斷構(gòu)建或運(yùn)行時問題的幫助,請參閱。
在第一次構(gòu)建期間,Dotfuscator生成了一個具有默認(rèn)保護(hù)設(shè)置的配置文件DotfuscatorConfig.xml。此功能在設(shè)置時很有用,但是一旦文件存在(并由版本控制跟蹤),你應(yīng)該禁用此功能,因?yàn)樗梢云帘?某種構(gòu)建錯誤。
要禁用配置文件生成,請?jiān)俅尉庉嬳?xiàng)目文件(.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>
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@ke049m.cn