Azure websites deployment fail - found conflicts between different versions of the same dependent assembly - asp.net

My azure websites deployment is failing. Everything is working fine on my local machine: I can't see any problems or conflicts when log verbosity is set to detailed in Visual Studio's output window.
But I can't figure out how to see logs and fix the following error in Kudu when trying to deploy to Azure:
Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling .NET Web Application deployment.
MSBuild auto-detection: using msbuild version '14.0' from 'D:\Program Files (x86)\MSBuild\14.0\bin\amd64'.
All packages listed in packages.config are already installed.
MyProject.Broadbean -> D:\home\site\repository\MyProject.Broadbean\bin\Release\MyProject.Broadbean.dll
MyProject.Domain -> D:\home\site\repository\MyProject.Domain\bin\Release\MyProject.Domain.dll
MyProject.Mandrill -> D:\home\site\repository\Mandrill\bin\Release\MyProject.Mandrill.dll
D:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1819,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed. [D:\home\site\repository\MyProject.WebUI\MyProject.WebUI.csproj]
D:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\Microsoft.TypeScript.targets(242,5): warning : No compiler log specified, 'Clean' won't work. [D:\home\site\repository\MyProject.WebUI\MyProject.WebUI.csproj]
CSC : error CS1703: Multiple assemblies with equivalent identity have been imported: 'D:\home\site\repository\packages\System.Xml.ReaderWriter.4.3.1\lib\net46\System.Xml.ReaderWriter.dll' and 'D:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.6.1\Facades\System.Xml.ReaderWriter.dll'. Remove one of the duplicate references. [D:\home\site\repository\MyProject.WebUI\MyProject.WebUI.csproj]
CSC : error CS1703: Multiple assemblies with equivalent identity have been imported: 'D:\home\site\repository\packages\System.ComponentModel.Annotations.4.5.0\lib\net461\System.ComponentModel.Annotations.dll' and 'D:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.6.1\Facades\System.ComponentModel.Annotations.dll'. Remove one of the duplicate references. [D:\home\site\repository\MyProject.WebUI\MyProject.WebUI.csproj]
Failed exitCode=1, command="D:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" "D:\home\site\repository\MyProject.WebUI\MyProject.WebUI.csproj" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="D:\local\Temp\8d69b9dee0afc5a";AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release;UseSharedCompilation=false /p:SolutionDir="D:\home\site\repository.\"
An error has occurred during web site deployment.
\r\nD:\Program Files (x86)\SiteExtensions\Kudu\79.20129.3767\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"
How do I see this build log in Kudu or the Azure websites environment and fix these errors? I'm obviously missing something. The background is that I updated a lot of nuget packages, the site now breaks on deployment, and I can't quite figure out how to fix it.

To fix the "Multiple assemblies with equivalent identity have been imported. Remove one of the duplicate references." error, I removed the references for those assemblies.
That allowed me to deploy. But on deployment I got error screens because of conflicts between different assemblies.
To fix the "Found conflicts between different versions of the same dependent assembly that could not be resolved." conflicts, I removed the binding redirects for problematic assemblies in the web.config file.

What it is trying to say that
.net framework itself has System.Xml.ReaderWriter.dll so you don't have add it separately.
Please remove any reference of System.Xml.ReaderWriter.dll from your project .
similarly you have to do it for other assemblies .

Please debug you deploy.cmd using log in every steps which you think could cause build failure.
It seems that due to nuget update in your project, you have conflicts between different versions of the same dependent assembly. Please look at the assemblies you have upgraded and check their compatibility in your project.
I believe you must be running your build using some build agent, if you have access to the build agent and log in to the VM and try to debug your cmd file.
Also, please replicate and install the same environment in your Agent VM as you have it in your local, most of the time , this is the reason of build failure.
Hope it helps.

Related

Why does building with Microsoft.Xml.SgmlReader 1.8.18 nuget output this warning MSB2346

I'm using the Microsoft.Xml.SgmlReader nuget in several places of my .Net Core 3.1 projects.
The build output says:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2123,5): warning MSB3246: Resolved file has a bad image, no metadata, or is otherwise inaccessible. Could not load file or assembly 'SgmlReader.exe' or one of its dependencies. The module was expected to contain an assembly manifest.
I'm unable to google what this really means or how I fix it. Maybe I should be using a different incarnation of the SgmlReader nuget, only this one (1.8.18) seems to be the one most up-to-date.
Edit:
No information reg. sgmlreader in fusion logs when building (or starting VS2019).
But I did notice these two in the references:
Compile Time Assemblies, SgmlReader.exe and SgmlReaderDll.dll
I can open SgmlReaderDll.dll in JustDecompile, but not SgmlReader.exe.
I also notice that the exe is part of netcoreapp3.1, but not netstandard2.0 and netstandard2.1. That does not look right to me.

MSBuild not compiling with both /p:Configuration=Release and -p:Configuration=Debug

We are attempting to install a clean build of the newest version of Kentico (12) on Azure, using Kudu, in DEBUG configuration. We traditionally accomplish this by setting SCM_BUILD_ARGS to -p:Configuration=Debug, and all is well. But for some reason in this newer version, the project fails to compile, and I see that this is the command being run:
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" "C:\Users\User\Documents\GitHub\Project\CMS\CMSApp.csproj" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="C:\local\Temp\8d6d315018f5ff9";AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release;UseSharedCompilation=false /p:SolutionDir="C:\Users\User\Documents\GitHub\Project\.\\" -p:Configuration=Debug
Notice both Configuration=Release and Configuration=Debug. The compilation errors are things like Invalid expression term 'string' on the following line of code:
bool licenseOK = LicenseHelper.CheckLicenseLimitations(FeatureEnum.Ecommerce, out int skuCount, out int maxSKUCount);
This doesn't highlight at all in Visual Studio in Debug or Release mode. I am also able to reproduce locally (as shown in my paths above), and if I change the two configurations to both be the same (regardless of whether I choose Debug or Release), it compiles just fine.
What I know I can do is create my own custom deployment command script file as a work-around, but I guess I don't understand why the above MSBUILD command isn't working in the first place.
Any ideas as to why this would work great for all of my ASP.NET projects prior to this one? One thing I know is that Kentico recently included the Roslyn compiler, which I am unfortunately not that familiar with - could that be part of the issue?
UPDATE #1: It appears all of the compilation errors have to do with code that is only valid in C# 7.0. That could be a clue.
It all came down to the fact that the newer versions of Kentico had code that was only valid in C# 7, and required MSBuild 15 to compile. Here's how I was able to set up Kudu:
Add a file named .deployment in the root of my repo, containing only the contents below. This tells Kudu to use a custom deployment script.
Download the deploy.cmd file from my Azure App Service via FTP to the root of my repo, and update it per https://github.com/projectkudu/kudu/issues/2350#issuecomment-373817740 to use the MSBuild 15 path. Details below.
.deployment file contents
[config]
command = deploy.cmd
deploy.cmd updates
1 - Add -MSBuildPath "%MSBUILD_15_DIR%" to nuget call. Example:
nuget.exe restore "{your .sln file path}" -MSBuildPath "%MSBUILD_15_DIR%"
2 - Replace %MSBUILD_PATH% with %MSBUILD_15_DIR%\MSBuild.exe in both occurrences under step 2. Build to the temporary path
This was all that was needed in order to get the build to complete.
As Keith mentions, it was a compatibility issue with C# 7.0 that Kentico 12 uses. This SO thread mentions that you need to run MSBuild version 15 for C# 7.0 code. I ran a similar debug command for my local Kentico 12 project using MSBuild 15, and it succeeded.

VSTS Build failing - Error : Web deployment task failed

I have a build definition in Visual Studio Team Services (previously Visual Studio Online) to build an ASP.NET web application using an on-premise agent. The agent has VS2012 installed and all the other necessary prerequisites to assist in building the application. However, when running the build, it fails and outputs below error:
C:\Program Files
x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets(4021,2):
Error : Web deployment task failed. (The .zip file package
'C:\BuildAgent\_work\1\a\' must be a file, not a directory.)
Process 'msbuild.exe' exited with code '1'.
I tried building the project on the agent machine using VS2012 and it builds fine. Also, I have defined following MSBuild parameters in the build definition which is same as my other builds that use a hosted agent:
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"
What could be the cause of this issue? Do I need to install anything extra?
You are using VS2012, you need to specify detail PackageLocation argument with .zip suffix ($(build.artifactstagingdirectory)\testWeb.zip). If you are using higher version of VS/MSBuild (e.g. vs 2015), a folder path is ok, it will adds [XXX].zip to the end of that path.

Why am I getting Could not load file or assembly error on a System.Configuration DLL when using framework 4.0?

Immediately after we upgraded to visual studio 2010 and the 4.0 framework our trunk build started breaking with the Could not load file or assembly error.
We determined that a 3.5 project couldn't reference a 4.0 project else we'd get this error because, as the error states, This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
We've since resolved this and the trunk has been building fine.
I recently did a branch and tag, however, and suddenly this error has resurfaced when I try to build the branch; except the error is regarding one of our own .net 4.0 project's reference to System.Configuration DLL.
Towps.Namespace.MyService.csproj in Core.Dev\Towps\Projetcs\Application\MyService:
RG0000: Could not load referenced assembly
"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll". Caught a BadImageFormatException saying "Could not load file or assembly 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.". in ResGen(0, 0)
I tried setting the specific version property on that system.Configuration DLL ref to true. I can see in it's properties that the runtime version is v4.0.30319 and the Version is 4.0.0.0. The path to the DLL ref is C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Configuration.dll which to me looks fine.
The target framework for the csproj file that CrusieControl is using MSBuild to try to build is targeting framework 4.0. Again seems fine.
It builds in the IDE for both trunk & branch. Cruise Control build it in the trunk. The branch build fails when CrusieControl tries to build.
Any ideas what could be happening?
It could be an MSBuild mismatch but I've scanned the config files and msbuild proj files that CruiseControl is using and there are no references to older MSBuilds; which makes sense since all those were updated to get the trunk working.
The branch was simply a copy of the trunk so I'm having difficulty determining what could be the difference!
It turns out that after I branched, all the .proj files in my branch build directory that cc.net uses were back to using ToolVerison="3.5".
I thought I committed all the ToolsVersion="4.0" proj and config changes to the trunk from which I made the branch; evidentially not.
The difference could easily be hint paths no longer lining up on the new branch. However there's not a log to go on in your description. What are the command line options you are passing? In ccnet.config and also any others that may get in if ccnet.config is pointing at a build script that calls msbuild instead of directly to a .sln or .csproj file.
Turn on /v:d for the msbuild on BOTH and then compare the reference resolutions (or build order, etc..) for that assembly or other ones involved/near it.
Also are you providing the path to msbuild on both?
msbuild4="C:\WINNT\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
<msbuild>
<executable>$(msbuild4)</executable>
in your ccnet.config?
I've seen it report the 2.0 build executable during a msbuild4 /tv:3.5:
<Message Text="MSBuildToolsPath:$(MSBuildToolsPath)" />
<Message Text="MSBuildToolsVersion:$(MSBuildToolsVersion)" />
MSBuildToolsPath:C:\WINNT\Microsoft.NET\Framework\v2.0.50727
MSBuildToolsVersion:2.0
so that didn't seem very useful.
I'd like to see the config blocks for both branch and trunk.
I know I had some paths in the buildscript that failed in my branch because there was a hardcoded path that would not be valid for the branch. I had to adjust the ccnet.config to pass in arguments for those items to override for the branch.
Please check .net framework version supported by your client. For example sharepoint2010 will not support dll built by 4.0 or higher .net framework. It will support only 3.5 or below.
A bit late I know, but if anybody else has this issue, try adding the RuntimeVersion into your .dna file if it does not already exist.
<DnaLibrary Name="PROJECTNAME" RuntimeVersion="v4.0">

Mono's XSP webserver can't find MySql.Web.dll on Linux

I'm working on getting my ASP.Net project working on Linux. I've been testing my code using XSP on windows, but now I am trying to make sure that I can develop and test on Linux as well. To that end I've gotten Ubuntu running and have MonoDevelop and MySQL running. I've downloaded the latest MySQL Connector/Net and I think I have it installed correctly.
There is no package that will automatically install the MySQL Connector/Net for distribution so I downloaded the 6.2.3 zip file from the MySQL website. Now I've already discovered the issue with case sensitivity because the zip file contains filenames in lowercase, and Mono expects them in uppercase. So I've changed the names of the files to MySql.Data.dll, and MySql.Web.dll respectively. I've also used gacutil to install both files to the GAC. Likewise I have added the files to the Mono Lib directory. The following files do exist on my machine:
/usr/lib/mono/gac/MySql.Data/6.2.3.0__c5687fc88969c44d/MySql.Data.dll
/usr/lib/mono/gac/MySql.Web/6.2.3.0__c5687fc88969c44d/MySql.Web.dll
/usr/lib/mono/2.0/MySql.Data.dll
/usr/lib/mono/2.0/MySql.Web.dll
I've also created package files so that I can add references to the the assemblies in MonoDevelop. The folder /usr/lib/mono/2.0 contains two .pc files that I added.
MySql.Web.pc:
Name: MySql.Web
Description: ASP Membership, Role and Profile providers powered by MySQL
Version: 6.2.3
Libs: -r:/usr/lib/mono/gac/MySql.Web/6.2.3.0__c5687fc88969c44d/MySql.Web.dll
MySql.Data.pc:
Name: MySql.Data
Description: Provides connectivity to MySQL databases
Version: 6.2.3
Libs: -r:/usr/lib/mono/gac/MySql.Data/6.2.3.0__c5687fc88969c44d/MySql.Data.dll
At this point I can use the assemblies in projects inside MonoDevelop. The Assemblies appear in the list of available assemblies when I edit the project references. The project now compiles without error inside MonoDevelop. However when I run the compiled web project in XSP the following error is displayed in the browser:
System.IO.FileNotFoundException: Could not load file or assembly 'MySql.Web.dll, Version=6.2.3.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D' or one of its dependencies. The system cannot find the file specified.
What is fustrating is that originally the error was that it could not load MySql.Data.dll and now the error message is that it can not load MySql.Web.dll. Which means that I somehow fixed the problem I was having with the Data dll, and now I have the problem with the Web dll. I have gone and re-done I learned to fix the problem for the Data dll, but I am unable to get the Web dll working.
Unfortunately I'm still pretty new to Linux and Mono (but not to ASP.Net) and I've run out of things to try. Likewise I haven't found anything on Google to try other than what has been described above which leaves me asking for help.
Can anyone help me find out why XSP can't find the assembly and what I can do about it?
Thanks,
-Will
You can try setting some environment variables which should tell you where all Mono is looking for assemblies:
MONO_LOG_LEVEL="debug" MONO_LOG_MASK="dll" xsp2
Not a perfect fix (I don't know why its going wrong), but if you're in a hurry, copy MySql.Web.dll to the bin directory of your app.

Resources