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.
I have solved this issue by installing Microsoft.Aspnet.Merge NuGet package (dont forget to click preview checkbox).
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.
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.
Use following workflow to retarget your projects on new .NET Framework version:
update-package
)update-package -reinstall
)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.Now your project correctly retargeted on new .NET Framework version with all dependencies update. And error must dissapear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With