13

I'm using Costura.Fody to embed all dlls into my application assembly.

Is there any way to disable Costura.Fody in Debug build mode? How to make Costura.Fody to work only in Release or custom build configuration?

Hooch
  • 25,377
  • 28
  • 89
  • 154

3 Answers3

14

One solution might be to check your .csproj file and add a condition to the Fody-related lines. Something like this:

<Content Include="FodyWeavers.xml" Condition=" '$(Configuration)' == 'Release' " />

<Import Project="..\..\packages\Fody.1.29.4\build\dotnet\Fody.targets" Condition="Exists('..\..\packages\Fody.1.29.4\build\dotnet\Fody.targets') And '$(Configuration)' == 'Release' " />

Of course, this is mainly for simple use cases where you don't want any Fody extension to run in certain build environments.

Kaj Nelissen
  • 873
  • 7
  • 26
  • 2
    this seems to disable all Fody plugins. When I have multiple fody plugins, for example, Costura.Fody and ReactiveUI.Fody, it also disable ReactiveUI.fody. Any suggestion to my case to disable only `Costura.Fody`? – Felix Mar 22 '17 at 08:54
  • The problem with this method is that on an update of the Fody Extension (for example over NuGet) the condition is deleted again – Apfelkuacha Jan 07 '20 at 14:44
6

By default Costura.Fody package only adds one line into your *.csproj file:

  <Import Project="Fody.targets" />

Replace it with

  <Import Project="Fody.targets" Condition=" '$(Configuration)' == 'Release' " />
trailmax
  • 31,605
  • 20
  • 126
  • 225
  • The problem with this method is that on an update of the Fody Extension over NuGet the condition is deleted again. I have posted an answer which doesn't have this problem – Apfelkuacha Jun 24 '20 at 09:27
  • @Apfelkuacha I don't think your option was available at the time when this answer was written. – trailmax Jun 24 '20 at 09:38
6

According to Costura Github, a better possiblity is to open the .csproj and insert following line into the first <PropertyGroup>:

<DisableFody Condition="'$(Configuration)' == 'Debug'">true</DisableFody>

This way you don't have to modify the file again if there is a package update

Apfelkuacha
  • 644
  • 8
  • 20