翻譯|使用教程|編輯:黃竹雯|2019-03-01 14:44:52.000|閱讀 898 次
概述:本篇文章主要介紹如何將Dotfuscator集成到Visual Studio項目中。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Dotfuscator是一款.NET混淆器和壓縮器,防止你的應用程序被反編譯。
保護整個應用程序就像在應用程序的Visual Studio項目文件中添加幾行代碼一樣簡單(例如,MyExecutable.csproj)。集成后,Dotfuscator Professional將自動保護您的所有程序集 - 無論是來自應用程序的項目還是解決方案中的其他項目。 每次的版本發布也會自動保護。
本次《Dotfuscator教程:保護你的應用》包括以下內容:
本篇文章主要介紹如何將Dotfuscator集成到Visual Studio項目中。
要將Dotfuscator集成到項目中,請在Visual Studio中編輯項目文件(.csproj)并進行如下所示的更改。
.NET Framework
要保護.NET Framework項目,請復制下面顯示的新XML元素(PropertyGroup等),并在結束標簽/Project之前將它們粘貼到項目文件中。請注意,元素的順序很重要。
<?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
要保護.NET Core或.NET Standard項目,請首先從項目的根Project標記中刪除Sdk屬性。然后,將下面顯示的新元素復制到項目文件中的相應位置。
<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應用程序集成是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="//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中,將更改保存到項目文件,關閉選項卡,然后重新加載項目。要獲得受保護的應用程序,請按照正常情況在發布配置中構建項目。
作為初始構建的一部分,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>
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn