6

I am upgrading an Asp.Net Website project to .net framework 4.8 from 4.7. After upgrading, the project builds successfully from visual studio and also running without any issue on local machine. When same project is published using MSBuild I am getting following error: (AspNetMerge target) -> aspnet_merge : error occurred: An error occurred when merging assemblies: Unresolved assembly reference not allowed: System.Net.Http.

MsBuild command used is: msbuild.exe "D:\Enterprise\Enterprise.sln" /nologo /nr:false /t:Build /p:DeployOnBuild=true /p:Configuration=Release /p:PublishProfile=VSO

And VSO.pubxml file referenced here has following configuration:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <publishUrl>..\..\Publish\Web</publishUrl>
    <DeleteExistingFiles>False</DeleteExistingFiles>
    <PrecompileBeforePublish>True</PrecompileBeforePublish>
    <EnableUpdateable>False</EnableUpdateable>
    <DebugSymbols>False</DebugSymbols>
    <WDPMergeOption>MergeAllOutputsToASingleAssembly</WDPMergeOption>
    <UseMerge>True</UseMerge>
    <SingleAssemblyName>MergedAssembly</SingleAssemblyName>
  </PropertyGroup>
</Project>

You can see that <UseMerge> is set to true which will merge output to single assembly. I tried by disabling merge altogether which fixed the issue, but I want to keep the merge option enabled as it was configured this way in the release pipeline earlier. Any help will be appreciated.

aksvinu
  • 147
  • 10
  • What version of system.net.http are you referencing? Do any of your projects have a nuget reference to system.net.http? – Jeff Mar 28 '20 at 18:04

2 Answers2

7

I have solved this issue by installing Microsoft.Aspnet.Merge NuGet package (dont forget to click preview checkbox).

enter image description here

A_HREF
  • 91
  • 3
  • 9
  • This is the only solution that worked for me. I've converted a web project to dotnet 4.7.2 and build would fail at merge time with an unresolved reference to System.Core. I've updated all projects to 4.7.2, resolved all assemblies conflicts, cleared cache, reinstalled all nuget packages... everything to no avail. Finally tried your approach (thanks for the "Include prerelease" tip). I would really love to know where you did find this! Maybe there is more information on the subject! But thank you anyway. – Loudenvier Jul 27 '20 at 14:29
6

System.Net.Http is a library that brings so much problems to plain developers. There are many unbelievable issues with it after NuGet packages update or after targeting new .NET Framework.

Unfortunately there is no silver bullet for resolve all these issues. It depends on many factors what really caused this error.

What is most likely cause such errors

Most likely this is config file's <dependencyAssemblies> section. After project .NET Framework retargeting there are NuGet packages that can't be resolved using old versions of dependency assemblies.

What you can try

Use following workflow to retarget your projects on new .NET Framework version:

  1. Change .NET Framework version in project/solution
  2. Update NuGet packages (in Package Manager Console: update-package)
  3. Reinstall NuGet packages (in Package Manager Console: update-package -reinstall)
  4. Rebuild project/solution
  5. Check Warnings window for some records like Found conflicts between different versions of the same dependent assembly. Double click on these records and press Yes on each popup window.
  6. Rebuild project/solution again

Now your project correctly retargeted on new .NET Framework version with all dependencies update. And error must dissapear.

picolino
  • 4,856
  • 1
  • 18
  • 31