Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dotfuscator throwing error on Xamarin.Android project

I followed the steps to integrate Dotfuscator into my Xamarin.Android project as described here, but when it's time to build the project, I'm getting the following error:

The "_DotfuscatorXamarin_DetermineDefaultInputsTask" task failed unexpectedly. 2>\path\to\PreEmptive.Dotfuscator.Xamarin.targets(570,5): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object. 2>\path\to\PreEmptive.Dotfuscator.Xamarin.targets(570,5): error MSB4018: at InlineCode._DotfuscatorXamarin_DetermineDefaultInputsTask.Execute() in \path\to\AppData\Local\Temp\eruovv3u.0.cs:line 106 2>\path\to\PreEmptive.Dotfuscator.Xamarin.targets(570,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() 2>\path\to\PreEmptive.Dotfuscator.Xamarin.targets(570,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()

I have looked and looked online, but no one seems to be having this issue. I think the problem has something to do with generating the default configuration file on the first build. Any ideas?

like image 515
AxiomaticNexus Avatar asked Dec 13 '22 20:12

AxiomaticNexus


1 Answers

UPDATE: This issue has been fixed in newer versions of Dotfuscator. See the detailed instructions for the free Dotfuscator Community and for the commercially-licensed Dotfuscator Professional. The original answer follows below.


Full Disclosure: I am a developer of Dotfuscator at PreEmptive Solutions, and am answering this question in that role.

You're right, the problem is the default config file generation in the targets file (PreEmptive.Dotfuscator.Xamarin.targets) - sorry about that. Specifically, the build integration is attempting to discover project references, but expects the classic MSBuild project format, not the new minimal one used by .NET Standard.

You can work around this issue as follows:

  1. In the targets file, locate the _DotfuscatorXamarinConfigTemplateLines property and copy its value (within the CDATA section) to a new file named DotfuscatorConfig.xml (or whatever value you supplied for the DotfuscatorXamarinConfigFileName property in your project file) in the same directory as your project file.
  2. In Visual Studio, build your project once in a configuration you want to protect (e.g., AnyCPU|Release). It will error, because the new config file doesn't have any input assemblies yet, but by building now we get those assemblies in the right location for configuring Dotfuscator.
  3. Open Dotfuscator's user interface.
    • For Community Edition, from Visual Studio, open the Tools menu and select PreEmptive Protection - Dotfuscator.
    • For Professional Edition, run Dotfuscator Professional Edition from the Start Menu.
  4. In the user interface, File | Open the file created in step 1.
  5. On the Inputs screen, click the "Add Input" button (a green plus-sign in Community Edition, a folder-opening icon in Professional Edition).
  6. Browse to your project directory, then obj\Release\DotfuscatorXamarin\dfin, and then select the assemblies you want to protect.
    • Substitute Release with the appropriate directory for the configuration you built in step 2.
    • You should select assemblies that correspond to projects in your solution, and not select third-party and assemblies that are part of the framework.
  7. Save the config file.
  8. Navigate to the Project Properties editor.
    • In Community Edition, go to the Build Settings screen and select the Project Properties tab.
    • In Professional Edition, go to the Settings tab and select the Settings > Project Properties screen.
  9. Add the following project properties (instructions for Community Edition, and for Professional Edition):
    • Property name InDir, value obj\Release\DotfuscatorXamarin\dfin
    • Property name OutDir, value obj\Release\DotfuscatorXamarin\dfout
    • Property name ReportDir, value DotfuscatorReports\Release
    • Substitute Release with the appropriate directory for the configuration you built in step 2. Note that the directories pointed to by OutDir and ReportDir won't exist on-disk yet.
  10. Save the config file.
  11. Return to the Inputs screen and select an input and click the pencil icon. Edit the path to the assembly from an absolute path to ${configdir}\${InDir}\AssemblyName.dll, substituting AssemblyName.dll for the actual name and extension of the assembly. Repeat for each input assembly.
  12. Save the config file (and commit it to source control).
  13. Rebuild the project in Visual Studio. The build integration will use your config file instead of trying to generate a new one.
like image 119
Joe Sewell Avatar answered Dec 28 '22 09:12

Joe Sewell