Fylix
Fylix

Reputation: 2713

Azure DevOps Build missing assembly reference

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:

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.

Upvotes: 4

Views: 8952

Answers (1)

user7944473
user7944473

Reputation:

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

Upvotes: 2

Related Questions