SGEN error when issuing a mixed version version of ASP.Net and .Net Standard 2.0 mixed projects

I am working on a Visual Studio 2017 solution that contains 3 projects:

Two class libraries in .Net Standard 2.0 (any processor)
One ASP.Net in .Net Framework 4.6.1 (any processor)

If I create everything in debugging (any processor), everything works fine.
But if I create everything in the release (any processor), then this error is displayed in the output window:

3> SGEN: error: an attempt was made to load the assembly with the wrong format: C: \ Program Files (x86) \ Microsoft Visual Studio \ 2017 \ Community \ MSBuild \ Microsoft \ Microsoft.NET.Build.Extensions \ net461 \ ref \ netfx. force.conflicts.dll.

How to solve it?

+6
source share
1 answer

The error occurs due to confusion between the NETStandard and NuGet libraries when resolving DLLs. Put this in your .csproj project file. (Unload the project, edit the .csproj file):

<Target Name="ReplaceNetFxNetStandardRefWithLib" AfterTargets="ImplicitlyExpandNETStandardFacades">
  <ItemGroup>
    <Reference Remove="@(_NETStandardLibraryNETFrameworkReference)" Condition="'%(FileName)' != 'netfx.force.conflicts'" />
    <Reference Remove="@(_NETStandardLibraryNETFrameworkReference)" Condition="'%(FileName)' != 'System.Configuration.ConfigurationManager'" />
    <Reference Include="@(_NETStandardLibraryNETFrameworkLib)">
      <Private>true</Private>
    </Reference>
  </ItemGroup>
</Target>
<Target Name="RemoveNetFxForceConflicts" AfterTargets="ResolveAssemblyReferences">
  <ItemGroup>
    <ReferencePath Remove="@(ReferencePath)" Condition="'%(FileName)' == 'netfx.force.conflicts'" />
    <ReferencePath Remove="@(ReferencePath)" Condition="'%(FileName)' == 'System.Configuration.ConfigurationManager'" />
  </ItemGroup>
</Target>
+4
source

All Articles