0

I experience the problem that in one solution the Fody weaving, in my case Fody.NameOf, doesn't work.

I created a new solution, copied the project in question and in this solution, the weaving works!

In the new solution I didn't configure anything special, e.g. to enable Fody or something else.

In the "original" solution I did a migration from NuGet to Paket recently, which might have to do with the problem.

My Visual Studio Version is 2012.

Onur
  • 5,017
  • 5
  • 38
  • 54

1 Answers1

0

When diffing the project folder, I found a difference in the project files

This block

  <Choose>
    <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.6.1'">
      <PropertyGroup>
        <__paket__Fody_targets>Fody</__paket__Fody_targets>
      </PropertyGroup>
    </When>
  </Choose>

is placed differently. After adjusting, it worked in both solutions.

I'm no expert in MSBuild but it seems to me, that in the non-working version fody is run before the compilation, so the results are probably overwritten.

Working project:

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Content Include="FodyWeavers.xml" />
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="NameOfPaket.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="paket.references" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <Choose>
    <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.6.1'">
      <PropertyGroup>
        <__paket__Fody_targets>Fody</__paket__Fody_targets>
      </PropertyGroup>
    </When>
  </Choose>

Not working project:

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <Choose>
    <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.6.1'">
      <PropertyGroup>
        <__paket__Fody_targets>Fody</__paket__Fody_targets>
      </PropertyGroup>
    </When>
  </Choose>
  <ItemGroup>
    <Content Include="FodyWeavers.xml" />
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="NameOfPaket.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="paket.references" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Onur
  • 5,017
  • 5
  • 38
  • 54
  • Onur, I'm not versed in Fody, if you think there is a bug in paket in the way it handles adding the MSBuild target in your project files, consider submitting an issue on github repository: https://github.com/fsprojects/Paket Thanks! – smoothdeveloper Apr 23 '16 at 13:23