You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Visual Studio 2017中Fody-Costura与Obfuscar能否结合使用?

Combining Fody-Costura with Obfuscar (MSBuild.Obfuscar) in Visual Studio 2017

Absolutely, you can use these two tools together—you just need to tweak the MSBuild target execution order to make sure Obfuscar runs before Costura processes your dependencies. Here's how to fix the "missing dependencies" error you're seeing:

The Core Issue

Costura’s job is to embed dependencies into your executable, which means it will either replace original dependency files with embedded versions or remove them from your output directory. Right now, Costura is running first, so when Obfuscar tries to process those dependencies, they’re already gone or modified. We need to flip that order: let Obfuscar obfuscate all assemblies (main + dependencies) first, then let Costura embed the obfuscated dependencies.

Step-by-Step Fixes

1. Adjust Obfuscar’s Execution Target via Project File

MSBuild.Obfuscar lets you control when its Obfuscate target runs using the ObfuscateBeforeTargets property. Since Costura runs as part of Fody’s core FodyWeave target, we can tell Obfuscar to run right before that:
Open your project’s .csproj file (right-click project → Edit .csproj) and add this property group:

<PropertyGroup>
  <!-- Make Obfuscar run before Fody/Costura weaves the assembly -->
  <ObfuscateBeforeTargets>FodyWeave</ObfuscateBeforeTargets>
</PropertyGroup>

This ensures Obfuscar processes all your unmodified dependencies while they’re still in the output directory.

2. Force Target Order with a Custom Target (Fallback)

If the above doesn’t work (depending on your specific Fody/Costura version), you can explicitly create a target that triggers Obfuscar before Costura runs:
Add this to your .csproj file:

<Target Name="RunObfuscateBeforeCostura" BeforeTargets="FodyWeave">
  <CallTarget Targets="Obfuscate" />
</Target>

This custom target will execute the Obfuscate target immediately before Fody starts weaving (which includes Costura’s embedding step).

Verification Tips

  • Clean and Rebuild: Always clean your project first (Build → Clean Solution) then rebuild to ensure the new target order is respected.
  • Check MSBuild Logs: If you’re still having issues, run MSBuild with detailed logging to confirm the order. Open the Developer Command Prompt for VS 2017, navigate to your project directory, and run:
    msbuild /v:detailed
    
    Look for entries for Obfuscate and FodyWeave—you should see Obfuscate execute first.

Key Notes

  • Make sure Obfuscar is configured to process all your dependency assemblies (not just the main executable). Double-check your Obfuscar.xml config to include any DLLs you want obfuscated before embedding.
  • After obfuscation, Costura will embed the obfuscated versions of your dependencies, so your final executable will have both obfuscated code and embedded dependencies as intended.

内容的提问来源于stack exchange,提问作者TheGuy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:51:10