Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in publishing project with MSBuild after upgrading from .Net Framework 4.7 to 4.8

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.

like image 352
aksvinu Avatar asked Jan 08 '20 15:01

aksvinu


2 Answers

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

enter image description here

like image 74
A_HREF Avatar answered Nov 15 '22 01:11

A_HREF


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.

like image 38
picolino Avatar answered Nov 14 '22 23:11

picolino