Xamarin Android项目集成Dotfuscator时构建中断问题求助
Let's tackle the two key issues you're hitting when integrating Dotfuscator into your Xamarin project, step by step:
Issue 1: "There are no assemblies to process. Stopping the build..." Error
This error pops up because Dotfuscator is trying to run before your project generates the target .dll assembly, or it can't find any valid assemblies to process. Here's how to fix it:
Adjust the Targets file import order: The Dotfuscator Xamarin targets need to run after Xamarin's own build targets (which handle generating your app's
.dll). In yourAndroid.csproj, move the Dotfuscator targets import line after the Xamarin Android targets import. For most projects, that line looks like this:<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets"/>This ensures Dotfuscator only kicks in once the assembly is ready to be obfuscated.
Populate the
DotfuscatorIncludeAsInputproperty: Your current config leaves this empty, so Dotfuscator has no assemblies to work with. Update it to point directly to your project's output.dllusing MSBuild variables for dynamic pathing:<DotfuscatorIncludeAsInput>$(OutputPath)$(AssemblyName).dll</DotfuscatorIncludeAsInput>Build in Release mode: Dotfuscator is set to run only for Release builds by default. Double-check you're not trying to trigger it in Debug mode (a common oversight, even if it's not the direct cause of this error).
Issue 2: Obfuscation Doesn't Trigger, App Builds Normally
If your project builds fine but Dotfuscator never runs, here's what to investigate:
Scope the
DotfuscatorXamarinEnabledproperty correctly: Make sure the<DotfuscatorXamarinEnabled>true</DotfuscatorXamarinEnabled>setting is tied specifically to your Release configuration. Wrap it in a condition-specific PropertyGroup to avoid enabling it accidentally for Debug builds:<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> <DotfuscatorXamarinEnabled>true</DotfuscatorXamarinEnabled> <DotfuscatorXamarinConfigFileName>DotfuscatorConfig.xml</DotfuscatorXamarinConfigFileName> <DotfuscatorXamarinCliPath>C:\Program Files (x86)\PreEmptive Solutions\Dotfuscator Professional Edition Evaluation4.43.1\dotfuscator.exe</DotfuscatorXamarinCliPath> <DotfuscatorXamarinGenerateNewConfigFile>true</DotfuscatorXamarinGenerateNewConfigFile> <DotfuscatorIncludeAsInput>$(OutputPath)$(AssemblyName).dll</DotfuscatorIncludeAsInput> </PropertyGroup>Verify the Dotfuscator CLI path: Double-check that the path in
DotfuscatorXamarinCliPathis correct. Navigate to that folder in File Explorer to confirmdotfuscator.exeexists—typos in the version number (like "Evaluation4.43.1") are easy to miss.Check diagnostic build logs: Enable detailed build logging in Visual Studio (go to
Tools > Options > Projects and Solutions > Build and Run, set "MSBuild project build output verbosity" to Diagnostic). Rebuild your project, then search the Output window for "Dotfuscator" entries. These logs will tell you exactly if the targets ran, why they skipped, or if there are path/configuration errors.Confirm the config file was generated: With
<DotfuscatorXamarinGenerateNewConfigFile>true</DotfuscatorXamarinGenerateNewConfigFile>, aDotfuscatorConfig.xmlshould appear in your project directory after a Release build. If it's missing, the Dotfuscator targets didn't execute at all—double-check the Targets import order and configuration properties again.
内容的提问来源于stack exchange,提问作者Сергей

