简体   繁体   中英

How can I implement Dotfuscator on a .NET Standard 2.0 project?

I'm in the process of of upgrading an existing Xamarin app from PCL to .NET Standard 2.0. I have several sub-projects such as business, data, BDO etc. which were PCL, I've been able to update them to .NET Standard 2.0 using this tutorial .

However I have Dotufscator implemented on all my PCL projects using this Xamarin Blog implementation, but it does not appear to work as an instruction for .NET Standard 2.0 projects. The DLL is not obfuscated and the 'Running Dotfuscator' message does not show in the Build Output.

My current attempt at adding Dotufcator to a .NET Standard 2.0 proj file is as follows:

<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>

Would anyone be able to help? Thanks

As a disclaimer, I should mention I'm answering this post as part of my job as a developer and technical writer on the Dotfuscator team. I also wrote the blog post you linked to , so I'm glad you've found it valuable in protecting your Xamarin app.

First, there's an ambiguity in the blog post that I should clear up. The Dotfuscator-Xamarin MSBuild integration shown there is only intended to be integrated into platform-specific Xamarin projects which build into a packaged format, like an Android project that builds an APK. Integrating directly into library projects like Portable Class Libraries (PCLs) or .NET Standard Libraries isn't supported.

Note that integrating Dotfuscator into a Xamarin project will protect all packaged assemblies that originated from your solution, so your library code will still be protected. For instance, if you integrate Dotfuscator into MyApp.Android.csproj , which references A.csproj , B.csproj , and C.csproj , Dotfuscator will protect all four projects' assemblies when they are packaged into the APK. This approach allows for stronger protection and doesn't require you to run Dotfuscator for each library separately, saving you build and configuration time.

If you are using the commercially-licensed Dotfuscator Professional Edition , version 4.37.0 includes a new MSBuild integration . The new integration is easier to set up, fixes some known issues, and going forward will be the primary way we recommend using Dotfuscator, for projects of all kinds, not just Xamarin. I recommend upgrading Dotfuscator to this version and removing the Dotfuscator-Xamarin MSBuild integration from your .NET Standard projects. Then, add the new MSBuild integration to your platform-specific Xamarin projects; for details, see the Xamarin Getting Started page of our User Guide.

If you are using Dotfuscator Community Edition (included with all Visual Studio editions) or an older Professional Edition, please continue to use the Dotfuscator-Xamarin MSBuild integration mentioned by the blog post. I recommend you remove the integration from your .NET Standard Libraries and instead add it into the platform-specific Xamarin projects that reference them. Note that when integrating into a Xamarin project that references .NET Standard Libraries, there is a known issue where the first build will fail (because the integration doesn't understand the minimal project format .NET Standard uses); see this answer for a workaround. Subsequent builds will occur normally without needing a workaround.

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