Azure DevOps Build missing assembly reference - c#

I have a build process on Azure DevOps that I have been building successfully for awhile now.
Recently one of my developer added a page that contains the MVC library
using System.Web.Mvc
However, the build keeps failing now when I build it via the Azure DevOps build agent as part of our CI/CD process.
ClassName.cs(5,18): Error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
It compiles if I compile manually using Visual Studio 2017 on my own laptop or if I use the Visual Studio 2017 on the build machine where the Azure DevOps build agent runs.
The steps that I've tried to troubleshoot:
Ensure in my Project's NuGet, that I have Microsoft.Aspnet.MVC latest
vesrion.
I've tried to reinstall Microsoft.Aspnet.MVC on the build
machine through NuGet
I verified my project' default package
management format is : Packages.config
I verified that my
packages.config has < package id="Microsoft.AspNet.Mvc" version="5.2.7" targetFramework="net472" />
I tried to reinstall all
the package on my build machine by running Update-Package
--reinstall command.
I verified that on the build agent machine I have the Microsoft.AspNet.Mvc folder and all of its dlls under repositoryPath -
$(Solutiondir)/packages and globalPackagesFolder -
$(UserProfile).nuget\packages
I'm running out of idea on why it compiles on Visual Studio manually but has error when I compile using the build agent through MS Build on x64 bits.

I have tried to reproduce your bug by comparing two new ASP.NET Web Application (.NET Framework) projects, one created with an empty template and the other with the MVC template. The MVC project comes with the System.Web.Mvc reference and the empty one does not, so I have come up with additional troubleshooting steps while manually adding the reference to the empty project.
Make sure the project file that is failing to build includes a reference to the Microsoft.AspNet.Mvc package which includes a path (use your latest version)
<Reference Include="System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.2.4\lib\net45\System.Web.Mvc.dll</HintPath>
</Reference>
You can copy this and it from a newly created MVC template. An implicit reference <Reference Include="System.Web.Mvc" /> will only work if build artifacts were generated before which could be a good reason for a build succeeding in development and failing in the build pipeline.
Clean the solution, close Visual Studio and delete all bin and obj folders to make sure your build is not succeeding because of previous ones and Visual Studio does not regenerate them.
Use the Developer Command Prompt to call msbuild.exe in the project folder, this will be a more similar environment to your build pipeline than building with Visual Studio

Related

How to change a nuget packet assembly version

In Visual Studio with my Asp.net core project, I have used some nuget packets (like StackExchange.Redis, Serilog etc..). I decided to use Visual studio 2019. Everything was going well, but one day I noticed some projects couldn't update their referenced projects in solution. Because they are (.net standard libraries) taking output codes to obj folder instead bin folder.
I decided to return Visual Studio 2017. Everything working great with VS2017, but this time it giving me a run time error such as could not found referenced assembly public key etc.. like below
I have removed old pockets from all projects in the solution by the package manager nuget manager. I have installed a new version by the nuget manager tool. But project always seemto be using the old version.
FileNotFoundException: Could not load file or assembly 'StackExchange.Redis, Version=2.0.0.0, Culture=neutral, PublicKeyToken=c219ff1ca8c2ce46'. The system cannot find the file specified.
For example, if I install a nuget packet version 2.0.0.0 and I want to remove it all from project and I want to install a new version by an upgrade or downgrade. What should I do? How can I change it?
Update: I have uninstalled 2 packages from nuget and from windows, still project seen this assemblies!
Severity Code Description Project File Line Suppression State
Error CS0433 The type 'ConnectionMultiplexer' exists in both
'StackExchange.Redis.StrongName, Version=1.2.6.0, Culture=neutral,
PublicKeyToken=c219ff1ca8c2ce46' and 'StackExchange.Redis,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=c219ff1ca8c2ce46' Tursys.Pool.Storage.Api D:\projects\tursys\PoolStorage\src\Tursys.Pool.Storage.Api\Startup.cs 76 Active
Both of them not exist
You can try it:
Install-Package "YourProjectName" -Version 6.2.0
Answering my own question, for anyone:
VS-2019 corrected it's output folder as bin folder with a new bug-fix! but it was not related with the nuget package removement problem
How to remove a package from a project:
In Visual Studio i want to go to file with F12 key. And with the open target folder command i see the local folder of the removed package as
C:\Users\HAMIT\AppData\Local\Temp\MetadataAsSource\821e7bd605414042826501fe0b5cdc21\32ae5450ea724e84b62f983bdb6bb879
I have deleted this temp files but by the rebuild process VS restored them again. This some bored me and i found a new manner. There is always a technic to removing a package from the VisualStudio with the -force argument like below in PM Console
Uninstall-Package -ProjectName "YourProjectName" -RemoveDependencies -Force
When you put this command it will asking you the PackageId will be removed. Write your package name and it is ok!
If you dont know your package name exactly then you can get a list according your project like below:
Get-Package -ProjectName "YourProjectName"
But uninstalling to StackExchange.Redis.StrongName still is enigma!!!
UPDATE: I found a solution for this too! Change Aspnetcore framework 2.2 to 3.0 under Visual Studio 2019. Now seem to right dlls and Everything corrected.

Build Error with pre-compiled Azure Function Library

Recently, I converted an Azure Function that used a C# script (*.csx) to a pre-complied class library using the Visual Studio Studio Tools for Azure Functions. It builds successfully in Visual Studio 2017 (as well as running and debugging too).
I'd like to build this AF library via our CI process. However, when I run the command dotnet build locally it fails with the following error:
C:\Users\ray\.nuget\packages\microsoft.net.sdk.functions\1.0.2\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5): error : Could not load file or assembly 'Microsoft.Azure.WebJobs.Host, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
The same error also occurs in our CI build.
Not sure why this error is occurring and how to resolve it. Is it the version of the dotnet CLI (I'm using v1.1)? Is it something else?
UPDATE 2018-01-08
According to a new answer by #theGRS https://stackoverflow.com/a/48156446/621827 this has been resolved.
Previous Answer
Here's what I've found.
dotnet msbuild uses the Microsoft.NET.Sdk.Functions .NETStandard 1.5 library which if you look at the dependencies on NuGet it doesn't use Microsoft.Azure.WebJobs
But if you use the Visual Studio 2017 msbuild it will use the .NETFramework 4.6 version of the library which includes Microsoft.Azure.WebJobs.
My suggestion is to use MSBuild for now.
I was having the same issue as well when running dotnet build, but no longer have this issue after updating Microsoft.NET.Sdk.Functions from 1.0.2 to 1.0.7.
Update to the latest version of this package in your Nuget package manaager and you should be able to run dotnet build again.

VS 2015 Multiple assemblies with equivalent identity have been imported

One of my project solution is working fine on a system where I have installed VS 2013. But When I open the same project on another system in VS 2015 it is giving this reference error:
Error CS1703 Multiple assemblies with equivalent identity have been imported: 'D:\src\packages\Microsoft.Bcl.1.1.10\lib\net40\System.IO.dll' and 'C:\Program Files (x86)\Reference
Assemblies\Microsoft\Framework.NETFramework\v4.5\Facades\System.IO.dll'. Remove one of the duplicate references.
The project file is referencing the package file, but when it opens in VS it auto converts to Framework library path. I can't uninstall the BCL package because it is a dependency for other packages.
Edit:
Why does the solution build fine in one version of Visual Studio but it gives the multiple assemblies error in another version?
Is there a way to resolve this issue so that it works in different versions?
I also have this issue however his solution builds perfectly in VS 2017 but it cannot build on VS 2015.
This error usually appears when a NuGet package has invalid dependencies, but this is not the case as everything works well in other versions of Visual Studio.
First you can force reinstall all NuGet packages. That can be done by opening the Package Manager Console and typing:
Update-Package -reinstall
Second most common solution to this problem is to ensure Visual Studio is updated to the latest version (Visual Studio 2015 Update 3 in this case). If that doesn't help, please try reinstalling Visual Studio completely on that device. Finally - you can try to install Visual Studio 2015 on another PC to verify if this is actually a problem of that version, or a PC-specific issue.
This error occurs when a non-portable library references to a portable library then the build system adds a facade assemblies. [1]
Try to remove following references:
<Reference Include="System.IO">
<HintPath>..\packages\System.IO.4.0.10-beta-22516\lib\net45\System.IO.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System.Text.Encoding">
<HintPath>..\packages\System.Text.Encoding.4.0.10-beta-22516\lib\net45\System.Text.Encoding.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Threading.Tasks">
<HintPath>..\packages\System.Threading.Tasks.4.0.10-beta-22516\lib\net45\System.Threading.Tasks.dll</HintPath>
<Private>True</Private>
</Reference>
If you are using a common assembly across multiple projects and want to ensure they are using the same version, I recommend installing that version into the Global Assembly Cache.
Then that version from the GAC will be available from the references dialog.
Use that same dialog for the references across assemblies.

vsts build fails on Microsoft.AspNet.Identity.EntityFramework

Got a git project hosten in VSTS. When i trigger a build in VSTS it fails stating the following:
You must add a reference to assembly
'Microsoft.AspNet.Identity.EntityFramework, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
The reference is the nuget package for aspnet identity and the project builds (rebuild solution) just fine in VS2015 on my local pc. There are of course no local changes and the same branche is build.
Can anyone tell me why this happens or point me in a direction on how to solve this.
Open Package Manager Console view in VS 2015 (View=>Other Window=>Package Manager Console)
Run Update-Package Microsoft.AspNet.Identity.EntityFramework in Package Manager Console
Build project in local
Commit and push changes (the files in package folder could not commit and push to server)
Add NuGet Installer build step (Installation type: Restore) to your build definition (top of other steps) to restore package
Queue build

System.*.Http files not copied to the drop location by TFS 2015 build-agent

Edit: After submitting this post I identified the real issue: MSBuild/TFSBuild does not deploy .dll 'CopyLocal=true' files if they are found in the GAC. In this case the "System.net.http.formatting" dll is in the GAC on the build server. Look here and here
After an upgrade from TFS 2012 to 2015, the build agent no longer copies the following DLLs to the drop locations. How can I identify why the build agent is not copying those files?
system.net.http.formatting, System.Web.Http.dll or System.Web.Http.WebHost.dll
Detail
We have solution with MVC projects that reference the above dlls.
The .csproj files use a hint path to reference the files in the solution /packages/... directory. I have confirmed the path is a valid: the solution has a packages directory.
Before the upgrade to TFS 2015, when building the solution, the above files are copied to the drop location. However they are not after the upgrade.
The build does not fail, however after the TFS 2015 update the target web server throws a 'file not found' error. (MVC is not and cannot be installed on the target web server)
The build utilizes a 2012 XAML Build Definition
Looking at the build log files, both reference the .dll files
CSC.exe ...
/reference:D:\B\15...\packages\Microsoft.AspNet.WebApi.Client.4.0.20710.0\lib\net40\System.Net.Http.Formatting.dll
The build logs shows that only the version build by TFS 2012 copies the .dll file to the drop location. The 2015 build log does not have a line similar to the following:
Copying file from "D:..\packages\Microsoft.AspNet.WebApi.Client.4.0.20710.0\lib\net40\System.Net.Http.Formatting.dll" to "D:..\BIN\EG.WS.EZScan.Web.Intranet\System.Net.Http.Formatting.dll
The build server was not changed during the upgrade other than the re-install of the build agent. The server was not rebuilt. No components were removed or added.
The project did not update to a newer version of MVC. The projects reference version 4.0.0.0. The GACed files on the build server is version 4.0.0.0 (file version 4.0.20710.0)
What else should I look at.
Since you have upgraded to TFS 2015, it's suggested to use the new build system which is completely different from XAML build. Check: https://www.visualstudio.com/en-us/docs/build/overview
It seems you are still checking in the referenced dlls to TFS, which is not suggested. Instead, we suggest restore the packages via a package manager such as NuGet. Check "Migrating to automatic restore" at website https://docs.nuget.org/ndocs/consume-packages/package-restore#msbuild-integrated-restore
If you start to use new build system, you can simply include the Restore NuGet Packages task in the definition before any build task. Detailed information of Nuget Package Restore, please check https://docs.nuget.org/ndocs/consume-packages/package-restore

Categories