System.IO.FileNotFoundException after changing TargetFramework to net6.0 while using assembly reference

Viewed 97

I have a project A that in its csproj has TargetFramework set to net48 and uses a local dll from another project B for an assembly reference. If I build both of the projects and run the app A it works correctly, and the bin folder contains every dll for Nuget packages the project B needs. When I change TargetFramework of both of the projects to net6.0 and build them, the bin folder of the project A doesn't contain the needed dlls anymore, and if i run the app A it stops with the exception: "System.IO.FileNotFoundExceptionn: Could not load file or assembly".

Here's an example of what the project A's csproj looked like before:

<PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net48</TargetFramework>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
    <LangVersion>latest</LangVersion>
    <RootNamespace>ProjectA</RootNamespace>
</PropertyGroup>

<ItemGroup>
    <Reference Include="ProjectB">
        <HintPath>..\..\SolutionB\ProjectB\bin\Release\ProjectB.dll</HintPath>
    </Reference>
</ItemGroup>
And here's how it looks after switching to net6.0 (I'm including other minor changes in case it turns out to be important):
<PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
    <LangVersion>latest</LangVersion>
    <RootNamespace>ProjectA</RootNamespace>
</PropertyGroup>

<ItemGroup>
    <Reference Include="ProjectB">
        <HintPath>..\..\SolutionB\ProjectB\bin\Release\net6.0\ProjectB.dll</HintPath>
    </Reference>
</ItemGroup>

I couldn't find the answer for why it behaves differently and what is needed to achieve the same behaviour as before, if it's even possible. If not then what is the best way to reference another project's assembly? Would really appreciate the help on this.

0 Answers
Related