I'm currently building a Class Library that targets both .NET Framework 4.8 and .NET7. Code-wise, everything works perfectly fine. The dependencies used on this project are all compatible on both targets. The issue is the configuration of Costura.Fody. The same configuration of FodyWeavers.xml that used to work for .NET7 when the project was just for .NET7 now works for .NET Framework 4.8 but not the .NET7

My .csproj:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFrameworks>net48;net7.0</TargetFrameworks>
        <LangVersion>latest</LangVersion>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <GenerateDocumentationFile>True</GenerateDocumentationFile>
    </PropertyGroup>

    <!-- Common Package References -->
    <ItemGroup>
        <PackageReference Include="Azure.Core" Version="1.35.0" />
        <PackageReference Include="Azure.Identity" Version="1.10.2" />
        <PackageReference Include="Azure.Security.KeyVault.Keys" Version="4.5.0" />
        <PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.5.0" />
        <PackageReference Include="BouncyCastle.Cryptography" Version="2.2.1" />
        <PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
        <PackageReference Include="Microsoft.Identity.Client" Version="4.56.0" />
        <PackageReference Include="Microsoft.IdentityModel.Abstractions" Version="7.0.3" />
        <PackageReference Include="System.Memory.Data" Version="7.0.0" />
        <PackageReference Include="Fody" Version="6.8.0" PrivateAssets="all" />
        <PackageReference Include="Costura.Fody" Version="5.7.0" PrivateAssets="all" />
    </ItemGroup>

        <!-- FodyWeavers Configuration -->
    <ItemGroup Condition="'$(TargetFramework)'=='net7.0'">
        <None Include="FodyWeavers.net7.xml">
            <Link>FodyWeavers.xml</Link>
            <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        </None>
    </ItemGroup>
    <ItemGroup Condition="'$(TargetFramework)'=='net48'">
        <None Include="FodyWeavers.net48.xml">
            <Link>FodyWeavers.xml</Link>
            <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        </None>
    </ItemGroup>

    
</Project>

I have create this Costura.Fody conf:

<?xml version="1.0" encoding="utf-8" ?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
    <Costura LoadAtModuleInit="true">
        <IncludeAssemblies>
            Azure.Identity
            Azure.Security.KeyVault.Keys
            Azure.Security.KeyVault.Secrets
            Azure.Core
            Microsoft.Extensions.Configuration
            Microsoft.Identity.Client
            Microsoft.IdentityModel.Abstractions
            System.Memory.Data
            BouncyCastle.Cryptography
        </IncludeAssemblies>
    </Costura>
</Weavers>

It used to work with .NET7 only. Now that I added the multi-targeting, with this .csproj it works for .NET Framework 4.8 but not .NET7. So it produces both projects, but doesn't embed the .dlls on the /bin/Release/net7/ but it does on /bin/Release/net48/ and I tested it and the dll works as expected.

The problem is obviously the .csproj I guess or the way I'm configuring Costura.Fody while I want to do multi-targeting building. I am not really sure about it.

Might anyone have the experience of how multi-targeting should be done and what I need to change on my csproj to make this work for both .NET7 and .NET Framework 4.8?

Kind regards, Fotis

0

There are 0 answers