简体   繁体   中英

I can`t enable dotfuscator in Xamarin.Android porject

I'm developing cross platform app using Xamarin.Forms and I'm having problems to use dotfuscator in my Xamarin.Android project. This is my development environment:

  • Windows 10 Pro
  • Visual Studio Professional 2017 (version 15.9.22)
  • Dotfuscator Community 5.44

Android project:

  • Application:
    • Compile using Android version: Android 9.0 (Pie)
  • Android Manifest:
    • Minimum Android version: Android 5.0 (API Level 21 - Lollipop)
    • Target Android version: Android 9.0 (API Level 28 - Pie)
  • Xamarin.Forms 4.6

I'm following this guide: Integrating Dotfuscator's Protection into Your Xamarin Apps in Visual Studio

Import the Targets File

In the Import the Targets File step I had to add an <Import> tag with the relative path to targets file. When I opened the project file, I could see that the tag already existed:

<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />

I checked that the file existed in this path: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Xamarin\Android\Xamarin.Android.CSharp.targets . I didn't change this tag, because I thought it was a correct configuration.

Set MSBuild Properties

In the Set MSBuild Properties step I added a <PropertyGroup> tag. I added it as the first node of <Project> root node.

<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <DotfuscatorXamarinConfigFileName>DotfuscatorConfig.xml</DotfuscatorXamarinConfigFileName>
    <DotfuscatorXamarinCliPath>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\PreEmptiveSolutions\DotfuscatorCE\dotfuscatorCLI.exe</DotfuscatorXamarinCliPath>
    <DotfuscatorXamarinGenerateNewConfigFile>true</DotfuscatorXamarinGenerateNewConfigFile>
    <!-- Enable Dotfuscator for Release -->
    <DotfuscatorXamarinEnabled Condition="'$(Configuration)' == 'Release'">true</DotfuscatorXamarinEnabled>
  </PropertyGroup>
  ...

Add Dotfuscator Config File to Project

In the Add Dotfuscator Config File to Project step I added this <ItemGroup> tag, after the last <ItemGroup> one:

  ...
  </ItemGroup>
  <ItemGroup>
    <None Include="DotfuscatorConfig.xml" />
  </ItemGroup>
  <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>

After these 3 steps, I saved the project file, closed it in the editor and reloaded the project. Then, I selected the Android project as StartUp project, and Release in the configuration combobox. After that I built the project and this is the output:

2>  MyApp.Android -> C:\..\MyApp\MyApp.Android\bin\Release\MyApp.Android.dll
2>  No way to resolve conflict between "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" and "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e". Choosing "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" arbitrarily.

Nothing about the lines described in the 5th step of Build the Project with Dotfuscator's Protection :

2>  Running Dotfuscator with a new config file based on project references...
2>  Finished running Dotfuscator with a new config file.
2>C:\code\protected-bugsweeper\BugSweeper\BugSweeper.Android\BugSweeper.Android.csproj : warning : A new Dotfuscator config file was generated because it did not exist: 'DotfuscatorConfig.xml'.

And DotfuscatorConfig.xml file was not created.

What am I doing wrong?

The <Import> tag you mention in Import the Targets File is different than the one the instructions tell you to add. In other words, there should be multiple <Import> tags in your project file by the time you finish editing it.

The tag you mention is part of a normal Xamarin project file, and unrelated to Dotfuscator. It refers to a .targets file that is already part of your Visual Studio installation. Please do not remove or modify this tag.

The tag the instructions tell you to add is the one that imports Dotfuscator into your project. It refers to the PreEmptive.Dotfuscator.Xamarin.targets file you downloaded in an earlier step . For instance, if you extracted the ZIP file's contents into the same directory as your .csproj , then add:

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

immediately before the closing </Project> tag. If you extracted the ZIP contents into a different directory, then change the part between the " marks to be the relative path from your .csproj directory to the file.

( Note : I am a developer on Dotfuscator, and am answering this question in that capacity.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM